From 69db1d37564a7f0fbdd04f23b9a738ce72941119 Mon Sep 17 00:00:00 2001 From: Tran Manh Date: Tue, 25 Jul 2023 16:00:48 +0700 Subject: [PATCH 1/2] [#38] Implement integration test for Question page and Question Complete page --- cypress/e2e/Question/Complete/index.spec.ts | 30 +++++++ cypress/e2e/Question/index.spec.ts | 86 +++++++++++++++++++++ cypress/fixtures/Survey/Detail/valid.json | 40 ---------- cypress/fixtures/Survey/Submit/invalid.json | 7 ++ cypress/fixtures/Survey/Submit/valid.json | 1 + 5 files changed, 124 insertions(+), 40 deletions(-) create mode 100644 cypress/e2e/Question/Complete/index.spec.ts create mode 100644 cypress/e2e/Question/index.spec.ts create mode 100644 cypress/fixtures/Survey/Submit/invalid.json create mode 100644 cypress/fixtures/Survey/Submit/valid.json diff --git a/cypress/e2e/Question/Complete/index.spec.ts b/cypress/e2e/Question/Complete/index.spec.ts new file mode 100644 index 0000000..82638bb --- /dev/null +++ b/cypress/e2e/Question/Complete/index.spec.ts @@ -0,0 +1,30 @@ +describe('Question Complete screen', () => { + context('given the Question Complete screen is opened', () => { + beforeEach(() => { + cy.signIn(); + cy.interceptWithDelay('GET', '**/api/v1/surveys/*', 200, { + statusCode: 200, + fixture: 'Survey/Detail/valid.json', + }); + cy.interceptWithDelay('GET', '**/api/v1/surveys*', 200, { + statusCode: 200, + fixture: 'Survey/List/valid.json', + }); + cy.interceptWithDelay('GET', '**/api/v1/me', 200, { + statusCode: 200, + fixture: 'User/valid.json', + }); + cy.interceptWithDelay('POST', '**/responses', 200, { + statusCode: 201, + fixture: 'Survey/Submit/valid.json', + }); + }); + it('navigates to the Home screen after 3 seconds', () => { + cy.visit('/surveys/d5de6a8f8f5f1cfe51bc/questions/complete'); + + cy.location().should((location) => { + expect(location.pathname).to.equal('/'); + }); + }); + }); +}); diff --git a/cypress/e2e/Question/index.spec.ts b/cypress/e2e/Question/index.spec.ts new file mode 100644 index 0000000..36c8b24 --- /dev/null +++ b/cypress/e2e/Question/index.spec.ts @@ -0,0 +1,86 @@ +const questionTestIds = { + questionIndex: 'question__index', + questionTitle: 'question__title', + questionAnswer: 'question__answer', + questionCloseButton: 'question__close-button', + questionNextButton: 'question__next-button', + questionSubmitButton: 'question__submit-button', + confirmDialogPositiveButton: 'confirm-dialog__positive-button', + surveyStartSurveyButton: 'survey__start-survey-button', +}; + +describe('Question screen', () => { + context('given the submit button is clicked', () => { + context('given the API responses returns success result', () => { + beforeEach(() => { + cy.signIn(); + cy.interceptWithDelay('GET', '**/api/v1/surveys/*', 200, { + statusCode: 200, + fixture: 'Survey/Detail/valid.json', + }); + cy.interceptWithDelay('GET', '**/api/v1/surveys*', 200, { + statusCode: 200, + fixture: 'Survey/List/valid.json', + }); + cy.interceptWithDelay('GET', '**/api/v1/me', 200, { + statusCode: 200, + fixture: 'User/valid.json', + }); + cy.interceptWithDelay('POST', '**/responses', 200, { + statusCode: 201, + fixture: 'Survey/Submit/valid.json', + }); + }); + + it('navigates to the Question Complete screen', () => { + cy.visit('/'); + cy.visit('/surveys/d5de6a8f8f5f1cfe51bc'); + + // Go to Question screen + cy.findByTestId(questionTestIds.surveyStartSurveyButton).click(); + + cy.findByTestId(questionTestIds.questionNextButton).click(); + cy.findByTestId(questionTestIds.questionSubmitButton).click(); + + cy.location({ timeout: 1000 }).should((location) => { + expect(location.pathname).to.equal('/surveys/d5de6a8f8f5f1cfe51bc/questions/complete'); + }); + }); + }); + }); + + context('given the close button is clicked', () => { + context('given the Positive button of the confirm dialog is clicked', () => { + beforeEach(() => { + cy.signIn(); + cy.interceptWithDelay('GET', '**/api/v1/surveys/*', 200, { + statusCode: 200, + fixture: 'Survey/Detail/valid.json', + }); + cy.interceptWithDelay('GET', '**/api/v1/surveys*', 200, { + statusCode: 200, + fixture: 'Survey/List/valid.json', + }); + cy.interceptWithDelay('GET', '**/api/v1/me', 200, { + statusCode: 200, + fixture: 'User/valid.json', + }); + }); + + it('navigates back to Home', () => { + cy.visit('/'); + cy.visit('/surveys/d5de6a8f8f5f1cfe51bc'); + + // Go to Question screen + cy.findByTestId(questionTestIds.surveyStartSurveyButton).click(); + + cy.findByTestId(questionTestIds.questionCloseButton).click(); + cy.findByTestId(questionTestIds.confirmDialogPositiveButton).click(); + + cy.location().should((location) => { + expect(location.pathname).to.equal('/'); + }); + }); + }); + }); +}); diff --git a/cypress/fixtures/Survey/Detail/valid.json b/cypress/fixtures/Survey/Detail/valid.json index 8cab687..c0a51d3 100644 --- a/cypress/fixtures/Survey/Detail/valid.json +++ b/cypress/fixtures/Survey/Detail/valid.json @@ -24,46 +24,6 @@ { "id": "940d229e4cd87cd1e202", "type": "question" - }, - { - "id": "ea0555f328b3b0124127", - "type": "question" - }, - { - "id": "16e68f5610ef0e0fa4db", - "type": "question" - }, - { - "id": "bab38ad82eaf22afcdfe", - "type": "question" - }, - { - "id": "85275a0bf28a6f3b1e63", - "type": "question" - }, - { - "id": "642770376f7cd0c87d3c", - "type": "question" - }, - { - "id": "b093a6ad9a6a466fa787", - "type": "question" - }, - { - "id": "e593b2fa2f81891a2b1e", - "type": "question" - }, - { - "id": "c3a9b8ce5c2356010703", - "type": "question" - }, - { - "id": "fbf5d260de1ee6195473", - "type": "question" - }, - { - "id": "4372463ce56db58c0983", - "type": "question" } ] } diff --git a/cypress/fixtures/Survey/Submit/invalid.json b/cypress/fixtures/Survey/Submit/invalid.json new file mode 100644 index 0000000..ebdc30d --- /dev/null +++ b/cypress/fixtures/Survey/Submit/invalid.json @@ -0,0 +1,7 @@ +{ + "errors": [ + { + "detail": "The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client." + } + ] +} diff --git a/cypress/fixtures/Survey/Submit/valid.json b/cypress/fixtures/Survey/Submit/valid.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/cypress/fixtures/Survey/Submit/valid.json @@ -0,0 +1 @@ +{} From 3c85d6154035080dbd9e722241b05ab609e983fc Mon Sep 17 00:00:00 2001 From: Tran Manh Date: Thu, 14 Sep 2023 15:07:22 +0700 Subject: [PATCH 2/2] [#38] Remove redundant text --- cypress/e2e/Question/Complete/index.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cypress/e2e/Question/Complete/index.spec.ts b/cypress/e2e/Question/Complete/index.spec.ts index 82638bb..389c58a 100644 --- a/cypress/e2e/Question/Complete/index.spec.ts +++ b/cypress/e2e/Question/Complete/index.spec.ts @@ -19,7 +19,7 @@ describe('Question Complete screen', () => { fixture: 'Survey/Submit/valid.json', }); }); - it('navigates to the Home screen after 3 seconds', () => { + it('navigates to the Home screen', () => { cy.visit('/surveys/d5de6a8f8f5f1cfe51bc/questions/complete'); cy.location().should((location) => {