Skip to content

Translate · E2E tests

6 modules · 31 exports · 0 repositories · 2 e2e tests · 3 routes

  • SSendou
  • Arrange data setup
  • Act what the user does
  • Assert what is expected

Translate

saves a draft, downloads it and previews it on the site

Renders//translate/:language/translate/:language

SSendou
Translate language page
Act
  1. Open the translate language page “de”, status “all” search “actions.addNew”
    await translate.goto("de", { status: "all", search: "actions.addNew" });
  2. Entry “common:actions.addNew” → entry
    const entry = translate.entry(KEY);
  3. Fill entry.textarea with “{{name}} Neu”
    await entry.textarea.fill("{{name}} Neu");
Assert
  1. entry.issues contains “{{name}}”
    await expect(entry.issues).toContainText("{{name}}");
  2. entry.saveButton is disabled
    await expect(entry.saveButton).toBeDisabled();
Act
  1. Fill entry.textarea with “Etwas Neues”
    await entry.textarea.fill(DRAFT);
  2. Click entry.saveButton
    await entry.saveButton.click();
  3. Open the translate language page “de”, status “drafts”
    await translate.goto("de", { status: "drafts" });
Assert
  1. entries count is 1
    await expect(translate.locators.entries).toHaveCount(1);
Act
  1. Wait for event “download” → downloadPromise
    const downloadPromise = page.waitForEvent("download");
  2. Click download button
    await translate.locators.downloadButton.click();
Assert
  1. download = downloadPromise
    const download = await downloadPromise;
  2. download.suggestedFilename() is “common.json”
    expect(download.suggestedFilename()).toBe("common.json");
  3. common = JSON.parse(fs.readFileSync(await download.path(), "utf8"))
    const common = JSON.parse(fs.readFileSync(await download.path(), "utf8"));
  4. common["actions.addNew"] is “Etwas Neues”
    expect(common["actions.addNew"]).toBe(DRAFT);
  5. common["actions.save"] is truthy
    expect(common["actions.save"]).toBeTruthy();
Act
  1. Click preview button
    await translate.locators.previewButton.click();
  2. Wait for URL (url) => url.pathname === "/"
    await page.waitForURL((url) => url.pathname === "/");
Assert
  1. preview banner is visible
    await expect(translate.locators.previewBanner).toBeVisible();
  2. first text “Etwas Neues” is visible
    await expect(page.getByText(DRAFT).first()).toBeVisible();
Source
test("saves a draft, downloads it and previews it on the site", async ({
	page,
}) => {
	const translate = new TranslateLanguagePage(page);

	// the draft is previewed on the "Add new" button, shown to logged in users
	await impersonate(page);
	await translate.goto("de", { status: "all", search: "actions.addNew" });

	const entry = translate.entry(KEY);

	await entry.textarea.fill("{{name}} Neu");
	await expect(entry.issues).toContainText("{{name}}");
	await expect(entry.saveButton).toBeDisabled();

	await entry.textarea.fill(DRAFT);
	await entry.saveButton.click();

	await translate.goto("de", { status: "drafts" });
	await expect(translate.locators.entries).toHaveCount(1);

	const downloadPromise = page.waitForEvent("download");
	await translate.locators.downloadButton.click();
	const download = await downloadPromise;
	expect(download.suggestedFilename()).toBe("common.json");
	const common = JSON.parse(fs.readFileSync(await download.path(), "utf8"));
	expect(common["actions.addNew"]).toBe(DRAFT);
	expect(common["actions.save"]).toBeTruthy();

	await translate.locators.previewButton.click();
	await page.waitForURL((url) => url.pathname === "/");

	await expect(translate.locators.previewBanner).toBeVisible();
	await expect(page.getByText(DRAFT).first()).toBeVisible();
})

imports translation files as drafts

Renders/translate/:language/translate/:language

LOLogged out
Translate language page
Act
  1. Open the translate language page “de”, status “drafts”
    await translate.goto("de", { status: "drafts" });
  2. Upload to import input name “common.json” mime type “application/json” buffer Buffer.from( JSON.stringify({ "actions.addNew": DRAFT, "actions.save": "Speic…
    await translate.locators.importInput.setInputFiles({
    	name: "common.json",
    	mimeType: "application/json",
    	buffer: Buffer.from(
    		JSON.stringify({
    			"actions.addNew": DRAFT,
    			"actions.save": "Speichern",
    			"not.a.key": "Ignoriert",
    		}),
    	),
    });
Assert
  1. entries count is 1
    await expect(translate.locators.entries).toHaveCount(1);
  2. textarea has value “Etwas Neues”
    await expect(translate.entry(KEY).textarea).toHaveValue(DRAFT);
Source
test("imports translation files as drafts", async ({ page }) => {
	const translate = new TranslateLanguagePage(page);

	await translate.goto("de", { status: "drafts" });
	await translate.locators.importInput.setInputFiles({
		name: "common.json",
		mimeType: "application/json",
		buffer: Buffer.from(
			JSON.stringify({
				"actions.addNew": DRAFT,
				"actions.save": "Speichern",
				"not.a.key": "Ignoriert",
			}),
		),
	});

	await expect(translate.locators.entries).toHaveCount(1);
	await expect(translate.entry(KEY).textarea).toHaveValue(DRAFT);
})