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";
|
2023-11-07 12:07:33 -05:00
|
|
|
import groupFixtures from "discourse/tests/fixtures/group-fixtures";
|
2021-11-12 13:13:46 -05:00
|
|
|
import {
|
|
|
|
acceptance,
|
|
|
|
updateCurrentUser,
|
|
|
|
} from "discourse/tests/helpers/qunit-helpers";
|
2019-04-16 11:57:16 -04:00
|
|
|
|
2021-01-04 15:42:25 -05:00
|
|
|
acceptance("AdSense", function (needs) {
|
2020-12-29 11:01:26 -05:00
|
|
|
needs.user();
|
|
|
|
needs.settings({
|
2020-08-04 02:03:22 -04:00
|
|
|
no_ads_for_groups: "47",
|
2019-09-11 12:18:42 -04:00
|
|
|
no_ads_for_categories: "1",
|
2019-04-16 11:57:16 -04:00
|
|
|
adsense_publisher_code: "MYADSENSEID",
|
2024-01-31 13:04:24 -05:00
|
|
|
adsense_display_groups: [
|
|
|
|
AUTO_GROUPS.trust_level_1,
|
|
|
|
AUTO_GROUPS.trust_level_2,
|
|
|
|
],
|
2019-04-16 11:57:16 -04:00
|
|
|
adsense_topic_list_top_code: "list_top_ad_unit",
|
|
|
|
adsense_topic_list_top_ad_sizes: "728*90 - leaderboard",
|
|
|
|
adsense_mobile_topic_list_top_code: "mobile_list_top_ad_unit",
|
|
|
|
adsense_mobile_topic_list_top_ad_size: "300*250 - medium rectangle",
|
|
|
|
adsense_post_bottom_code: "post_bottom_ad_unit",
|
|
|
|
adsense_post_bottom_ad_sizes: "728*90 - leaderboard",
|
|
|
|
adsense_mobile_post_bottom_code: "mobile_post_bottom_ad_unit",
|
|
|
|
adsense_mobile_post_bottom_ad_size: "300*250 - medium rectangle",
|
2019-09-11 12:18:42 -04:00
|
|
|
adsense_nth_post_code: 6,
|
|
|
|
adsense_topic_above_post_stream_code: "above_post_stream_ad_unit",
|
2020-09-04 07:24:14 -04:00
|
|
|
adsense_topic_above_post_stream_ad_sizes: "728*90 - leaderboard",
|
2020-12-29 11:01:26 -05:00
|
|
|
});
|
|
|
|
needs.site({
|
2019-04-18 17:52:59 -04:00
|
|
|
house_creatives: {
|
|
|
|
settings: {
|
|
|
|
topic_list_top: "",
|
|
|
|
topic_above_post_stream: "",
|
|
|
|
topic_above_suggested: "",
|
|
|
|
post_bottom: "",
|
2020-09-04 07:24:14 -04:00
|
|
|
after_nth_post: 20,
|
2019-04-18 17:52:59 -04:00
|
|
|
},
|
2020-09-04 07:24:14 -04:00
|
|
|
creatives: {},
|
|
|
|
},
|
2020-12-29 11:01:26 -05:00
|
|
|
});
|
2019-04-16 11:57:16 -04:00
|
|
|
|
2020-12-29 11:01:26 -05:00
|
|
|
test("correct number of ads should show", async (assert) => {
|
2024-01-31 13:04:24 -05:00
|
|
|
updateCurrentUser({
|
|
|
|
staff: false,
|
|
|
|
trust_level: 1,
|
|
|
|
groups: [AUTO_GROUPS.trust_level_1],
|
|
|
|
show_adsense_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-09-11 12:18:42 -04:00
|
|
|
|
2023-11-07 12:03:47 -05:00
|
|
|
assert
|
|
|
|
.dom(".google-adsense.adsense-topic-above-post-stream")
|
|
|
|
.exists({ count: 1 }, "it should render 1 ad above post stream");
|
2019-09-11 12:18:42 -04:00
|
|
|
|
2023-11-07 12:03:47 -05:00
|
|
|
assert
|
|
|
|
.dom(".google-adsense.adsense-post-bottom")
|
|
|
|
.exists({ count: 3 }, "it should render 3 ads");
|
|
|
|
|
|
|
|
assert
|
|
|
|
.dom("#post_6 + .widget-connector .google-adsense.adsense-post-bottom")
|
|
|
|
.exists({ count: 1 }, "ad after 6th post");
|
|
|
|
|
|
|
|
assert
|
|
|
|
.dom("#post_12 + .widget-connector .google-adsense.adsense-post-bottom")
|
|
|
|
.exists({ count: 1 }, "ad after 12th post");
|
|
|
|
|
|
|
|
assert
|
|
|
|
.dom("#post_18 + .widget-connector .google-adsense.adsense-post-bottom")
|
|
|
|
.exists({ count: 1 }, "ad after 18th post");
|
2020-12-29 11:01:26 -05:00
|
|
|
});
|
2019-04-16 11:57:16 -04:00
|
|
|
|
2020-12-29 11:01:26 -05:00
|
|
|
test("no ads for trust level 3", async (assert) => {
|
2024-01-31 13:04:24 -05:00
|
|
|
updateCurrentUser({
|
|
|
|
staff: false,
|
|
|
|
trust_level: 3,
|
|
|
|
groups: [AUTO_GROUPS.trust_level_3],
|
|
|
|
});
|
2020-12-29 11:01:26 -05:00
|
|
|
await visit("/t/280");
|
2023-11-07 12:03:47 -05:00
|
|
|
assert
|
|
|
|
.dom(".google-adsense.adsense-post-bottom")
|
|
|
|
.doesNotExist("it should render 0 ads");
|
2020-12-29 11:01:26 -05:00
|
|
|
});
|
2019-04-17 15:40:50 -04:00
|
|
|
|
2020-12-29 11:01:26 -05:00
|
|
|
test("can omit ads based on groups", async (assert) => {
|
|
|
|
updateCurrentUser({
|
|
|
|
staff: false,
|
|
|
|
trust_level: 1,
|
|
|
|
groups: [groupFixtures["/groups/discourse.json"].group],
|
|
|
|
});
|
|
|
|
await visit("/t/280");
|
2023-11-07 12:03:47 -05:00
|
|
|
assert
|
|
|
|
.dom(".google-adsense.adsense-post-bottom")
|
|
|
|
.doesNotExist("it should render 0 ads");
|
2019-04-17 15:40:50 -04:00
|
|
|
});
|
2019-09-11 12:18:42 -04:00
|
|
|
|
2020-12-29 11:01:26 -05:00
|
|
|
test("can omit ads based on category", async (assert) => {
|
|
|
|
updateCurrentUser({ staff: false, trust_level: 1 });
|
|
|
|
await visit("/t/28830");
|
2023-11-07 12:03:47 -05:00
|
|
|
assert
|
|
|
|
.dom(".google-adsense.adsense-topic-above-post-stream")
|
|
|
|
.doesNotExist("it should render 0 ads");
|
2020-12-29 11:01:26 -05:00
|
|
|
});
|
2019-09-11 12:18:42 -04:00
|
|
|
});
|