From 63408c179a51976aa711afd78e2eddc1e76492f2 Mon Sep 17 00:00:00 2001 From: Tran Manh Date: Mon, 28 Aug 2023 11:06:54 +0700 Subject: [PATCH] [#35] Extract data to constant for cypress --- cypress/e2e/SignIn/index.spec.ts | 23 ++++++++++++++--------- cypress/support/constants.ts | 6 ++++++ 2 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 cypress/support/constants.ts diff --git a/cypress/e2e/SignIn/index.spec.ts b/cypress/e2e/SignIn/index.spec.ts index ab48418..62a0600 100644 --- a/cypress/e2e/SignIn/index.spec.ts +++ b/cypress/e2e/SignIn/index.spec.ts @@ -1,3 +1,5 @@ +import { api } from '../../support/constants'; + const signInScreenTestIds = { nimbleLogo: 'sign-in__nimble-logo', signInForm: 'sign-in-form', @@ -12,23 +14,25 @@ const signInScreenTestIds = { }; describe('SignIn screen', () => { - context('given the valid form submission', () => { + context('given a valid form submission', () => { beforeEach(() => { - cy.interceptWithDelay('GET', '**/api/v1/surveys*', 200, { - statusCode: 200, + cy.interceptWithDelay('GET', '**/api/v1/surveys*', api.delay.short, { + statusCode: api.status.success, fixture: 'Survey/List/valid.json', }); - cy.interceptWithDelay('GET', '**/api/v1/me', 200, { - statusCode: 200, + + cy.interceptWithDelay('GET', '**/api/v1/me', api.delay.short, { + statusCode: api.status.success, fixture: 'User/valid.json', }); }); it('shows the loading dialog and navigates to Dashboard screen', () => { - cy.interceptWithDelay('POST', '**/api/v1/oauth/token', 200, { - statusCode: 200, + cy.interceptWithDelay('POST', '**/api/v1/oauth/token', api.delay.short, { + statusCode: api.status.success, fixture: 'Authentication/SignIn/valid.json', }); + cy.visit('/'); cy.location().should((location) => { expect(location.pathname).to.equal('/sign-in'); @@ -48,10 +52,11 @@ describe('SignIn screen', () => { context('given the invalid form submission', () => { it('shows the error dialog', () => { - cy.interceptWithDelay('POST', '**/api/v1/oauth/token', 200, { - statusCode: 400, + cy.interceptWithDelay('POST', '**/api/v1/oauth/token', api.delay.short, { + statusCode: api.status.badRequest, fixture: 'Authentication/SignIn/invalid.json', }); + cy.visit('/'); cy.findByTestId(signInScreenTestIds.emailField).type('test@email.com'); cy.findByTestId(signInScreenTestIds.passwordField).type('12345678'); diff --git a/cypress/support/constants.ts b/cypress/support/constants.ts new file mode 100644 index 0000000..f672b30 --- /dev/null +++ b/cypress/support/constants.ts @@ -0,0 +1,6 @@ +export const api = { + status: { success: 200, badRequest: 400 }, + delay: { + short: 200, + }, +};