2023-11-07 12:07:33 -05:00
|
|
|
import { visit } from "@ember/test-helpers";
|
|
|
|
import { test } from "qunit";
|
2024-01-31 13:04:24 -05:00
|
|
|
import { AUTO_GROUPS } from "discourse/lib/constants";
|
2021-11-12 13:13:46 -05:00
|
|
|
import {
|
|
|
|
acceptance,
|
2023-11-07 12:03:47 -05:00
|
|
|
count,
|
2021-11-12 13:13:46 -05:00
|
|
|
updateCurrentUser,
|
|
|
|
} from "discourse/tests/helpers/qunit-helpers";
|
2019-05-08 11:17:40 -04:00
|
|
|
|
2021-01-04 15:42:25 -05:00
|
|
|
acceptance("Mixed Ads", function (needs) {
|
2020-12-29 11:01:26 -05:00
|
|
|
needs.user();
|
|
|
|
needs.settings({
|
2019-05-08 11:17:40 -04:00
|
|
|
house_ads_after_nth_post: 6,
|
|
|
|
house_ads_frequency: 50,
|
|
|
|
dfp_publisher_id: "MYdfpID",
|
2024-01-31 13:04:24 -05:00
|
|
|
dfp_display_groups: [AUTO_GROUPS.trust_level_1, AUTO_GROUPS.trust_level_2],
|
2019-05-08 11:17:40 -04:00
|
|
|
dfp_topic_list_top_code: "list_top_ad_unit",
|
|
|
|
dfp_topic_list_top_ad_sizes: "728*90 - leaderboard",
|
|
|
|
dfp_mobile_topic_list_top_code: "mobile_list_top_ad_unit",
|
|
|
|
dfp_mobile_topic_list_top_ad_size: "300*250 - medium rectangle",
|
|
|
|
dfp_post_bottom_code: "post_bottom_ad_unit",
|
|
|
|
dfp_post_bottom_ad_sizes: "728*90 - leaderboard",
|
|
|
|
dfp_mobile_post_bottom_code: "mobile_post_bottom_ad_unit",
|
|
|
|
dfp_mobile_post_bottom_ad_size: "300*250 - medium rectangle",
|
2020-09-04 07:24:14 -04:00
|
|
|
dfp_nth_post_code: 6,
|
2020-12-29 11:01:26 -05:00
|
|
|
});
|
|
|
|
needs.site({
|
2019-05-08 11:17:40 -04:00
|
|
|
house_creatives: {
|
|
|
|
settings: {
|
|
|
|
topic_list_top: "Topic List",
|
|
|
|
topic_above_post_stream: "Above Post Stream",
|
|
|
|
topic_above_suggested: "Above Suggested",
|
|
|
|
post_bottom: "Post",
|
2020-09-04 07:24:14 -04:00
|
|
|
after_nth_post: 6,
|
2019-05-08 11:17:40 -04:00
|
|
|
},
|
|
|
|
creatives: {
|
|
|
|
"Topic List": "<div class='h-topic-list'>TOPIC LIST</div>",
|
|
|
|
"Above Post Stream":
|
|
|
|
"<div class='h-above-post-stream'>ABOVE POST STREAM</div>",
|
|
|
|
"Above Suggested":
|
|
|
|
"<div class='h-above-suggested'>ABOVE SUGGESTED</div>",
|
2020-09-04 07:24:14 -04:00
|
|
|
Post: "<div class='h-post'>BELOW POST</div>",
|
|
|
|
},
|
|
|
|
},
|
2020-12-29 11:01:26 -05:00
|
|
|
});
|
2019-05-08 11:17:40 -04:00
|
|
|
|
2020-12-29 11:01:26 -05:00
|
|
|
test("correct ads show", async (assert) => {
|
2024-01-31 13:04:24 -05:00
|
|
|
updateCurrentUser({
|
|
|
|
staff: false,
|
|
|
|
trust_level: 1,
|
|
|
|
show_dfp_ads: true,
|
2024-02-15 16:52:15 -05:00
|
|
|
show_to_groups: true,
|
2024-01-31 13:04:24 -05:00
|
|
|
});
|
2020-12-29 11:01:26 -05:00
|
|
|
await visit("/t/280"); // 20 posts
|
2019-05-08 11:17:40 -04:00
|
|
|
|
2023-11-07 12:03:47 -05:00
|
|
|
const houseAdsCount = count(".house-creative");
|
|
|
|
const dfpAdsCount = count(".google-dfp-ad");
|
2019-05-08 11:17:40 -04:00
|
|
|
|
2023-11-07 12:03:47 -05:00
|
|
|
assert.true(houseAdsCount > 1);
|
|
|
|
assert.true(houseAdsCount < 4);
|
|
|
|
assert.true(dfpAdsCount > 1);
|
|
|
|
assert.true(dfpAdsCount < 4);
|
2019-05-08 11:17:40 -04:00
|
|
|
|
2020-12-29 11:01:26 -05:00
|
|
|
await visit("/latest");
|
2023-11-07 12:03:47 -05:00
|
|
|
assert
|
|
|
|
.dom(".h-topic-list-top, .dfp-ad-topic-list-top")
|
|
|
|
.exists({ count: 1 }, "it should render ad above topic list");
|
2020-12-29 11:01:26 -05:00
|
|
|
});
|
2019-05-08 11:17:40 -04:00
|
|
|
});
|