-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
131 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
const incident = { | ||
incident: { | ||
ASNs: [], | ||
CCs: [], | ||
domains: [], | ||
end_time: null, | ||
event_type: 'incident', | ||
id: 1234, | ||
links: [], | ||
mine: 0, | ||
published: true, | ||
reported_by: 'ooni', | ||
short_description: 'China recently started blocking access to our website (ooni.org) and censorship measurement app (OONI Probe).', | ||
start_time: '2023-07-07T00:00:00Z', | ||
tags: [], | ||
test_names: [], | ||
text: 'China recently started blocking access to our website (ooni.org) and censorship measurement app (OONI Probe).', | ||
title: 'China is blocking OONI', | ||
update_time: '2023-09-14T10:59:31Z' | ||
} | ||
} | ||
|
||
describe('Incidents Dashboard', () => { | ||
it('admin can see the dashboard', () => { | ||
cy.intercept('/api/_/account_metadata', {logged_in: true, role: 'admin'}).as('accountMetadata') | ||
const dashboardUrl = '/incidents/dashboard' | ||
cy.visit(dashboardUrl) | ||
cy.wait('@accountMetadata') | ||
cy.findByText('Incidents Dashboard').should('exist') | ||
}) | ||
|
||
it('redirects user if not logged in', () => { | ||
cy.intercept('/api/_/account_metadata', {statusCode: 401}).as('accountMetadata') | ||
const dashboardUrl = '/incidents/dashboard' | ||
cy.visit(dashboardUrl) | ||
cy.wait('@accountMetadata') | ||
cy.findByText('Incidents Dashboard').should('not.exist') | ||
cy.url({timeout: 6000}).should('eq', 'http://localhost:3100/incidents') | ||
}) | ||
|
||
it('redirects user if not admin', () => { | ||
cy.intercept('/api/_/account_metadata', {logged_in: true, role: 'user'}).as('accountMetadata') | ||
const dashboardUrl = '/incidents/dashboard' | ||
cy.visit(dashboardUrl) | ||
cy.wait('@accountMetadata') | ||
cy.findByText('Incidents Dashboard').should('not.exist') | ||
cy.url({timeout: 6000}).should('eq', 'http://localhost:3100/incidents') | ||
}) | ||
}) | ||
|
||
describe('Incidents Edit', () => { | ||
it('admin can see edit incident page', () => { | ||
cy.intercept('/api/_/account_metadata', {logged_in: true, role: 'admin'}).as('accountMetadata') | ||
cy.intercept('/api/v1/incidents/show/1234', incident).as('showIncident') | ||
|
||
const dashboardUrl = '/incidents/edit/1234' | ||
cy.visit(dashboardUrl) | ||
cy.wait('@accountMetadata') | ||
cy.wait('@showIncident') | ||
cy.findByText('Edit Incident Report').should('exist') | ||
}) | ||
|
||
it('report creator can see edit incident page', () => { | ||
cy.intercept('/api/_/account_metadata', {logged_in: true, role: 'user'}).as('accountMetadata') | ||
cy.intercept('/api/v1/incidents/show/1234', incident).as('showIncident') | ||
|
||
const dashboardUrl = '/incidents/edit/1234' | ||
cy.visit(dashboardUrl) | ||
cy.wait('@accountMetadata') | ||
cy.wait('@showIncident') | ||
cy.findByText('Edit Incident Report').should('exist') | ||
}) | ||
|
||
it('redirects user if not logged in', () => { | ||
cy.intercept('/api/_/account_metadata', {statusCode: 401}).as('accountMetadata') | ||
const dashboardUrl = '/incidents/edit/1234' | ||
cy.visit(dashboardUrl) | ||
cy.wait('@accountMetadata') | ||
cy.findByText('Edit Incident Report').should('not.exist') | ||
cy.url({timeout: 6000}).should('eq', 'http://localhost:3100/incidents') | ||
}) | ||
|
||
it('redirects user if not admin', () => { | ||
cy.intercept('/api/_/account_metadata', {logged_in: true, role: 'user'}).as('accountMetadata') | ||
cy.intercept('/api/v1/incidents/show/1234', incident).as('showIncident') | ||
|
||
const dashboardUrl = '/incidents/edit/1234' | ||
cy.visit(dashboardUrl) | ||
cy.wait('@accountMetadata') | ||
cy.wait('@showIncident') | ||
cy.findByText('Edit Incident Report').should('not.exist') | ||
cy.url({timeout: 6000}).should('eq', 'http://localhost:3100/incidents') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -320,21 +320,25 @@ describe('Measurement Page Tests', () => { | |
}) | ||
|
||
it('can login', () => { | ||
cy.interceptRequest(failedAccountMetadata) | ||
|
||
cy.intercept('/api/_/account_metadata', {statusCode: 401}) | ||
cy.intercept('/api/v1/user_register', {statusCode: 200}) | ||
|
||
const measurementUrl = '/m/20230307142542.625294_US_webconnectivity_9215f30cf2412f49' | ||
cy.visit(measurementUrl) | ||
cy.findByText('VERIFY').click() | ||
|
||
cy.findByRole('textbox').click().type('[email protected]') | ||
cy.findByRole('textbox').click() | ||
cy.findByRole('textbox').type('[email protected]') | ||
cy.findByText('Login').click() | ||
cy.findByText('Login link sent') | ||
}) | ||
|
||
|
||
it('can submit feedback', () => { | ||
const measurementUrl = '/m/20230307142542.625294_US_webconnectivity_9215f30cf2412f49' | ||
cy.intercept('/api/_/account_metadata', {logged_in: true, role: 'user'}) | ||
cy.intercept('/api/_/measurement_feedback', {statusCode: 200}) | ||
|
||
const measurementUrl = '/m/20230307142542.625294_US_webconnectivity_9215f30cf2412f49' | ||
|
||
cy.visit(measurementUrl) | ||
cy.findByText('VERIFY').click() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
|
||
import { setupWorker, rest} from 'msw' | ||
import { handlers } from '/cypress/mocks/handlers' | ||
// import { setupWorker} from 'msw' | ||
// import { handlers } from '/cypress/mocks/handlers' | ||
|
||
let worker | ||
// let worker | ||
|
||
before(() => { | ||
worker = setupWorker(...handlers) | ||
cy.wrap(worker.start({ onUnhandledRequest: 'bypass' }), { log: false }) | ||
}) | ||
Cypress.on('test:before:run', () => { | ||
if (!worker) return | ||
worker.resetHandlers() | ||
}) | ||
// before(() => { | ||
// worker = setupWorker(...handlers) | ||
// cy.wrap(worker.start({ onUnhandledRequest: 'bypass' })) | ||
// }) | ||
// Cypress.on('test:before:run', () => { | ||
// if (!worker) return | ||
// worker.resetHandlers() | ||
// }) | ||
|
||
Cypress.Commands.add('interceptRequest', (...params) => { | ||
worker.use(...params) | ||
}) | ||
// Cypress.Commands.add('interceptRequest', (...params) => { | ||
// worker.use(...params) | ||
// }) |