From bc03bffe70a98edb0d4099747fda82bdaf945c2f Mon Sep 17 00:00:00 2001 From: Alican Erdurmaz Date: Mon, 5 Aug 2024 10:20:34 +0300 Subject: [PATCH] test(cypress): add e2e for i18n-nextjs and i18n-react (#6218) Co-authored-by: Batuhan Wilhelm --- .github/workflows/build-examples.yml | 1 + cypress/e2e/i18n-nextjs/all.cy.ts | 75 ++++++++++++++++++++++++++++ cypress/e2e/i18n-react/all.cy.ts | 63 +++++++++++++++++++++++ 3 files changed, 139 insertions(+) create mode 100644 cypress/e2e/i18n-nextjs/all.cy.ts create mode 100644 cypress/e2e/i18n-react/all.cy.ts diff --git a/.github/workflows/build-examples.yml b/.github/workflows/build-examples.yml index 625797805093..8a2fb06b01a6 100644 --- a/.github/workflows/build-examples.yml +++ b/.github/workflows/build-examples.yml @@ -5,6 +5,7 @@ on: paths: - "packages/**" - "examples/**" + - "cypress/e2e/**" types: - labeled - synchronize diff --git a/cypress/e2e/i18n-nextjs/all.cy.ts b/cypress/e2e/i18n-nextjs/all.cy.ts new file mode 100644 index 000000000000..672c04eeaf17 --- /dev/null +++ b/cypress/e2e/i18n-nextjs/all.cy.ts @@ -0,0 +1,75 @@ +/// +/// + +Cypress.on("uncaught:exception", () => { + return false; +}); + +describe("i18n-nextjs", () => { + beforeEach(() => { + cy.clearAllCookies(); + cy.clearAllLocalStorage(); + cy.clearAllSessionStorage(); + + cy.interceptGETBlogPosts(); + cy.visit("/"); + }); + + it("should change", () => { + cy.wait("@getBlogPosts"); + + // check the elements are in English which is the default language + cy.get(".ant-menu > .ant-menu-item") + .contains("Blog Posts") + .get(".ant-page-header-heading-left") + .contains("Posts") + .get(".refine-create-button") + .contains("Create") + .get(".ant-table-thead > tr > :nth-child(2)") + .contains("Title") + .get(".ant-table-thead > tr > :nth-child(3)") + .contains("Content") + .get(".ant-table-thead > tr > :nth-child(4)") + .contains("Category") + .get(".ant-table-thead > tr > :nth-child(5)") + .contains("Status") + .get(".ant-table-thead > tr > :nth-child(6)") + .contains("Created At") + .get(".ant-table-thead > tr > :nth-child(7)") + .contains("Actions"); + + // find the language button + cy.get(".ant-layout-header > .ant-btn") + // should contain English which is the default language + .contains("English") + // hover over the button to show the dropdown + .trigger("mouseover") + // click on the German language + .get(".ant-dropdown-menu-title-content") + .contains("German") + .click() + // should contain German + .get(".ant-layout-header > .ant-btn") + .contains("German"); + + // check the elements are translated + cy.get(".ant-menu > .ant-menu-item") + .contains("Einträge") + .get(".ant-page-header-heading-left") + .contains("Einträge") + .get(".refine-create-button") + .contains("Erstellen") + .get(".ant-table-thead > tr > :nth-child(2)") + .contains("Titel") + .get(".ant-table-thead > tr > :nth-child(3)") + .contains("Inhalh") + .get(".ant-table-thead > tr > :nth-child(4)") + .contains("Kategorie") + .get(".ant-table-thead > tr > :nth-child(5)") + .contains("Status") + .get(".ant-table-thead > tr > :nth-child(6)") + .contains("Erstellt am") + .get(".ant-table-thead > tr > :nth-child(7)") + .contains("Aktionen"); + }); +}); diff --git a/cypress/e2e/i18n-react/all.cy.ts b/cypress/e2e/i18n-react/all.cy.ts new file mode 100644 index 000000000000..6884cc50df55 --- /dev/null +++ b/cypress/e2e/i18n-react/all.cy.ts @@ -0,0 +1,63 @@ +/// +/// + +Cypress.on("uncaught:exception", () => { + return false; +}); + +describe("i18n-react", () => { + beforeEach(() => { + cy.clearAllCookies(); + cy.clearAllLocalStorage(); + cy.clearAllSessionStorage(); + + cy.interceptGETPosts(); + cy.visit("/"); + }); + + it("should change", () => { + cy.wait("@getPosts"); + + // check the elements are in English which is the default language + cy.get(".ant-menu > .ant-menu-item") + .contains("Posts") + .get(".ant-page-header-heading-left") + .contains("Posts") + .get(".refine-create-button") + .contains("Create") + .get(".ant-table-thead > tr > :nth-child(2)") + .contains("Title") + .get(".ant-table-thead > tr > :nth-child(3)") + .contains("Category") + .get(".ant-table-thead > tr > :nth-child(4)") + .contains("Actions"); + + // find the language button + cy.get(".ant-layout-header > .ant-btn") + // should contain English which is the default language + .contains("English") + // hover over the button to show the dropdown + .trigger("mouseover") + // click on the German language + .get(".ant-dropdown-menu-title-content") + .contains("German") + .click() + // should contain German + .get(".ant-layout-header > .ant-btn") + .contains("German"); + + // check the elements are translated + cy.get(".ant-menu > .ant-menu-item") + .contains("Einträge") + .get(".ant-page-header-heading-left") + .contains("Einträge") + .get(".refine-create-button") + .contains("Erstellen") + .get(".ant-table-thead > tr > :nth-child(2)") + .contains("Titel") + .get(".ant-table-thead > tr > :nth-child(3)") + .contains("Kategorie") + .get(".ant-table-thead > tr > :nth-child(4)") + .contains("Aktionen"); + }); +});