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 6086fd1 commit fb73626
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 163 deletions.
72 changes: 28 additions & 44 deletions test/javascripts/acceptance/adsense-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { find, visit } from "@ember/test-helpers";
import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import groupFixtures from "discourse/tests/fixtures/group-fixtures";
import {
Expand Down 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");
});
});
65 changes: 26 additions & 39 deletions test/javascripts/acceptance/dfp-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { find, visit } from "@ember/test-helpers";
import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import groupFixtures from "discourse/tests/fixtures/group-fixtures";
import {
Expand Down 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");
});
});
126 changes: 58 additions & 68 deletions test/javascripts/acceptance/house-ad-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { find, visit } from "@ember/test-helpers";
import { visit } from "@ember/test-helpers";
import { test } from "qunit";
import {
acceptance,
Expand Down 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"
);
});
});
23 changes: 11 additions & 12 deletions test/javascripts/acceptance/mixed-ads-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { find, visit } from "@ember/test-helpers";
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 fb73626

Please sign in to comment.