Skip to content

Commit

Permalink
[E2E] Add tests for translations (#4723)
Browse files Browse the repository at this point in the history
* add changeset

* add ttest for add and edit translation

* add test for celaring translation
  • Loading branch information
szczecha authored Mar 18, 2024
1 parent 12622c1 commit 31e4575
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/sharp-cobras-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": patch
---

add playwright test for translations
18 changes: 18 additions & 0 deletions playwright/data/e2eTestData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,3 +380,21 @@ export const APPS = {
info: "App used in delete app test",
}
}

export const TRANSLATIONS = {
translationsToBeAdded: {
id: "Q2F0ZWdvcnk6NTEy",
name: "CategoryToTranslate",
info: "Category used to add translation test",
},
translationsToBeEdited: {
id: "UHJvZHVjdDo3OA==",
name: "Green Juice",
info: "Product used to edit translation test",
},
translationsToBeCleared: {
id: "Q29sbGVjdGlvbjox",
name: "Summer collection",
info: "Translation used in clear translation test",
}
}
28 changes: 26 additions & 2 deletions playwright/pages/translationsPage.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
import type { Page } from "@playwright/test";
import { URL_LIST } from "@data/url";
import { BasePage } from "@pages/basePage";

export class TranslationsPage {
export class TranslationsPage extends BasePage {
readonly page: Page;
readonly basePage: BasePage;

constructor(page: Page) {

constructor(page: Page,
readonly translationPl_PL = page.getByTestId("PL_PL"),
readonly editTranslationNameButton = page.getByTestId("edit-name"),
readonly translationInput = page.getByTestId("translation-field").locator("input"),
readonly translationRichText = page
.getByTestId("rich-text-editor-translation")
.locator("[contenteditable]"),
readonly editTranslationDescriptionButton = page.getByTestId("edit-description"),
) {
super(page);
this.page = page;
this.basePage = new BasePage(page);
}

async gotoTranslationsPage() {
await this.page.goto(URL_LIST.translations);
}

async goToDirectTranslationPage(translationCode: string, translatedObjectType: string, translatedObjectId: string,) {
const translationUrl = URL_LIST.translations + translationCode + "/" + translatedObjectType + "/" + translatedObjectId;
await this.page.goto(translationUrl)
}

}
49 changes: 49 additions & 0 deletions playwright/tests/translations.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { TRANSLATIONS } from "@data/e2eTestData";
import { expect, test } from "@playwright/test";
import { TranslationsPage } from "@pages/translationsPage";

test.use({ storageState: "playwright/.auth/admin.json" });
let translationsPage: TranslationsPage;
test.beforeEach(({ page }) => {
translationsPage = new TranslationsPage(page);
});

test("TC: SALEOR_121 Should be able to add translation @e2e @translations", async () => {
await translationsPage.gotoTranslationsPage();
await translationsPage.translationPl_PL.click();
await translationsPage.page.getByText("CategoryToTranslate").click();
await expect(translationsPage.page.getByText("Translation Category \"CategoryToTranslate\" - PL_PL")).toBeVisible();
await translationsPage.editTranslationNameButton.click();
await translationsPage.translationInput.fill("Kategoria do Translacji");
await translationsPage.saveButton.click();
await expect(translationsPage.successBanner).toBeVisible();
await expect(translationsPage.page.getByText("Kategoria do Translacji")).toBeVisible();
});

test("TC: SALEOR_122 Should be able to edit translation @e2e @translations", async () => {
const newDescription = "Brukselka, szpinak, groszek, jarmuż, sałata, kapusta, cukinia, więcej brukselki. Wszystkie warzywa, jakich będziesz potrzebować, w jednym pysznym soku."

await translationsPage.goToDirectTranslationPage("PL_PL", "products", TRANSLATIONS.translationsToBeEdited.id);
await expect(translationsPage.page.getByText("Translation Product \"Green Juice\" - PL_PL")).toBeVisible();
await expect(translationsPage.page.getByText("Brukselka, szpinak")).toBeVisible();
await translationsPage.editTranslationDescriptionButton.click();
await translationsPage.translationRichText.clear();
await translationsPage.translationRichText.type(newDescription);

await translationsPage.saveButton.click();
await expect(translationsPage.successBanner).toBeVisible();
await expect(translationsPage.page.getByText(newDescription)).toBeVisible();
});

test("TC: SALEOR_123 Should be able to clear translation @e2e @translations", async () => {
const description = "Letnia kolekcja Saleor obejmuje gamę produktów, które cieszą się popularnością na rynku.Sklep demonstracyjny na każdą porę roku.Saleor uchwycił słońce open source, e-commerce."

await translationsPage.goToDirectTranslationPage("PL_PL", "collections", TRANSLATIONS.translationsToBeCleared.id);
await expect(translationsPage.page.getByText("Translation Collection \"Summer collection\" - PL_PL")).toBeVisible();
await expect(translationsPage.page.getByText(description)).toBeVisible();
await translationsPage.editTranslationDescriptionButton.click();
await translationsPage.translationRichText.clear();
await translationsPage.saveButton.click();
await expect(translationsPage.successBanner).toBeVisible();
await expect(translationsPage.page.getByText(description)).not.toBeVisible();
});

0 comments on commit 31e4575

Please sign in to comment.