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

View File

@ -40,76 +40,66 @@ acceptance("House Ads", function (needs) {
updateCurrentUser({ staff: false, trust_level: 1 }); updateCurrentUser({ staff: false, trust_level: 1 });
await visit("/t/280"); // 20 posts await visit("/t/280"); // 20 posts
assert.equal( assert
find(".h-above-post-stream").length, .dom(".h-above-post-stream")
1, .exists({ count: 1 }, "it should render ad at top of topic");
"it should render ad at top of topic"
);
assert.equal( assert
find(".h-above-suggested").length, .dom(".h-above-suggested")
1, .exists({ count: 1 }, "it should render ad above suggested topics");
"it should render ad above suggested topics"
);
const ads = find(".h-post"); assert
assert.equal(ads.length, 3, "it should render 3 ads"); .dom(".h-post")
assert.equal( .exists({ count: 3 }, "it should render 3 ads between posts");
find("#post_6 + .widget-connector").find(".h-post").length,
1, assert
"ad after 6th post" .dom("#post_6 + .widget-connector .h-post")
); .exists({ count: 1 }, "ad after 6th post");
assert.equal(
find("#post_12 + .widget-connector").find(".h-post").length, assert
1, .dom("#post_12 + .widget-connector .h-post")
"ad after 12th post" .exists({ count: 1 }, "ad after 12th post");
);
assert.equal( assert
find("#post_18 + .widget-connector").find(".h-post").length, .dom("#post_18 + .widget-connector .h-post")
1, .exists({ count: 1 }, "ad after 18th post");
"ad after 18th post"
);
await visit("/latest"); await visit("/latest");
assert.equal(
find(".h-topic-list").length,
1,
"it should render ad above topic list"
);
/* assert
Commenting this assertion for now. .dom(".h-topic-list")
The code-review plugin overrides core's topic list template, .exists({ count: 1 }, "it should render ad above topic list");
so the between-topic-list connector is never injected.
await visit("/latest"); await visit("/latest");
assert.equal( assert
find(".h-between-topic-list").length, .dom(".h-between-topic-list")
5, .exists({ count: 5 }, "it should render 5 ads between topics");
"it should render 5 ads"
);
*/
await visit("/t/28830"); await visit("/t/28830");
assert.equal(
find(".h-above-post-stream").length, assert
0, .dom(".h-above-post-stream")
.doesNotExist(
"no ad above post stream because category is in no_ads_for_categories" "no ad above post stream because category is in no_ads_for_categories"
); );
assert.equal(
find(".h-post").length, assert
0, .dom(".h-post")
.doesNotExist(
"no ad between posts because category is in no_ads_for_categories" "no ad between posts because category is in no_ads_for_categories"
); );
assert.equal(
find(".h-above-suggested").length, assert
0, .dom(".h-above-suggested")
.doesNotExist(
"no ad above suggested because category is in no_ads_for_categories" "no ad above suggested because category is in no_ads_for_categories"
); );
await visit("/c/bug"); await visit("/c/bug");
assert.equal(
find(".h-topic-list").length, assert
0, .dom(".h-topic-list")
.doesNotExist(
"no ad above category topic list because category is in no_ads_for_categories" "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 { test } from "qunit";
import { import {
acceptance, acceptance,
count,
updateCurrentUser, updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers"; } from "discourse/tests/helpers/qunit-helpers";
@ -46,19 +47,17 @@ acceptance("Mixed Ads", function (needs) {
updateCurrentUser({ staff: false, trust_level: 1 }); updateCurrentUser({ staff: false, trust_level: 1 });
await visit("/t/280"); // 20 posts await visit("/t/280"); // 20 posts
const houseAdsCount = find(".house-creative").length; const houseAdsCount = count(".house-creative");
const dfpAdsCount = find(".google-dfp-ad").length; const dfpAdsCount = count(".google-dfp-ad");
assert.ok(houseAdsCount > 1); assert.true(houseAdsCount > 1);
assert.ok(houseAdsCount < 4); assert.true(houseAdsCount < 4);
assert.ok(dfpAdsCount > 1); assert.true(dfpAdsCount > 1);
assert.ok(dfpAdsCount < 4); assert.true(dfpAdsCount < 4);
await visit("/latest"); await visit("/latest");
assert.equal( assert
find(".h-topic-list-top, .dfp-ad-topic-list-top").length, .dom(".h-topic-list-top, .dfp-ad-topic-list-top")
1, .exists({ count: 1 }, "it should render ad above topic list");
"it should render ad above topic list"
);
}); });
}); });