saves a draft, downloads it and previews it on the site
Renders//translate/:language/translate/:language
SSendou
Translate language page
Act
- Open the translate language page “de”, status “all” search “actions.addNew”
await translate.goto("de", { status: "all", search: "actions.addNew" });
- Entry “common:actions.addNew” → entry
const entry = translate.entry(KEY);
- Fill
entry.textareawith “{{name}} Neu”await entry.textarea.fill("{{name}} Neu");
Assert
entry.issuescontains “{{name}}”await expect(entry.issues).toContainText("{{name}}");
entry.saveButtonis disabledawait expect(entry.saveButton).toBeDisabled();
Act
- Fill
entry.textareawith “Etwas Neues”await entry.textarea.fill(DRAFT);
- Click
entry.saveButtonawait entry.saveButton.click();
- Open the translate language page “de”, status “drafts”
await translate.goto("de", { status: "drafts" });
Assert
- entries count is 1
await expect(translate.locators.entries).toHaveCount(1);
Act
- Wait for event “download” → downloadPromise
const downloadPromise = page.waitForEvent("download");
- Click download button
await translate.locators.downloadButton.click();
Assert
download=downloadPromiseconst download = await downloadPromise;
download.suggestedFilename()is “common.json”expect(download.suggestedFilename()).toBe("common.json");
common=JSON.parse(fs.readFileSync(await download.path(), "utf8"))const common = JSON.parse(fs.readFileSync(await download.path(), "utf8"));
common["actions.addNew"]is “Etwas Neues”expect(common["actions.addNew"]).toBe(DRAFT);
common["actions.save"]is truthyexpect(common["actions.save"]).toBeTruthy();
Act
- Click preview button
await translate.locators.previewButton.click();
- Wait for URL
(url) => url.pathname === "/"await page.waitForURL((url) => url.pathname === "/");
Assert
- preview banner is visible
await expect(translate.locators.previewBanner).toBeVisible();
- 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(); })