2023-11-07 12:07:33 -05:00
|
|
|
import { visit } from "@ember/test-helpers";
|
|
|
|
import { test } from "qunit";
|
2021-11-12 13:13:46 -05:00
|
|
|
import {
|
|
|
|
acceptance,
|
2023-11-07 16:12:30 -05:00
|
|
|
query,
|
2021-11-12 13:13:46 -05:00
|
|
|
updateCurrentUser,
|
|
|
|
} from "discourse/tests/helpers/qunit-helpers";
|
2019-04-18 17:52:59 -04:00
|
|
|
|
2020-12-29 11:01:26 -05:00
|
|
|
acceptance("House Ads", function (needs) {
|
|
|
|
needs.user();
|
|
|
|
needs.settings({
|
2019-06-05 15:52:52 -04:00
|
|
|
no_ads_for_categories: "1",
|
2020-09-04 07:24:14 -04:00
|
|
|
house_ads_after_nth_post: 6,
|
2022-07-07 07:53:29 -04:00
|
|
|
house_ads_after_nth_topic: 3,
|
2020-12-29 11:01:26 -05:00
|
|
|
});
|
|
|
|
needs.site({
|
2019-04-18 17:52:59 -04:00
|
|
|
house_creatives: {
|
|
|
|
settings: {
|
2022-07-07 07:53:29 -04:00
|
|
|
topic_list_top: "Topic List Top",
|
2019-04-18 17:52:59 -04:00
|
|
|
topic_above_post_stream: "Above Post Stream",
|
|
|
|
topic_above_suggested: "Above Suggested",
|
|
|
|
post_bottom: "Post",
|
2022-07-07 07:53:29 -04:00
|
|
|
topic_list_between: "Between Topic List",
|
2020-09-04 07:24:14 -04:00
|
|
|
after_nth_post: 6,
|
2022-07-07 07:53:29 -04:00
|
|
|
after_nth_topic: 6,
|
2019-04-18 17:52:59 -04:00
|
|
|
},
|
|
|
|
creatives: {
|
2024-04-09 13:54:11 -04:00
|
|
|
"Topic List Top": {
|
|
|
|
html: "<div class='h-topic-list'>TOPIC LIST TOP</div>",
|
|
|
|
category_ids: [],
|
|
|
|
},
|
|
|
|
"Above Post Stream": {
|
|
|
|
html: "<div class='h-above-post-stream'>ABOVE POST STREAM</div>",
|
|
|
|
category_ids: [],
|
|
|
|
},
|
|
|
|
"Above Suggested": {
|
|
|
|
html: "<div class='h-above-suggested'>ABOVE SUGGESTED</div>",
|
|
|
|
category_ids: [],
|
|
|
|
},
|
|
|
|
Post: {
|
|
|
|
html: "<div class='h-post'>BELOW POST</div>",
|
|
|
|
category_ids: [],
|
|
|
|
},
|
|
|
|
"Between Topic List": {
|
|
|
|
html: "<div class='h-between-topic-list'>BETWEEN TOPIC LIST</div>",
|
|
|
|
category_ids: [],
|
|
|
|
},
|
2020-09-04 07:24:14 -04:00
|
|
|
},
|
|
|
|
},
|
2020-12-29 11:01:26 -05:00
|
|
|
});
|
2019-04-18 17:52:59 -04:00
|
|
|
|
2020-12-29 11:01:26 -05:00
|
|
|
test("correct ads show", async (assert) => {
|
2024-02-15 16:52:15 -05:00
|
|
|
updateCurrentUser({ staff: false, trust_level: 1, show_to_groups: true });
|
2020-12-29 11:01:26 -05:00
|
|
|
await visit("/t/280"); // 20 posts
|
2019-04-18 17:52:59 -04:00
|
|
|
|
2023-11-07 12:03:47 -05:00
|
|
|
assert
|
|
|
|
.dom(".h-above-post-stream")
|
|
|
|
.exists({ count: 1 }, "it should render ad at top of topic");
|
|
|
|
|
|
|
|
assert
|
|
|
|
.dom(".h-above-suggested")
|
|
|
|
.exists({ count: 1 }, "it should render ad above suggested topics");
|
|
|
|
|
|
|
|
assert
|
|
|
|
.dom(".h-post")
|
|
|
|
.exists({ count: 3 }, "it should render 3 ads between posts");
|
|
|
|
|
|
|
|
assert
|
|
|
|
.dom("#post_6 + .widget-connector .h-post")
|
|
|
|
.exists({ count: 1 }, "ad after 6th post");
|
|
|
|
|
|
|
|
assert
|
|
|
|
.dom("#post_12 + .widget-connector .h-post")
|
|
|
|
.exists({ count: 1 }, "ad after 12th post");
|
|
|
|
|
|
|
|
assert
|
|
|
|
.dom("#post_18 + .widget-connector .h-post")
|
|
|
|
.exists({ count: 1 }, "ad after 18th post");
|
2019-04-18 17:52:59 -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")
|
|
|
|
.exists({ count: 1 }, "it should render ad above topic list");
|
2023-11-07 16:12:30 -05:00
|
|
|
const originalTopAdElement = query(".h-topic-list");
|
2023-11-07 12:03:47 -05:00
|
|
|
|
|
|
|
assert
|
|
|
|
.dom(".h-between-topic-list")
|
|
|
|
.exists({ count: 5 }, "it should render 5 ads between topics");
|
|
|
|
|
2023-11-07 16:12:30 -05:00
|
|
|
await visit("/top");
|
|
|
|
const newTopAdElement = query(".h-topic-list");
|
|
|
|
|
|
|
|
assert.notStrictEqual(
|
|
|
|
originalTopAdElement,
|
|
|
|
newTopAdElement,
|
|
|
|
"ad is fully re-rendered when changing pages"
|
|
|
|
);
|
|
|
|
|
2020-12-29 11:01:26 -05:00
|
|
|
await visit("/t/28830");
|
2023-11-07 12:03:47 -05:00
|
|
|
|
|
|
|
assert
|
|
|
|
.dom(".h-above-post-stream")
|
|
|
|
.doesNotExist(
|
|
|
|
"no ad above post stream because category is in no_ads_for_categories"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert
|
|
|
|
.dom(".h-post")
|
|
|
|
.doesNotExist(
|
|
|
|
"no ad between posts because category is in no_ads_for_categories"
|
|
|
|
);
|
|
|
|
|
|
|
|
assert
|
|
|
|
.dom(".h-above-suggested")
|
|
|
|
.doesNotExist(
|
|
|
|
"no ad above suggested because category is in no_ads_for_categories"
|
|
|
|
);
|
2019-06-05 15:52:52 -04:00
|
|
|
|
2020-12-29 11:01:26 -05:00
|
|
|
await visit("/c/bug");
|
2023-11-07 12:03:47 -05:00
|
|
|
|
|
|
|
assert
|
|
|
|
.dom(".h-topic-list")
|
|
|
|
.doesNotExist(
|
|
|
|
"no ad above category topic list because category is in no_ads_for_categories"
|
|
|
|
);
|
2020-12-29 11:01:26 -05:00
|
|
|
});
|
2019-04-18 17:52:59 -04:00
|
|
|
});
|
2024-04-09 13:54:11 -04:00
|
|
|
|
|
|
|
acceptance(
|
|
|
|
"House Ads | Category and Group Permissions | Authenticated | Display Ad",
|
|
|
|
function (needs) {
|
|
|
|
needs.user();
|
|
|
|
needs.settings({
|
|
|
|
no_ads_for_categories: "",
|
|
|
|
});
|
|
|
|
needs.site({
|
|
|
|
house_creatives: {
|
|
|
|
settings: {
|
|
|
|
topic_list_top: "Topic List Top",
|
|
|
|
},
|
|
|
|
creatives: {
|
|
|
|
"Topic List Top": {
|
|
|
|
html: "<div class='h-topic-list'>TOPIC LIST TOP</div>",
|
|
|
|
// match /c/bug/1
|
|
|
|
category_ids: [1],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
test("displays ad to users when current category id is included in ad category_ids", async (assert) => {
|
|
|
|
updateCurrentUser({
|
|
|
|
staff: false,
|
|
|
|
trust_level: 1,
|
|
|
|
show_to_groups: true,
|
|
|
|
});
|
|
|
|
await visit("/c/bug/1");
|
|
|
|
assert
|
|
|
|
.dom(".h-topic-list")
|
|
|
|
.exists(
|
|
|
|
"ad is displayed above the topic list because the current category id is included in the ad category_ids"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
acceptance(
|
|
|
|
"House Ads | Category and Group Permissions | Authenticated | Hide Ad",
|
|
|
|
function (needs) {
|
|
|
|
needs.user();
|
|
|
|
needs.settings({
|
|
|
|
no_ads_for_categories: "",
|
|
|
|
});
|
|
|
|
needs.site({
|
|
|
|
house_creatives: {
|
|
|
|
settings: {
|
|
|
|
topic_list_top: "Topic List Top",
|
|
|
|
},
|
|
|
|
creatives: {
|
|
|
|
"Topic List Top": {
|
|
|
|
html: "<div class='h-topic-list'>TOPIC LIST TOP</div>",
|
|
|
|
// restrict ad to a different category than /c/bug/1
|
|
|
|
category_ids: [2],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
test("hides ad to users when current category id is not included in ad category_ids", async (assert) => {
|
|
|
|
updateCurrentUser({
|
|
|
|
staff: false,
|
|
|
|
trust_level: 1,
|
|
|
|
show_to_groups: true,
|
|
|
|
});
|
|
|
|
await visit("/c/bug/1");
|
|
|
|
assert
|
|
|
|
.dom(".h-topic-list")
|
|
|
|
.doesNotExist(
|
2024-06-27 12:43:54 -04:00
|
|
|
"ad is not displayed because the current category id is not included in the ad category_ids"
|
2024-04-09 13:54:11 -04:00
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
acceptance(
|
|
|
|
"House Ads | Category and Group Permissions | Anonymous | Hide Ad",
|
|
|
|
function (needs) {
|
|
|
|
needs.settings({
|
|
|
|
no_ads_for_categories: "",
|
|
|
|
});
|
|
|
|
needs.site({
|
|
|
|
house_creatives: {
|
|
|
|
settings: {
|
|
|
|
topic_list_top: "Topic List Top",
|
|
|
|
},
|
|
|
|
creatives: {
|
|
|
|
"Topic List Top": {
|
|
|
|
html: "<div class='h-topic-list'>TOPIC LIST TOP</div>",
|
|
|
|
// restrict ad to a different category than /c/bug/1
|
|
|
|
category_ids: [2],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
test("hides ad to anon users when current category id is not included in ad category_ids", async (assert) => {
|
|
|
|
await visit("/c/bug/1");
|
|
|
|
assert
|
|
|
|
.dom(".h-topic-list")
|
|
|
|
.doesNotExist(
|
2024-06-27 12:43:54 -04:00
|
|
|
"ad is not displayed because the current category id is not included in the ad category_ids"
|
2024-04-09 13:54:11 -04:00
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
acceptance(
|
|
|
|
"House Ads | Category and Group Permissions | Anonymous | Hide Ad",
|
|
|
|
function (needs) {
|
|
|
|
needs.settings({
|
|
|
|
no_ads_for_categories: "",
|
|
|
|
});
|
|
|
|
needs.site({
|
|
|
|
house_creatives: {
|
|
|
|
settings: {
|
|
|
|
topic_list_top: "Topic List Top",
|
|
|
|
},
|
|
|
|
creatives: {
|
|
|
|
"Topic List Top": {
|
|
|
|
html: "<div class='h-topic-list'>TOPIC LIST TOP</div>",
|
|
|
|
// restrict ad to a different category than /c/bug/1
|
|
|
|
category_ids: [2],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
test("hides ad to anon users when current category id is not included in ad category_ids", async (assert) => {
|
|
|
|
await visit("/c/bug/1");
|
|
|
|
assert
|
|
|
|
.dom(".h-topic-list")
|
|
|
|
.doesNotExist(
|
2024-06-27 12:43:54 -04:00
|
|
|
"ad is not displayed because the current category id is not included in the ad category_ids"
|
2024-04-09 13:54:11 -04:00
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
acceptance(
|
|
|
|
"House Ads | Category and Group Permissions | Anonymous | Show Ad",
|
|
|
|
function (needs) {
|
|
|
|
needs.settings({
|
|
|
|
no_ads_for_categories: "",
|
|
|
|
});
|
|
|
|
needs.site({
|
|
|
|
house_creatives: {
|
|
|
|
settings: {
|
|
|
|
topic_list_top: "Topic List Top",
|
|
|
|
},
|
|
|
|
creatives: {
|
|
|
|
"Topic List Top": {
|
|
|
|
html: "<div class='h-topic-list'>TOPIC LIST TOP</div>",
|
|
|
|
// match /c/bug/1
|
|
|
|
category_ids: [1],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2024-06-27 12:43:54 -04:00
|
|
|
test("shows ad to anon users when current category id is included in ad category_ids", async (assert) => {
|
2024-04-09 13:54:11 -04:00
|
|
|
await visit("/c/bug/1");
|
|
|
|
assert
|
|
|
|
.dom(".h-topic-list")
|
|
|
|
.exists(
|
|
|
|
"ad is displayed because the current category id is included in the ad category_ids"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
2024-06-27 12:43:54 -04:00
|
|
|
|
|
|
|
acceptance(
|
|
|
|
"House Ads | Category and Group Permissions | Anonymous | Show non-restricted ads",
|
|
|
|
function (needs) {
|
|
|
|
needs.settings({
|
|
|
|
no_ads_for_categories: "",
|
|
|
|
});
|
|
|
|
needs.site({
|
|
|
|
house_creatives: {
|
|
|
|
settings: {
|
|
|
|
topic_list_top: "Topic List Top One|Topic List Top Two",
|
|
|
|
},
|
|
|
|
creatives: {
|
|
|
|
"Topic List Top One": {
|
|
|
|
html: "<div class='h-topic-list-one'>TOPIC LIST TOP ONE</div>",
|
|
|
|
category_ids: [2],
|
|
|
|
},
|
|
|
|
"Topic List Top Two": {
|
|
|
|
html: "<div class='h-topic-list-two'>TOPIC LIST TOP TWO</div>",
|
|
|
|
category_ids: [],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
test("shows non-restricted ad to anon users", async (assert) => {
|
|
|
|
await visit("/c/bug/1");
|
|
|
|
assert.dom(".h-topic-list-two").exists("non-restricted ad is displayed");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|