Skip to content

Commit

Permalink
DEV: Update tests to use qunit-dom
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaylorhq committed Nov 7, 2023
1 parent 86ef7da commit dbafb3b
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 159 deletions.
70 changes: 27 additions & 43 deletions test/javascripts/acceptance/adsense-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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");
});
});
63 changes: 25 additions & 38 deletions test/javascripts/acceptance/dfp-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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");
});
});
124 changes: 57 additions & 67 deletions test/javascripts/acceptance/house-ad-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.equal(
find(".h-above-suggested").length,
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-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");

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.
await visit("/latest");
assert.equal(
find(".h-between-topic-list").length,
5,
"it should render 5 ads"
);
*/

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("/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"
);
});
});
21 changes: 10 additions & 11 deletions test/javascripts/acceptance/mixed-ads-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import {
acceptance,
count,
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";

Expand Down Expand Up @@ -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");
});
});

0 comments on commit dbafb3b

Please sign in to comment.