Skip to content

Commit

Permalink
[#38] Implement integration test for Question page and Question Compl…
Browse files Browse the repository at this point in the history
…ete page
  • Loading branch information
manh-t committed Jul 25, 2023
1 parent 931b0aa commit d111e8c
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 41 deletions.
30 changes: 30 additions & 0 deletions cypress/e2e/Question/Complete/index.spec.ts
Original file line number Diff line number Diff line change
@@ -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('/');
});
});
});
});
90 changes: 90 additions & 0 deletions cypress/e2e/Question/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { surveyScreenTestIds } from '../Survey/index.spec';

const questionScreenTestIds = {
index: 'question__index',
title: 'question__title',
answer: 'question__answer',
closeButton: 'question__close-button',
nextButton: 'question__next-button',
submitButton: 'question__submit-button',
};

const confirmDialogDataTestIds = {
positiveButton: 'confirm-dialog__positive-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(surveyScreenTestIds.startSurveyButton).click();

cy.findByTestId(questionScreenTestIds.nextButton).click();
cy.findByTestId(questionScreenTestIds.submitButton).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(surveyScreenTestIds.startSurveyButton).click();

cy.findByTestId(questionScreenTestIds.closeButton).click();
cy.findByTestId(confirmDialogDataTestIds.positiveButton).click();

cy.location().should((location) => {
expect(location.pathname).to.equal('/');
});
});
});
});
});
2 changes: 1 addition & 1 deletion cypress/e2e/Survey/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const surveyScreenTestIds = {
export const surveyScreenTestIds = {
backgroundImage: 'survey__background-image',
backButton: 'survey__back-button',
coverImage: 'survey__cover-image',
Expand Down
40 changes: 0 additions & 40 deletions cypress/fixtures/Survey/Detail/valid.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
Expand Down
7 changes: 7 additions & 0 deletions cypress/fixtures/Survey/Submit/invalid.json
Original file line number Diff line number Diff line change
@@ -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."
}
]
}
1 change: 1 addition & 0 deletions cypress/fixtures/Survey/Submit/valid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}

0 comments on commit d111e8c

Please sign in to comment.