From d351887e0a91f9f101f4f482cc39f09532390f65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Boixader=20G=C3=BCell?= Date: Fri, 5 Jan 2024 16:25:05 +0100 Subject: [PATCH] test: language test --- e2e/cypress/integration/language.js | 53 +++++++++++++++++++++++++++++ e2e/cypress/support/login.js | 16 ++++++--- e2e/vite_example/src/App.tsx | 4 ++- 3 files changed, 68 insertions(+), 5 deletions(-) create mode 100644 e2e/cypress/integration/language.js diff --git a/e2e/cypress/integration/language.js b/e2e/cypress/integration/language.js new file mode 100644 index 0000000..a2347b3 --- /dev/null +++ b/e2e/cypress/integration/language.js @@ -0,0 +1,53 @@ +import { ITEMS_PANELS_SELECTORS } from '../elements/panels-selectors' + +describe('check languages', function () { + beforeEach('clear', function () { + cy.clearLocalStorage() + cy.clearCookies() + }) + + it('Check eng language', function () { + cy.containerLogin() + cy.findAllByText('Addons').click() + cy.findAllByText('Install') + cy.findAllByText('Remove') + cy.findAllByText('Available Addons') + cy.findAllByText('Installed Addons') + cy.findAllByText('Actions').click() + cy.findAllByText('Delete') + cy.findAllByText('Move to...') + cy.findAllByText('Copy to...') + }) + + it('Check ca language', function () { + cy.containerLogin({ + language: 'ca', + }) + cy.findAllByText('Addons').click() + cy.findAllByText('InstalĀ·la') + cy.findAllByText('Elimina') + cy.findAllByText('Addons Disponibles') + cy.findAllByText('Addons InstalĀ·lats') + + cy.findAllByText('Actions').click() + cy.findAllByText('Elimina') + cy.findAllByText('Mou a...') + cy.findAllByText('Copia a...') + }) + + it('Check es language', function () { + cy.containerLogin({ + language: 'es', + }) + cy.findAllByText('Addons').click() + cy.findAllByText('Instalar') + cy.findAllByText('Eliminar') + cy.findAllByText('Complementos Disponibles') + cy.findAllByText('Complementos Instalados') + + cy.findAllByText('Actions').click() + cy.findAllByText('Eliminar') + cy.findAllByText('Mover a...') + cy.findAllByText('Copiar a...') + }) +}) diff --git a/e2e/cypress/support/login.js b/e2e/cypress/support/login.js index 8709e22..6075497 100644 --- a/e2e/cypress/support/login.js +++ b/e2e/cypress/support/login.js @@ -3,7 +3,7 @@ import { BREADCRUMB_SELECTORS } from '../elements/breadcrumb-selectors' Cypress.Commands.add( 'autologin', - function ({ username, password, api_url } = {}) { + function ({ username, password, api_url, language = 'en' } = {}) { const url = api_url || Cypress.env('GUILLOTINA') const user = username || 'root' const pw = password || 'root' @@ -21,7 +21,11 @@ Cypress.Commands.add( cy.setLocalStorage('auth_expires', new Date(response.body.exp).getTime()) }) - cy.visit('/') + cy.visit('/', { + onBeforeLoad(win) { + Object.defineProperty(win.navigator, 'language', { value: language }) + }, + }) cy.get('.box > .container').should('be.visible') } ) @@ -66,14 +70,18 @@ Cypress.Commands.add( Cypress.Commands.add( 'containerLogin', - function ({ username, password, api_url } = {}) { + function ({ username, password, api_url, language = 'en' } = {}) { cy.intercept('POST', `/@login`).as('login') const url = api_url || Cypress.env('GUILLOTINA') const user = username || 'root' const pw = password || 'root' cy.interceptPostObject('@login') - cy.visit('/') + cy.visit('/', { + onBeforeLoad(win) { + Object.defineProperty(win.navigator, 'language', { value: language }) + }, + }) cy.get(LOGIN_SELECTORS.form).should('be.visible') cy.get(LOGIN_SELECTORS.username).type('root').should('have.value', 'root') cy.get(LOGIN_SELECTORS.password).type('root').should('have.value', 'root') diff --git a/e2e/vite_example/src/App.tsx b/e2e/vite_example/src/App.tsx index eef543a..6c81d70 100644 --- a/e2e/vite_example/src/App.tsx +++ b/e2e/vite_example/src/App.tsx @@ -109,7 +109,7 @@ function App() { const [currentSchema, setCurrentSchema] = useState('/') const [clientInstance, setClientInstance] = useState(undefined) const [isLogged, setLogged] = useState(auth.isLogged) - console.log('auth is logged', auth.isLogged) + useEffect(() => { setClientInstance(getClient(url, currentSchema, auth)) }, [currentSchema]) @@ -127,11 +127,13 @@ function App() { return null } + console.log('language', navigator.language) return ( {isLogged && (