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 6ed60d7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
10 changes: 6 additions & 4 deletions test/cypress/e2e/moderationDashboard.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ import enUS from '../../../i18n/locales/en.json'
import fakeSubmissionResponse from '../../fake_data/moderation_dashboard/fakeSubmissionResponse.json'
import { aliasQuery } from '../utils'

before(() => {
cy.login()
})

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

cy.login()

cy.visit('/moderation')
cy.wait('@query Submissions')
})
Expand Down Expand Up @@ -115,6 +113,8 @@ describe('Moderation Edit Submission Form', () => {
aliasQuery(req, 'query Submissions', fakeSubmissionResponse)
})

cy.login()

cy.visit('/moderation')
cy.wait('@query Submissions')
cy.get('[data-testid="mod-submission-list-item-1"]').click()
Expand Down Expand Up @@ -278,6 +278,8 @@ describe('Moderation Edit Submission Modal', () => {
aliasQuery(req, 'query Submissions', fakeSubmissionResponse)
})

cy.login()

cy.visit('/moderation')
cy.wait('@query Submissions')
cy.get('[data-testid="mod-submission-list-item-1"]').click()
Expand Down
11 changes: 11 additions & 0 deletions test/cypress/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,20 @@ 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.alias = 'Continue'
req.continue()
return
}
Expand Down

0 comments on commit 6ed60d7

Please sign in to comment.