Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
gminetoma committed Jan 24, 2025
1 parent d1ebe2f commit 862ac80
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ jobs:
- name: Run Cypress tests
uses: cypress-io/github-action@v6
env:
AUTH0_DOMAIN: https://findadoc.jp.auth0.com/
AUTH0_USERNAME: [email protected]
AUTH0_PASSWORD: vCnL5J8agHg6m2f
with:
command: yarn test:e2e
# env:
# AUTH0_DOMAIN: https://findadoc.jp.auth0.com/
# AUTH0_USERNAME: [email protected]
# AUTH0_PASSWORD: vCnL5J8agHg6m2f

- name: Upload screenshots
uses: actions/upload-artifact@v3
Expand Down
8 changes: 4 additions & 4 deletions test/cypress/e2e/moderationDashboard.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ before(() => {

describe('Moderation dashboard', () => {
before(() => {
cy.intercept('POST', '*', req => {
cy.intercept('POST', '**/', req => {
aliasQuery(req, 'query Submissions', fakeSubmissionResponse)
})

Expand Down Expand Up @@ -111,7 +111,7 @@ describe('Moderation dashboard', () => {
describe('Moderation Edit Submission Form', () => {
context('Landscape mode', () => {
before(() => {
cy.intercept('POST', '*', req => {
cy.intercept('POST', '**/', req => {
aliasQuery(req, 'query Submissions', fakeSubmissionResponse)
})

Expand Down Expand Up @@ -168,7 +168,7 @@ describe('Moderation Edit Submission Form', () => {
cy.get('[data-testid="submission-form-locales"]').should('exist')
})

it('should autofill the form', function() {
it('should autofill the form', () => {
const submission = fakeSubmissionResponse.data.submissions[1].facility

cy.get('[data-testid="submission-form-nameEn"]').find('input')
Expand Down Expand Up @@ -274,7 +274,7 @@ describe('Moderation Edit Submission Modal', () => {
beforeEach(() => {
cy.viewport('macbook-16')

cy.intercept('POST', '*', req => {
cy.intercept('POST', '**/', req => {
aliasQuery(req, 'query Submissions', fakeSubmissionResponse)
})

Expand Down
4 changes: 2 additions & 2 deletions test/cypress/e2e/moderationEditFacility.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ before(() => {

describe('Moderation edit facility form', () => {
context('Landscape mode', () => {
before(function() {
cy.intercept('POST', '*', req => {
before(() => {
cy.intercept('POST', '**/', req => {
aliasQuery(req, 'query Facilities', fakeFacilityResult)
})

Expand Down
4 changes: 2 additions & 2 deletions test/cypress/e2e/moderationEditHealthcareProfessional.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ before(() => {

describe('Moderation edit professional healthcare form', () => {
context('Landscape mode', () => {
before(function() {
before(() => {
cy.viewport('macbook-16')

cy.intercept('POST', '*', req => {
cy.intercept('POST', '**/', req => {
aliasQuery(req, 'HealthcareProfessionalSearchFilters', fakeHealthcareProfessionalResult)
})

Expand Down
10 changes: 10 additions & 0 deletions test/cypress/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,18 @@ export const auth0Login = () => {
cy.url().should('equal', baseUrl)
}

// https://docs.cypress.io/api/commands/intercept#Interception-lifecycle
export const requestHandler = (req: IncomingHttpRequest) => {
req.on('before:response', res => {
// force all API responses to not be cached
res.headers['cache-control'] = 'no-store'
})
}

// https://docs.cypress.io/app/guides/network-requests#Working-with-GraphQL
export const aliasQuery = (req: IncomingHttpRequest, operation: string, responseBody: unknown) => {
requestHandler(req)

if (!hasOperation(req, operation)) {
req.continue()
return
Expand Down

0 comments on commit 862ac80

Please sign in to comment.