-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test: EthicalAds HTML content checks (#191)
Initial tests for auto-injected ad placement.
- Loading branch information
Showing
5 changed files
with
97 additions
and
6 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* @web/test-runner snapshot v1 */ | ||
export const snapshots = {}; | ||
|
||
snapshots["EthicalAd addon ad placement defined by the user"] = `<div | ||
class="ad-flat ethical-alabaster" | ||
data-ea-manual="true" | ||
data-ea-publisher="readthedocs" | ||
data-ea-type="readthedocs-sidebar" | ||
id="ethical-ad-placement" | ||
> | ||
</div> | ||
`; | ||
/* end snapshot EthicalAd addon ad placement defined by the user */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<html> | ||
<body> | ||
<script type="module"> | ||
import { expect, fixture, fixtureCleanup } from "@open-wc/testing"; | ||
import { runTests } from "@web/test-runner-mocha"; | ||
import * as ethicalads from "../src/ethicalads.js"; | ||
|
||
// Define the config globally to be able to override on ``beforeEach`` and inside each test | ||
let config; | ||
|
||
runTests(async () => { | ||
beforeEach(() => { | ||
config = { | ||
addons: { | ||
ethicalads: { | ||
enabled: true, | ||
ad_free: false, | ||
campaign_types: ["community", "paid"], | ||
keywords: ["docs", "data-science"], | ||
publisher: "readthedocs", | ||
}, | ||
}, | ||
}; | ||
}); | ||
|
||
afterEach(() => { | ||
// Remove all the fixtures added by each test. | ||
fixtureCleanup(); | ||
}); | ||
|
||
describe("EthicalAd addon", () => { | ||
it("ad placement defined by the user", async () => { | ||
await fixture( | ||
'<div id="ethical-ad-placement" class="ad-flat"></div>', | ||
); | ||
const addon = new ethicalads.EthicalAdsAddon(config); | ||
|
||
const element = document.querySelector("#ethical-ad-placement"); | ||
|
||
expect(element).to.have.attribute( | ||
"data-ea-publisher", | ||
"readthedocs", | ||
); | ||
expect(element).to.have.attribute( | ||
"data-ea-type", | ||
"readthedocs-sidebar", | ||
); | ||
|
||
// It's not a Read the Docs-like theme | ||
expect(element).to.have.class("ethical-alabaster"); | ||
|
||
// Keep the CSS classes added manually by the user | ||
expect(element).to.have.class("ad-flat"); | ||
|
||
// Required `await` on this to generate the snapshot file | ||
await expect(element).dom.to.equalSnapshot(); | ||
}); | ||
|
||
it("inject ethicalads.min.js", async () => { | ||
const addon = new ethicalads.EthicalAdsAddon(config); | ||
|
||
const element = document.querySelector("#ethicaladsjs"); | ||
expect(element).to.exist; | ||
expect(element).to.have.attribute( | ||
"src", | ||
"https://media.ethicalads.io/media/client/ethicalads.min.js", | ||
); | ||
expect(element).to.have.attribute("type", "text/javascript"); | ||
expect(element).to.have.attribute("async", "true"); | ||
}); | ||
}); | ||
}); | ||
</script> | ||
</body> | ||
</html> |