Skip to content

Commit

Permalink
Add simple cypress test
Browse files Browse the repository at this point in the history
  • Loading branch information
magnurh-cx committed Dec 6, 2024
1 parent 1978df6 commit ae9bb71
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/bygger-backend/src/routers/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import enhetsliste from './enhetsliste';
import formDiff from './formDiff';
import formioGlobalTranslationsRouter from './formio-global-translations';
import formsRouter from './forms';
import formsApiFormTranslations from './forms-api-form-translations';
import formsApiFormTranslationsRouter from './forms-api-form-translations';
import formsApiGlobalTranslationsRouter from './forms-api-global-translations';
import apiErrorHandler from './helpers/apiErrorHandler';
import authHandlers from './helpers/authHandlers';
Expand Down Expand Up @@ -48,7 +48,7 @@ apiRouter.get('/form/:formPath/diff', formDiff);
apiRouter.use('/forms', formsRouter);
apiRouter.use('/recipients', formsApiAuthHandler, recipientsRouter);
apiRouter.use('/forms-api/global-translations', formsApiAuthHandler, formsApiGlobalTranslationsRouter);
apiRouter.use('/forms-api/translations', formsApiAuthHandler, formsApiFormTranslations);
apiRouter.use('/forms-api/translations', formsApiAuthHandler, formsApiFormTranslationsRouter);
apiRouter.use('/import', importRouter);
apiRouter.use('/global-translations', authorizedPublisher, formioGlobalTranslationsRouter);
apiRouter.post('/log/:level', rateLimiter(60000, 60), log);
Expand Down
38 changes: 38 additions & 0 deletions packages/bygger/cypress/e2e/globalTranslations.spec.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { expect } from 'chai';

describe('Global translations', () => {
beforeEach(() => {
cy.intercept('GET', '/api/config', { fixture: 'config.json' }).as('getConfig');
cy.intercept('GET', '/api/forms-api/global-translations', { fixture: 'formsApiGlobalTranslations.json' }).as(
'getGlobalTranslations',
);
});

describe('Skjematekster', () => {
beforeEach(() => {
cy.visit('/oversettelser');
cy.wait('@getGlobalTranslations');
});

it('Adds new translation', () => {
cy.intercept('POST', '/api/forms-api/global-translations', (req) => {
expect(req.body).to.deep.equal({
key: 'Ny tekst',
nb: 'Ny tekst',
nn: 'Ny tekst (nynorsk)',
en: 'New text',
tag: 'skjematekster',
});
req.reply(200, req.body);
}).as('postGlobalTranslation');
cy.findByRole('textbox', { name: 'Bokmål' }).type('Ny tekst');
cy.findByRole('textbox', { name: 'Nynorsk' }).type('Ny tekst (nynorsk)');
cy.findByRole('textbox', { name: 'Engelsk' }).type('New text');
cy.findByRole('button', { name: 'Lagre' }).click();
cy.wait('@postGlobalTranslation');
cy.findByRole('textbox', { name: 'Bokmål' }).should('have.value', '');
cy.findByRole('textbox', { name: 'Nynorsk' }).should('have.value', '');
cy.findByRole('textbox', { name: 'Engelsk' }).should('have.value', '');
});
});
});
54 changes: 54 additions & 0 deletions packages/bygger/cypress/fixtures/formsApiGlobalTranslations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[
{
"id": 1,
"key": "Ny",
"tag": "skjematekster",
"changedAt": "2024-12-05T14:39:27.512821+01:00",
"changedBy": "Testesen, Test",
"revision": 4,
"nb": "Ny",
"nn": "Ny",
"en": "New",
"publishedAt": null,
"publishedBy": null
},
{
"id": 2,
"key": "Nyere",
"tag": "skjematekster",
"changedAt": "2024-12-05T14:39:27.498692+01:00",
"changedBy": "Testesen, Test",
"revision": 3,
"nb": "Nyere",
"nn": "Nyare",
"en": "Newer",
"publishedAt": null,
"publishedBy": null
},
{
"id": 3,
"key": "Abc",
"tag": "skjematekster",
"changedAt": "2024-12-05T14:39:27.489663+01:00",
"changedBy": "Testesen, Test",
"revision": 4,
"nb": "Abc",
"nn": "Def",
"en": "Xyz",
"publishedAt": null,
"publishedBy": null
},
{
"id": 4,
"key": "Hei",
"tag": "skjematekster",
"changedAt": "2024-12-05T14:39:27.493745+01:00",
"changedBy": "Testesen, Test",
"revision": 6,
"nb": "Hei",
"nn": "",
"en": "Hello",
"publishedAt": null,
"publishedBy": null
}
]

0 comments on commit ae9bb71

Please sign in to comment.