Skip to content

Commit

Permalink
[#35] Extract data to constant for cypress
Browse files Browse the repository at this point in the history
  • Loading branch information
manh-t committed Aug 28, 2023
1 parent ae6c043 commit 63408c1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
23 changes: 14 additions & 9 deletions cypress/e2e/SignIn/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { api } from '../../support/constants';

const signInScreenTestIds = {
nimbleLogo: 'sign-in__nimble-logo',
signInForm: 'sign-in-form',
Expand All @@ -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');
Expand All @@ -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('[email protected]');
cy.findByTestId(signInScreenTestIds.passwordField).type('12345678');
Expand Down
6 changes: 6 additions & 0 deletions cypress/support/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const api = {
status: { success: 200, badRequest: 400 },
delay: {
short: 200,
},
};

0 comments on commit 63408c1

Please sign in to comment.