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,
|
|
|
|
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: {
|
2022-07-07 07:53:29 -04:00
|
|
|
"Topic List Top": "<div class='h-topic-list'>TOPIC LIST TOP</div>",
|
2019-04-18 17:52:59 -04:00
|
|
|
"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>",
|
2022-07-07 07:53:29 -04:00
|
|
|
"Between Topic List":
|
|
|
|
"<div class='h-between-topic-list'>BETWEEN TOPIC LIST</div>",
|
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) => {
|
|
|
|
updateCurrentUser({ staff: false, trust_level: 1 });
|
|
|
|
await visit("/t/280"); // 20 posts
|
2019-04-18 17:52:59 -04:00
|
|
|
|
2020-12-29 11:01:26 -05:00
|
|
|
assert.equal(
|
|
|
|
find(".h-above-post-stream").length,
|
|
|
|
1,
|
|
|
|
"it should render ad at top of topic"
|
|
|
|
);
|
2019-04-18 17:52:59 -04:00
|
|
|
|
2020-12-29 11:01:26 -05:00
|
|
|
assert.equal(
|
|
|
|
find(".h-above-suggested").length,
|
|
|
|
1,
|
|
|
|
"it should render ad above suggested topics"
|
|
|
|
);
|
2019-04-18 17:52:59 -04:00
|
|
|
|
2020-12-29 11:01:26 -05:00
|
|
|
const ads = find(".h-post");
|
|
|
|
assert.equal(ads.length, 3, "it should render 3 ads");
|
|
|
|
assert.equal(
|
|
|
|
find("#post_6 + .widget-connector").find(".h-post").length,
|
|
|
|
1,
|
|
|
|
"ad after 6th post"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
find("#post_12 + .widget-connector").find(".h-post").length,
|
|
|
|
1,
|
|
|
|
"ad after 12th post"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
find("#post_18 + .widget-connector").find(".h-post").length,
|
|
|
|
1,
|
|
|
|
"ad after 18th post"
|
|
|
|
);
|
2019-04-18 17:52:59 -04:00
|
|
|
|
2020-12-29 11:01:26 -05:00
|
|
|
await visit("/latest");
|
|
|
|
assert.equal(
|
|
|
|
find(".h-topic-list").length,
|
|
|
|
1,
|
|
|
|
"it should render ad above topic list"
|
|
|
|
);
|
2019-06-05 15:52:52 -04:00
|
|
|
|
2022-07-07 14:07:16 -04:00
|
|
|
/*
|
|
|
|
Commenting this assertion for now.
|
|
|
|
The code-review plugin overrides core's topic list template,
|
|
|
|
so the between-topic-list connector is never injected.
|
2022-07-07 07:53:29 -04:00
|
|
|
|
2022-07-07 14:07:16 -04:00
|
|
|
await visit("/latest");
|
|
|
|
assert.equal(
|
|
|
|
find(".h-between-topic-list").length,
|
|
|
|
5,
|
|
|
|
"it should render 5 ads"
|
|
|
|
);
|
|
|
|
*/
|
2020-12-29 11:01:26 -05:00
|
|
|
await visit("/t/28830");
|
|
|
|
assert.equal(
|
|
|
|
find(".h-above-post-stream").length,
|
|
|
|
0,
|
|
|
|
"no ad above post stream because category is in no_ads_for_categories"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
find(".h-post").length,
|
|
|
|
0,
|
|
|
|
"no ad between posts because category is in no_ads_for_categories"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
find(".h-above-suggested").length,
|
|
|
|
0,
|
|
|
|
"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");
|
|
|
|
assert.equal(
|
|
|
|
find(".h-topic-list").length,
|
|
|
|
0,
|
|
|
|
"no ad above category topic list because category is in no_ads_for_categories"
|
|
|
|
);
|
|
|
|
});
|
2019-04-18 17:52:59 -04:00
|
|
|
});
|