Skip to content

Commit

Permalink
test: language test
Browse files Browse the repository at this point in the history
  • Loading branch information
rboixaderg committed Jan 5, 2024
1 parent 8d0e955 commit d351887
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 5 deletions.
53 changes: 53 additions & 0 deletions e2e/cypress/integration/language.js
Original file line number Diff line number Diff line change
@@ -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...')
})
})
16 changes: 12 additions & 4 deletions e2e/cypress/support/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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')
}
)
Expand Down Expand Up @@ -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')
Expand Down
4 changes: 3 additions & 1 deletion e2e/vite_example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -127,11 +127,13 @@ function App() {
return null
}

console.log('language', navigator.language)
return (
<ClientProvider client={clientInstance}>
<Layout auth={auth} onLogout={onLogout}>
{isLogged && (
<Guillotina
locale={navigator.language || 'en'}
auth={auth}
url={currentSchema}
registry={{
Expand Down

0 comments on commit d351887

Please sign in to comment.