-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add E2E test for settings and locale detection
Partially resolves: Add unit tests #33
- Loading branch information
Showing
15 changed files
with
3,524 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { defineConfig } from "cypress"; | ||
|
||
export default defineConfig({ | ||
component: { | ||
devServer: { | ||
framework: "next", | ||
bundler: "webpack", | ||
}, | ||
}, | ||
|
||
e2e: { | ||
baseUrl: "http://localhost:3000", | ||
setupNodeEvents(on, config) { | ||
// implement node event listeners here | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
describe('Locale detection', () => { | ||
beforeEach(() => { | ||
cy.intercept('/api/locales', { | ||
fixture: 'locales.json', | ||
}); | ||
|
||
cy.clearAllCookies(); | ||
cy.clearAllLocalStorage(); | ||
}); | ||
|
||
it('English locale detection', () => { | ||
cy | ||
.intercept('/api/articles?locale=en&metadataOnly=true', { | ||
fixture: 'articles.json', | ||
}) | ||
.as('getArticles'); | ||
cy.visit('/en').intercept('/en').as('page'); // Visit the English homepage | ||
|
||
cy.url().should('include', '/en'); // Check that the URL contains the locale | ||
|
||
cy.getCookie('NEXT_LOCALE').should('have.property', 'value', 'en'); // Check that the locale cookie is set to English | ||
|
||
cy.wait('@getArticles'); // Wait for the locale to be set | ||
cy | ||
.window() | ||
.its('localStorage') | ||
.then((localStorage) => { | ||
expect(localStorage.getItem('settings')).exist; | ||
|
||
const settings = JSON.parse(localStorage.getItem('settings') || '{}'); | ||
|
||
expect(settings.locale).to.equal('en'); // Check that the locale in the settings is set to English | ||
}); | ||
|
||
cy | ||
.title() | ||
.should('eq', 'Survival Manual'); // Check that the title is in English | ||
|
||
cy | ||
.get('h1') | ||
.should('have.text', 'Introduction'); // Check that the text is in English | ||
}); | ||
|
||
it('Ukrainian locale detection', () => { | ||
cy | ||
.intercept('/api/articles?locale=uk&metadataOnly=true', { | ||
fixture: 'articles.uk.json', | ||
}) | ||
.as('getArticles'); | ||
cy.visit('/uk'); // Visit the Ukrainian homepage | ||
|
||
cy.url().should('include', '/uk'); // Check that the URL contains the locale | ||
|
||
cy.getCookie('NEXT_LOCALE').should('have.property', 'value', 'uk'); // Check that the locale cookie is set to Ukrainian | ||
|
||
cy.wait('@getArticles'); // Wait for the locale to be set | ||
cy | ||
.window() | ||
.its('localStorage') | ||
.then((localStorage) => { | ||
expect(localStorage.getItem('settings')).exist; | ||
|
||
const settings = JSON.parse(localStorage.getItem('settings') || '{}'); | ||
|
||
expect(settings.locale).to.equal('uk'); // Check that the locale in the settings is set to English | ||
}); | ||
|
||
cy | ||
.title() | ||
.should('eq', 'Довідник по виживанню'); // Check that the title is in Ukrainian | ||
|
||
cy | ||
.get('h1') | ||
.should('have.text', 'Знайомство'); // Check that the text is in Ukrainian | ||
}); | ||
}); |
Oops, something went wrong.