Skip to content

Commit

Permalink
Extract base urls used in /tests into a module (#12132)
Browse files Browse the repository at this point in the history
* extract base urls used in /tests into a module
  • Loading branch information
mmmavis authored Apr 4, 2024
1 parent 3564814 commit ac45f72
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"lint": "run-s lint:*",
"lint:procfile": "node test/test-procfile.js",
"lint:js": "run-s lint:js:*",
"lint:js:eslint": "eslint --config ./.eslintrc.json \"source/js/**/*.js\" \"source/js/**/*.jsx\" \"network-api/networkapi/wagtailcustomization/**/*.js\" ./*.js",
"lint:js:eslint": "eslint --config ./.eslintrc.json \"source/js/**/*.js\" \"source/js/**/*.jsx\" \"network-api/networkapi/wagtailcustomization/**/*.js\" \"tests/**/*.js\" ./*.js",
"lint:js:a11y": "eslint --config ./.eslintrc.a11y.json \"source/js/**/*.jsx\"",
"lint:css": "run-s lint:css:*",
"lint:css:scss": "stylelint \"source/sass/**/*.scss\" \"source/js/**/*.scss\" --custom-syntax postcss-scss",
Expand Down
14 changes: 14 additions & 0 deletions tests/base-urls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
donateBaseUrl: function (locale = "en") {
return `http://localhost:8000/${locale}/donate`;
},
foundationBaseUrl: function (locale = "en") {
return `http://localhost:8000/${locale}`;
},
mozfestBaseUrl: function (locale = "en") {
return `http://mozfest.localhost:8000/${locale}`;
},
pniBaseUrl: function (locale = "en") {
return `http://localhost:8000/${locale}/privacynotincluded`;
},
};
22 changes: 13 additions & 9 deletions tests/integration/donate/help/001-help-form.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ test.describe("Donate Help Form", () => {
// Locales supported by FormAssembly and their corresponding IDs.
// (Locales unsupported by FA, such as SW, default to `tfa_227`)
const formAssemblySupportedLocaleMap = {
"nl": "tfa_221",
nl: "tfa_221",
"fy-NL": "tfa_221",
"en": "tfa_222",
"fr": "tfa_223",
"de": "tfa_224",
"pl": "tfa_228",
en: "tfa_222",
fr: "tfa_223",
de: "tfa_224",
pl: "tfa_228",
"pt-BR": "tfa_229",
"es": "tfa_231",
"other": "tfa_227",
es: "tfa_231",
other: "tfa_227",
};

let localeToTest = foundationSupportedLocales[0];
Expand Down Expand Up @@ -98,10 +98,14 @@ test.describe("Donate Help Form", () => {

// Test that the "Lang" input value is being prepopulated with the correct FA language code.
if (localeToTest in formAssemblySupportedLocaleMap) {
expect(await langInput.inputValue()).toBe(formAssemblySupportedLocaleMap[localeToTest]);
expect(await langInput.inputValue()).toBe(
formAssemblySupportedLocaleMap[localeToTest]
);
} else {
// If current page locale is not supported by FA, the input should default to the value of "Other".
expect(await langInput.inputValue()).toBe(formAssemblySupportedLocaleMap["other"]);
expect(await langInput.inputValue()).toBe(
formAssemblySupportedLocaleMap["other"]
);
}

// Test that the "Thank You Url" input exists, is hidden, and is prepopulated with the appropriate "thank you" URL.
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/donate/help/utility.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { donateBaseUrl } = require("../../../base-urls.js");
const THANK_YOU_PAGE_QUERY_PARAM = {
key: `thank_you`,
value: `true`,
Expand Down Expand Up @@ -35,7 +36,7 @@ module.exports = {
* @param {boolean} addThankYouQueryParam whether to add the thank you query parameter to the URL
*/
generateUrl: function (locale = "en", addThankYouQueryParam = false) {
let baseUrl = `http://localhost:8000/${locale}/donate/help/?existing=query`;
let baseUrl = `${donateBaseUrl(locale)}/help/?existing=query`;

return addThankYouQueryParam
? `${baseUrl}&${THANK_YOU_PAGE_QUERY_PARAM.key}=${THANK_YOU_PAGE_QUERY_PARAM.value}`
Expand Down
4 changes: 3 additions & 1 deletion tests/integration/foundation-homepage.spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const { test, expect } = require("@playwright/test");
const waitForImagesToLoad = require("../wait-for-images.js");
const { foundationBaseUrl } = require("../base-urls.js");

test(`Foundation homepage`, async ({ page }) => {
page.on(`console`, console.log);
await page.goto(`http://localhost:8000/en/`);
await page.goto(`${foundationBaseUrl("en")}/`);
await page.locator(`body.react-loaded`);
await waitForImagesToLoad(page);

Expand All @@ -14,6 +15,7 @@ test(`Foundation homepage`, async ({ page }) => {
const newsLetterButton = page.locator(
`.wide-screen-menu-container button.btn-newsletter`
);

await newsLetterButton.click();
await page.waitForTimeout(500);
expect(await newsLetterWrapper.isVisible()).toBe(true);
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/navigation/001-site-nav.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const { test, expect } = require("@playwright/test");
const waitForImagesToLoad = require("../../wait-for-images.js");
const { foundationBaseUrl } = require("../../base-urls.js");

const MOBILE_VIEWPORT = { width: 360, height: 800 };

test.describe("Main site primary nav", () => {
test(`Primary nav (mobile)`, async ({ page }) => {
const PAGE_URL = `http://localhost:8000/en/`;
const PAGE_URL = `${foundationBaseUrl("en")}/`;

await page.setViewportSize(MOBILE_VIEWPORT);
await page.goto(PAGE_URL);
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/navigation/002-mozfest-nav.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const { test, expect } = require("@playwright/test");
const waitForImagesToLoad = require("../../wait-for-images.js");
const { mozfestBaseUrl } = require("../../base-urls.js");

const MOBILE_VIEWPORT = { width: 360, height: 800 };

test.describe("MozFest site navs", () => {
test(`Primary nav (mobile)`, async ({ page }) => {
const PAGE_URL = `http://mozfest.localhost:8000/en/`;
const PAGE_URL = `${mozfestBaseUrl("en")}/`;

await page.setViewportSize(MOBILE_VIEWPORT);
await page.goto(PAGE_URL);
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/navigation/003-pni-nav.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const { test, expect } = require("@playwright/test");
const waitForImagesToLoad = require("../../wait-for-images.js");
const { pniBaseUrl } = require("../../base-urls.js");

const MOBILE_VIEWPORT = { width: 360, height: 800 };

test.describe("PNI navs", () => {
test(`Primary nav (mobile)`, async ({ page }) => {
const PAGE_URL = `http://localhost:8000/en/privacynotincluded`;
const PAGE_URL = pniBaseUrl("en");

await page.setViewportSize(MOBILE_VIEWPORT);
await page.goto(PAGE_URL);
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/newsletter/001-default-layout.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ const waitForImagesToLoad = require("../../wait-for-images.js");
const {
LANGUAGE_OPTIONS,
} = require("../../../source/js/components/newsletter-signup/data/language-options.js");
const { foundationBaseUrl } = require("../../base-urls.js");

const locales = LANGUAGE_OPTIONS.map((language) => language.value);
function generateUrl(locale = "en") {
return `http://localhost:8000/${locale}/blog/initial-test-blog-post-with-fixed-title/?random=query`;
return `${foundationBaseUrl(locale)}/blog/initial-test-blog-post-with-fixed-title/?random=query`;
}

test.describe("Blog body newsletter signup form", () => {
Expand Down
4 changes: 3 additions & 1 deletion tests/integration/petition/utility.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { foundationBaseUrl } = require("../../base-urls.js");

const THANK_YOU_PAGE_QUERY_PARAM = {
key: `thank_you`,
value: `true`,
Expand Down Expand Up @@ -26,7 +28,7 @@ module.exports = {
* @param {boolean} addThankYouQueryParam whether to add the thank you query parameter to the URL
*/
generateUrl: function (locale = "en", addThankYouQueryParam = false) {
let baseUrl = `http://localhost:8000/${locale}/campaigns/single-page/?existing=query`;
let baseUrl = `${foundationBaseUrl(locale)}/campaigns/single-page/?existing=query`;

return addThankYouQueryParam
? `${baseUrl}&${THANK_YOU_PAGE_QUERY_PARAM.key}=${THANK_YOU_PAGE_QUERY_PARAM.value}`
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/pni/search.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { test, expect } = require("@playwright/test");
const waitForImagesToLoad = require("../../wait-for-images.js");
const { pniBaseUrl } = require("../../base-urls.js");

/**
* Perform several PNI tests related to searching/filtering
Expand Down Expand Up @@ -50,7 +51,7 @@ test.describe("PNI search", () => {

test.beforeEach(async ({ page }) => {
page.on(`console`, console.log);
await page.goto(`http://localhost:8000/en/privacynotincluded`);
await page.goto(pniBaseUrl("en"));
await page.locator(`body.react-loaded`);
await waitForImagesToLoad(page);
});
Expand Down
5 changes: 3 additions & 2 deletions tests/urls.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { test, expect } = require("@playwright/test");
const FoundationURLs = require("./foundation-urls.js");
const MozfestURLs = require("./mozfest-urls.js");
const { foundationBaseUrl, mozfestBaseUrl } = require("./base-urls.js");

/**
* Test to see if the given URL can be loaded
Expand All @@ -18,11 +19,11 @@ function testURL(baseUrl, path) {
}

function testFoundationURL(path, locale = `en`) {
return testURL(`http://localhost:8000/${locale}`, path);
return testURL(foundationBaseUrl(locale), path);
}

function testMozfestURL(path, locale = `en`) {
return testURL(`http://mozfest.localhost:8000/${locale}`, path);
return testURL(mozfestBaseUrl(locale), path);
}

test.describe.parallel(`Foundation page tests`, () => {
Expand Down
5 changes: 3 additions & 2 deletions tests/visual.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const percySnapshot = require("@percy/playwright");
const waitForImagesToLoad = require("./wait-for-images.js");
const FoundationURLs = require("./foundation-urls.js");
const MozfestURLs = require("./mozfest-urls.js");
const { foundationBaseUrl, mozfestBaseUrl } = require("./base-urls.js");

const runTime = Date.now();
/**
Expand Down Expand Up @@ -58,12 +59,12 @@ function testURL(baseUrl, path) {

// fall-through call for foundation URLs
function testFoundationURL(path, locale = `en`) {
return testURL(`http://localhost:8000/${locale}`, path);
return testURL(foundationBaseUrl(locale), path);
}

// fall-through call for mozfest URLs
function testMozfestURL(path, locale = `en`) {
return testURL(`http://mozfest.localhost:8000/${locale}`, path);
return testURL(mozfestBaseUrl(locale), path);
}

test.describe.parallel(`Foundation page tests`, () => {
Expand Down

0 comments on commit ac45f72

Please sign in to comment.