DEV: Update tests to use qunit-dom

This commit is contained in:
David Taylor 2023-11-07 17:03:47 +00:00
parent 86ef7da2eb
commit dbafb3b277
4 changed files with 115 additions and 155 deletions

View File

@ -42,45 +42,33 @@ acceptance("AdSense", function (needs) {
updateCurrentUser({ staff: false, trust_level: 1 });
await visit("/t/280"); // 20 posts
assert.equal(
find(".google-adsense.adsense-topic-above-post-stream").length,
1,
"it should render 1 ad"
);
assert
.dom(".google-adsense.adsense-topic-above-post-stream")
.exists({ count: 1 }, "it should render 1 ad above post stream");
const ads = find(".google-adsense.adsense-post-bottom");
assert.equal(ads.length, 3, "it should render 3 ads");
assert.equal(
find("#post_6 + .widget-connector").find(
".google-adsense.adsense-post-bottom"
).length,
1,
"ad after 6th post"
);
assert.equal(
find("#post_12 + .widget-connector").find(
".google-adsense.adsense-post-bottom"
).length,
1,
"ad after 12th post"
);
assert.equal(
find("#post_18 + .widget-connector").find(
".google-adsense.adsense-post-bottom"
).length,
1,
"ad after 18th post"
);
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");
});
test("no ads for trust level 3", async (assert) => {
updateCurrentUser({ staff: false, trust_level: 3 });
await visit("/t/280");
assert.equal(
find(".google-adsense.adsense-post-bottom").length,
0,
"it should render 0 ads"
);
assert
.dom(".google-adsense.adsense-post-bottom")
.doesNotExist("it should render 0 ads");
});
test("can omit ads based on groups", async (assert) => {
@ -90,20 +78,16 @@ acceptance("AdSense", function (needs) {
groups: [groupFixtures["/groups/discourse.json"].group],
});
await visit("/t/280");
assert.equal(
find(".google-adsense.adsense-post-bottom").length,
0,
"it should render 0 ads"
);
assert
.dom(".google-adsense.adsense-post-bottom")
.doesNotExist("it should render 0 ads");
});
test("can omit ads based on category", async (assert) => {
updateCurrentUser({ staff: false, trust_level: 1 });
await visit("/t/28830");
assert.equal(
find(".google-adsense.adsense-topic-above-post-stream").length,
0,
"it should render 0 ads"
);
assert
.dom(".google-adsense.adsense-topic-above-post-stream")
.doesNotExist("it should render 0 ads");
});
});

View File

@ -41,39 +41,30 @@ acceptance("DFP Ads", function (needs) {
test("correct number of ads should show", async (assert) => {
updateCurrentUser({ staff: false, trust_level: 1 });
await visit("/t/280"); // 20 posts
const ads = find(".google-dfp-ad.dfp-ad-post-bottom");
assert.equal(ads.length, 3, "it should render 3 ads");
assert.equal(
find("#post_6 + .widget-connector").find(
".google-dfp-ad.dfp-ad-post-bottom"
).length,
1,
"ad after 6th post"
);
assert.equal(
find("#post_12 + .widget-connector").find(
".google-dfp-ad.dfp-ad-post-bottom"
).length,
1,
"ad after 12th post"
);
assert.equal(
find("#post_18 + .widget-connector").find(
".google-dfp-ad.dfp-ad-post-bottom"
).length,
1,
"ad after 18th post"
);
assert
.dom(".google-dfp-ad.dfp-ad-post-bottom")
.exists({ count: 3 }, "it should render 3 ads");
assert
.dom("#post_6 + .widget-connector .google-dfp-ad.dfp-ad-post-bottom")
.exists({ count: 1 }, "ad after 6th post");
assert
.dom("#post_12 + .widget-connector .google-dfp-ad.dfp-ad-post-bottom")
.exists({ count: 1 }, "ad after 12th post");
assert
.dom("#post_18 + .widget-connector .google-dfp-ad.dfp-ad-post-bottom")
.exists({ count: 1 }, "ad after 18th post");
});
test("no ads for trust level 3", async (assert) => {
updateCurrentUser({ staff: false, trust_level: 3 });
await visit("/t/280");
assert.equal(
find(".google-dfp-ad.dfp-ad-post-bottom").length,
0,
"it should render 0 ads"
);
assert
.dom(".google-dfp-ad.dfp-ad-post-bottom")
.doesNotExist("it should render 0 ads");
});
test("can omit ads based on groups", async (assert) => {
@ -83,20 +74,16 @@ acceptance("DFP Ads", function (needs) {
groups: [groupFixtures["/groups/discourse.json"].group],
});
await visit("/t/280");
assert.equal(
find(".google-dfp-ad.dfp-ad-post-bottom").length,
0,
"it should render 0 ads"
);
assert
.dom(".google-dfp-ad.dfp-ad-post-bottom")
.doesNotExist("it should render 0 ads");
});
test("can omit ads based on category", async (assert) => {
updateCurrentUser({ staff: false, trust_level: 1 });
await visit("/t/28830");
assert.equal(
find(".google-dfp-ad.dfp-ad-topic-above-post-stream").length,
0,
"it should render 0 ads"
);
assert
.dom(".google-dfp-ad.dfp-ad-topic-above-post-stream")
.doesNotExist("it should render 0 ads");
});
});

View File

@ -40,77 +40,67 @@ acceptance("House Ads", function (needs) {
updateCurrentUser({ staff: false, trust_level: 1 });
await visit("/t/280"); // 20 posts
assert.equal(
find(".h-above-post-stream").length,
1,
"it should render ad at top of topic"
);
assert
.dom(".h-above-post-stream")
.exists({ count: 1 }, "it should render ad at top of topic");
assert.equal(
find(".h-above-suggested").length,
1,
"it should render ad above suggested topics"
);
assert
.dom(".h-above-suggested")
.exists({ count: 1 }, "it should render ad above suggested topics");
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"
);
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");
await visit("/latest");
assert.equal(
find(".h-topic-list").length,
1,
"it should render ad above topic list"
);
/*
Commenting this assertion for now.
The code-review plugin overrides core's topic list template,
so the between-topic-list connector is never injected.
assert
.dom(".h-topic-list")
.exists({ count: 1 }, "it should render ad above topic list");
await visit("/latest");
assert
.dom(".h-between-topic-list")
.exists({ count: 5 }, "it should render 5 ads between topics");
await visit("/latest");
assert.equal(
find(".h-between-topic-list").length,
5,
"it should render 5 ads"
);
*/
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"
);
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"
);
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"
);
assert
.dom(".h-topic-list")
.doesNotExist(
"no ad above category topic list because category is in no_ads_for_categories"
);
});
});

View File

@ -2,6 +2,7 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import {
acceptance,
count,
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
@ -46,19 +47,17 @@ acceptance("Mixed Ads", function (needs) {
updateCurrentUser({ staff: false, trust_level: 1 });
await visit("/t/280"); // 20 posts
const houseAdsCount = find(".house-creative").length;
const dfpAdsCount = find(".google-dfp-ad").length;
const houseAdsCount = count(".house-creative");
const dfpAdsCount = count(".google-dfp-ad");
assert.ok(houseAdsCount > 1);
assert.ok(houseAdsCount < 4);
assert.ok(dfpAdsCount > 1);
assert.ok(dfpAdsCount < 4);
assert.true(houseAdsCount > 1);
assert.true(houseAdsCount < 4);
assert.true(dfpAdsCount > 1);
assert.true(dfpAdsCount < 4);
await visit("/latest");
assert.equal(
find(".h-topic-list-top, .dfp-ad-topic-list-top").length,
1,
"it should render ad above topic list"
);
assert
.dom(".h-topic-list-top, .dfp-ad-topic-list-top")
.exists({ count: 1 }, "it should render ad above topic list");
});
});