mirror of
https://github.com/discourse/discourse-adplugin.git
synced 2025-02-09 04:54:44 +00:00
REFACTOR: Use the new format for acceptance tests. (#97)
This commit is contained in:
parent
4131f8403a
commit
4bf6420b91
@ -1,9 +1,9 @@
|
|||||||
import { acceptance, updateCurrentUser } from "helpers/qunit-helpers";
|
import { acceptance, updateCurrentUser } from "helpers/qunit-helpers";
|
||||||
import groupFixtures from "fixtures/group-fixtures";
|
import groupFixtures from "fixtures/group-fixtures";
|
||||||
|
|
||||||
acceptance("AdSense", {
|
acceptance("AdSense", function(needs) {
|
||||||
loggedIn: true,
|
needs.user();
|
||||||
settings: {
|
needs.settings({
|
||||||
no_ads_for_groups: "47",
|
no_ads_for_groups: "47",
|
||||||
no_ads_for_categories: "1",
|
no_ads_for_categories: "1",
|
||||||
adsense_publisher_code: "MYADSENSEID",
|
adsense_publisher_code: "MYADSENSEID",
|
||||||
@ -19,8 +19,8 @@ acceptance("AdSense", {
|
|||||||
adsense_nth_post_code: 6,
|
adsense_nth_post_code: 6,
|
||||||
adsense_topic_above_post_stream_code: "above_post_stream_ad_unit",
|
adsense_topic_above_post_stream_code: "above_post_stream_ad_unit",
|
||||||
adsense_topic_above_post_stream_ad_sizes: "728*90 - leaderboard",
|
adsense_topic_above_post_stream_ad_sizes: "728*90 - leaderboard",
|
||||||
},
|
});
|
||||||
site: {
|
needs.site({
|
||||||
house_creatives: {
|
house_creatives: {
|
||||||
settings: {
|
settings: {
|
||||||
topic_list_top: "",
|
topic_list_top: "",
|
||||||
@ -31,74 +31,74 @@ acceptance("AdSense", {
|
|||||||
},
|
},
|
||||||
creatives: {},
|
creatives: {},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
test("correct number of ads should show", async (assert) => {
|
|
||||||
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"
|
|
||||||
);
|
|
||||||
|
|
||||||
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"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
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"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("can omit ads based on groups", async (assert) => {
|
|
||||||
updateCurrentUser({
|
|
||||||
staff: false,
|
|
||||||
trust_level: 1,
|
|
||||||
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"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("can omit ads based on category", 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/28830");
|
await visit("/t/280"); // 20 posts
|
||||||
assert.equal(
|
|
||||||
find(".google-adsense.adsense-topic-above-post-stream").length,
|
assert.equal(
|
||||||
0,
|
find(".google-adsense.adsense-topic-above-post-stream").length,
|
||||||
"it should render 0 ads"
|
1,
|
||||||
);
|
"it should render 1 ad"
|
||||||
|
);
|
||||||
|
|
||||||
|
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"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
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"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("can omit ads based on groups", async (assert) => {
|
||||||
|
updateCurrentUser({
|
||||||
|
staff: false,
|
||||||
|
trust_level: 1,
|
||||||
|
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"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
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"
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import { acceptance, updateCurrentUser } from "helpers/qunit-helpers";
|
import { acceptance, updateCurrentUser } from "helpers/qunit-helpers";
|
||||||
import groupFixtures from "fixtures/group-fixtures";
|
import groupFixtures from "fixtures/group-fixtures";
|
||||||
|
|
||||||
acceptance("DFP Ads", {
|
acceptance("DFP Ads", function(needs) {
|
||||||
loggedIn: true,
|
needs.user();
|
||||||
settings: {
|
needs.settings({
|
||||||
no_ads_for_groups: "47",
|
no_ads_for_groups: "47",
|
||||||
no_ads_for_categories: "1",
|
no_ads_for_categories: "1",
|
||||||
dfp_publisher_id: "MYdfpID",
|
dfp_publisher_id: "MYdfpID",
|
||||||
@ -19,8 +19,8 @@ acceptance("DFP Ads", {
|
|||||||
dfp_nth_post_code: 6,
|
dfp_nth_post_code: 6,
|
||||||
dfp_topic_above_post_stream_code: "list_top_ad_unit",
|
dfp_topic_above_post_stream_code: "list_top_ad_unit",
|
||||||
dfp_topic_above_post_stream_ad_sizes: "728*90 - leaderboard",
|
dfp_topic_above_post_stream_ad_sizes: "728*90 - leaderboard",
|
||||||
},
|
});
|
||||||
site: {
|
needs.site({
|
||||||
house_creatives: {
|
house_creatives: {
|
||||||
settings: {
|
settings: {
|
||||||
topic_list_top: "",
|
topic_list_top: "",
|
||||||
@ -31,67 +31,67 @@ acceptance("DFP Ads", {
|
|||||||
},
|
},
|
||||||
creatives: {},
|
creatives: {},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
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"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
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"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("can omit ads based on groups", async (assert) => {
|
|
||||||
updateCurrentUser({
|
|
||||||
staff: false,
|
|
||||||
trust_level: 1,
|
|
||||||
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"
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("can omit ads based on category", 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/28830");
|
await visit("/t/280"); // 20 posts
|
||||||
assert.equal(
|
const ads = find(".google-dfp-ad.dfp-ad-post-bottom");
|
||||||
find(".google-dfp-ad.dfp-ad-topic-above-post-stream").length,
|
assert.equal(ads.length, 3, "it should render 3 ads");
|
||||||
0,
|
assert.equal(
|
||||||
"it should render 0 ads"
|
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"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
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"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("can omit ads based on groups", async (assert) => {
|
||||||
|
updateCurrentUser({
|
||||||
|
staff: false,
|
||||||
|
trust_level: 1,
|
||||||
|
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"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
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"
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import { acceptance, updateCurrentUser } from "helpers/qunit-helpers";
|
import { acceptance, updateCurrentUser } from "helpers/qunit-helpers";
|
||||||
|
|
||||||
acceptance("House Ads", {
|
acceptance("House Ads", function (needs) {
|
||||||
loggedIn: true,
|
needs.user();
|
||||||
settings: {
|
needs.settings({
|
||||||
no_ads_for_categories: "1",
|
no_ads_for_categories: "1",
|
||||||
house_ads_after_nth_post: 6,
|
house_ads_after_nth_post: 6,
|
||||||
},
|
});
|
||||||
site: {
|
needs.site({
|
||||||
house_creatives: {
|
house_creatives: {
|
||||||
settings: {
|
settings: {
|
||||||
topic_list_top: "Topic List",
|
topic_list_top: "Topic List",
|
||||||
@ -24,71 +24,71 @@ acceptance("House Ads", {
|
|||||||
Post: "<div class='h-post'>BELOW POST</div>",
|
Post: "<div class='h-post'>BELOW POST</div>",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
});
|
|
||||||
|
test("correct ads show", async (assert) => {
|
||||||
test("correct ads 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
|
|
||||||
|
assert.equal(
|
||||||
assert.equal(
|
find(".h-above-post-stream").length,
|
||||||
find(".h-above-post-stream").length,
|
1,
|
||||||
1,
|
"it should render ad at top of topic"
|
||||||
"it should render ad at top of topic"
|
);
|
||||||
);
|
|
||||||
|
assert.equal(
|
||||||
assert.equal(
|
find(".h-above-suggested").length,
|
||||||
find(".h-above-suggested").length,
|
1,
|
||||||
1,
|
"it should render ad above suggested topics"
|
||||||
"it should render ad above suggested topics"
|
);
|
||||||
);
|
|
||||||
|
const ads = find(".h-post");
|
||||||
const ads = find(".h-post");
|
assert.equal(ads.length, 3, "it should render 3 ads");
|
||||||
assert.equal(ads.length, 3, "it should render 3 ads");
|
assert.equal(
|
||||||
assert.equal(
|
find("#post_6 + .widget-connector").find(".h-post").length,
|
||||||
find("#post_6 + .widget-connector").find(".h-post").length,
|
1,
|
||||||
1,
|
"ad after 6th post"
|
||||||
"ad after 6th post"
|
);
|
||||||
);
|
assert.equal(
|
||||||
assert.equal(
|
find("#post_12 + .widget-connector").find(".h-post").length,
|
||||||
find("#post_12 + .widget-connector").find(".h-post").length,
|
1,
|
||||||
1,
|
"ad after 12th post"
|
||||||
"ad after 12th post"
|
);
|
||||||
);
|
assert.equal(
|
||||||
assert.equal(
|
find("#post_18 + .widget-connector").find(".h-post").length,
|
||||||
find("#post_18 + .widget-connector").find(".h-post").length,
|
1,
|
||||||
1,
|
"ad after 18th post"
|
||||||
"ad after 18th post"
|
);
|
||||||
);
|
|
||||||
|
await visit("/latest");
|
||||||
await visit("/latest");
|
assert.equal(
|
||||||
assert.equal(
|
find(".h-topic-list").length,
|
||||||
find(".h-topic-list").length,
|
1,
|
||||||
1,
|
"it should render ad above topic list"
|
||||||
"it should render ad above topic list"
|
);
|
||||||
);
|
|
||||||
|
await visit("/t/28830");
|
||||||
await visit("/t/28830");
|
assert.equal(
|
||||||
assert.equal(
|
find(".h-above-post-stream").length,
|
||||||
find(".h-above-post-stream").length,
|
0,
|
||||||
0,
|
"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(
|
||||||
assert.equal(
|
find(".h-post").length,
|
||||||
find(".h-post").length,
|
0,
|
||||||
0,
|
"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(
|
||||||
assert.equal(
|
find(".h-above-suggested").length,
|
||||||
find(".h-above-suggested").length,
|
0,
|
||||||
0,
|
"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(
|
||||||
assert.equal(
|
find(".h-topic-list").length,
|
||||||
find(".h-topic-list").length,
|
0,
|
||||||
0,
|
"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"
|
);
|
||||||
);
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { acceptance, updateCurrentUser } from "helpers/qunit-helpers";
|
import { acceptance, updateCurrentUser } from "helpers/qunit-helpers";
|
||||||
|
|
||||||
acceptance("Mixed Ads", {
|
acceptance("Mixed Ads", function(needs) {
|
||||||
loggedIn: true,
|
needs.user();
|
||||||
settings: {
|
needs.settings({
|
||||||
house_ads_after_nth_post: 6,
|
house_ads_after_nth_post: 6,
|
||||||
house_ads_frequency: 50,
|
house_ads_frequency: 50,
|
||||||
dfp_publisher_id: "MYdfpID",
|
dfp_publisher_id: "MYdfpID",
|
||||||
@ -16,8 +16,8 @@ acceptance("Mixed Ads", {
|
|||||||
dfp_mobile_post_bottom_code: "mobile_post_bottom_ad_unit",
|
dfp_mobile_post_bottom_code: "mobile_post_bottom_ad_unit",
|
||||||
dfp_mobile_post_bottom_ad_size: "300*250 - medium rectangle",
|
dfp_mobile_post_bottom_ad_size: "300*250 - medium rectangle",
|
||||||
dfp_nth_post_code: 6,
|
dfp_nth_post_code: 6,
|
||||||
},
|
});
|
||||||
site: {
|
needs.site({
|
||||||
house_creatives: {
|
house_creatives: {
|
||||||
settings: {
|
settings: {
|
||||||
topic_list_top: "Topic List",
|
topic_list_top: "Topic List",
|
||||||
@ -35,25 +35,25 @@ acceptance("Mixed Ads", {
|
|||||||
Post: "<div class='h-post'>BELOW POST</div>",
|
Post: "<div class='h-post'>BELOW POST</div>",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
});
|
|
||||||
|
test("correct ads show", async (assert) => {
|
||||||
test("correct ads 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 houseAdsCount = find(".house-creative").length;
|
||||||
const houseAdsCount = find(".house-creative").length;
|
const dfpAdsCount = find(".google-dfp-ad").length;
|
||||||
const dfpAdsCount = find(".google-dfp-ad").length;
|
|
||||||
|
assert.ok(houseAdsCount > 1);
|
||||||
assert.ok(houseAdsCount > 1);
|
assert.ok(houseAdsCount < 4);
|
||||||
assert.ok(houseAdsCount < 4);
|
assert.ok(dfpAdsCount > 1);
|
||||||
assert.ok(dfpAdsCount > 1);
|
assert.ok(dfpAdsCount < 4);
|
||||||
assert.ok(dfpAdsCount < 4);
|
|
||||||
|
await visit("/latest");
|
||||||
await visit("/latest");
|
assert.equal(
|
||||||
assert.equal(
|
find(".h-topic-list-top, .dfp-ad-topic-list-top").length,
|
||||||
find(".h-topic-list-top, .dfp-ad-topic-list-top").length,
|
1,
|
||||||
1,
|
"it should render ad above topic list"
|
||||||
"it should render ad above topic list"
|
);
|
||||||
);
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user