Skip to content

Commit

Permalink
Merge pull request #89 from manh-t/feature/38-integration-test-questi…
Browse files Browse the repository at this point in the history
…on-page-and-question-complete-page

[#38] [Chore] UI Integration Testing - Question page and Completion page
  • Loading branch information
manh-t authored Sep 14, 2023
2 parents 3d76c07 + 3c85d61 commit d493c4b
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 40 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', () => {
cy.visit('/surveys/d5de6a8f8f5f1cfe51bc/questions/complete');

cy.location().should((location) => {
expect(location.pathname).to.equal('/');
});
});
});
});
86 changes: 86 additions & 0 deletions cypress/e2e/Question/index.spec.ts
Original file line number Diff line number Diff line change
@@ -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('/');
});
});
});
});
});
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 d493c4b

Please sign in to comment.