Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
lmcnulty committed Apr 23, 2024
2 parents d95088a + 2b8bf51 commit 2993e79
Show file tree
Hide file tree
Showing 109 changed files with 6,807 additions and 639 deletions.
62 changes: 62 additions & 0 deletions site/gatsby-site/cypress/e2e/integration/apps/checklistsForm.cy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { maybeIt } from '../../../support/utils';
import riskSortingRisks from '../../../fixtures/checklists/riskSortingRisks.json';
import riskSortingChecklist from '../../../fixtures/checklists/riskSortingChecklist.json';
const { gql } = require('@apollo/client');

describe('Checklists App Form', () => {
Expand Down Expand Up @@ -59,6 +61,12 @@ describe('Checklists App Form', () => {
);
};

const interceptFindRisks = (risks) => {
cy.conditionalIntercept('**/graphql', (req) => req.body.query.includes('GMF'), 'findRisks', {
data: { risks },
});
};

it('Should have read-only access for non-logged-in users', () => {
interceptFindChecklist(defaultChecklist);

Expand Down Expand Up @@ -151,6 +159,60 @@ describe('Checklists App Form', () => {
});
});

maybeIt('Should trigger UI update on adding and removing tag', () => {
withLogin(({ user }) => {
interceptFindChecklist({
...defaultChecklist,
owner_id: user.userId,
});
interceptUpsertChecklist({});

cy.visit(url);

cy.get('#tags_methods_input').type('Transformer');
cy.get('#tags_methods').contains('Transformer').click();

cy.waitForStableDOM();

cy.get('details').should('exist');

cy.get('.rbt-close').click();

cy.waitForStableDOM();

cy.get('details').should('not.exist');
});
});

it('Should change sort order of risk items', () => {
cy.viewport(1920, 1080);

withLogin(({ user }) => {
interceptFindChecklist({
...riskSortingChecklist.data.checklist,
owner_id: user.userId,
});

interceptFindRisks(riskSortingRisks.data.risks);

cy.visit(url);

cy.wait(['@findChecklist']);

cy.wait(['@findRisks']);

cy.waitForStableDOM();

cy.contains('Mitigated').click();

cy.get('details:nth(1)').contains('Distributional Bias').should('exist');

cy.contains('Minor').click();

cy.get('details:nth(1)').contains('Dataset Imbalance').should('exist');
});
});

it('Should remove a manually-created risk', () => {
withLogin(({ user }) => {
interceptFindChecklist({
Expand Down
13 changes: 13 additions & 0 deletions site/gatsby-site/cypress/e2e/integration/apps/newsdigest.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ describe('News Digest', () => {
newsArticles
);

cy.conditionalIntercept(
'**/graphql',
(req) => req.body.operationName == 'UpdateCandidate',
'UpdateCandidate',
{
data: {
updateOneCandidate: {
url: 'https://dummy.com',
},
},
}
);

cy.visit(url);

cy.get('[data-cy="results"] [data-cy="candidate-card"] [data-cy="candidate-dropdown"]', {
Expand Down
3 changes: 0 additions & 3 deletions site/gatsby-site/cypress/e2e/integration/blog.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ describe('Blog', () => {

cy.title().should('eq', title);

cy.get('head meta[name="title"]').should('have.attr', 'content', title);
cy.get('head meta[name="description"]').should('have.attr', 'content', description);

cy.get('head meta[name="twitter:site"]').should('have.attr', 'content', '@IncidentsDB');
cy.get('head meta[name="twitter:creator"]').should('have.attr', 'content', '@IncidentsDB');

Expand Down
38 changes: 30 additions & 8 deletions site/gatsby-site/cypress/e2e/integration/cite.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ describe('Cite pages', () => {
expect(variables.query.report_number).to.equal(23);
expect(variables.set).deep.eq({
flag: true,
date_modified: format(now, 'yyyy-MM-dd'),
date_modified: now.toISOString(),
epoch_date_modified: getUnixTime(now),
});
});
Expand All @@ -236,7 +236,7 @@ describe('Cite pages', () => {
);

expectedReport.modifiedBy = '';
expectedReport.date_modified = format(now, 'yyyy-MM-dd');
expectedReport.date_modified = now.toISOString();
expectedReport.epoch_date_modified = getUnixTime(now);

expect(input).to.deep.eq(expectedReport);
Expand Down Expand Up @@ -347,15 +347,15 @@ describe('Cite pages', () => {
cy.get(`.incident-ids-field [data-cy="token"]`).contains('10').should('be.visible');
});

it('should render Next and Previous incident buttons', () => {
it('Should render Next and Previous incident buttons', () => {
cy.visit(url);

cy.contains('Next Incident').should('be.visible').should('have.attr', 'href', '/cite/11');

cy.contains('Previous Incident').should('be.visible').should('have.attr', 'href', '/cite/9');
});

it('', () => {
it('Should render the header next/previous buttons', () => {
cy.visit(url);
cy.get(`[data-cy="header-previous-incident-link"]`)
.should('be.visible')
Expand All @@ -364,14 +364,39 @@ describe('Cite pages', () => {
.should('be.visible')
.should('have.attr', 'href', '/cite/11');
});
it('', () => {

it('Should not show the previous button on incident 1.', () => {
cy.visit('/cite/1');
cy.get(`[data-cy="header-previous-incident-link"]`).should('not.exist');
cy.get(`[data-cy="header-next-incident-link"]`)
.should('be.visible')
.should('have.attr', 'href', '/cite/2');
});

it('Should disable Previous and Next incident buttons on first and last incidents', () => {
cy.visit('/cite/1');

cy.contains('Previous Incident').within(($button) => {
cy.wrap($button).should('be.visible');
cy.wrap($button).should('have.attr', 'disabled');
cy.wrap($button).should('not.have.attr', 'href');
});

cy.contains('Next Incident').should('be.visible').should('have.attr', 'href', '/cite/2');

cy.visit(`/cite/${lastIncidentId}`);

cy.contains('Previous Incident')
.should('be.visible')
.should('have.attr', 'href', `/cite/${lastIncidentId - 1}`);

cy.contains('Next Incident').within(($button) => {
cy.wrap($button).should('be.visible');
cy.wrap($button).should('have.attr', 'disabled');
cy.wrap($button).should('not.have.attr', 'href');
});
});

maybeIt('Should show the edit incident form', () => {
cy.login(Cypress.env('e2eUsername'), Cypress.env('e2ePassword'));

Expand Down Expand Up @@ -640,9 +665,6 @@ describe('Cite pages', () => {

const description = incident.description;

cy.get('head meta[name="title"]').should('have.attr', 'content', title);
cy.get('head meta[name="description"]').should('have.attr', 'content', description);

cy.get('head meta[name="twitter:site"]').should('have.attr', 'content', '@IncidentsDB');
cy.get('head meta[name="twitter:creator"]').should('have.attr', 'content', '@IncidentsDB');

Expand Down
3 changes: 3 additions & 0 deletions site/gatsby-site/cypress/e2e/integration/citeEdit.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ describe('Edit report', () => {
cy.get(`[name=${key}]`).clear().type(updates[key]);
});

cy.get(`[name="quiet"]`).click();

cy.setEditorText(
'## This is text in English\n\nthat is longer that eighty characters, yes eighty characters!',
'[data-cy="text"] .CodeMirror'
Expand Down Expand Up @@ -215,6 +217,7 @@ describe('Edit report', () => {
source_domain: 'test.com',
editor_notes: 'Pro iustitia tantum',
language: 'en',
quiet: true,
};

cy.wait('@updateReport').then((xhr) => {
Expand Down
6 changes: 3 additions & 3 deletions site/gatsby-site/cypress/e2e/integration/discover.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import flaggedReport from '../../fixtures/reports/flagged.json';
import unflaggedReport from '../../fixtures/reports/unflagged.json';
import config from '../../../config';
import path from 'path';
import { format, getUnixTime } from 'date-fns';
import { getUnixTime } from 'date-fns';
import { deleteReportTypenames, transformReportData } from '../../../src/utils/reports';
import { conditionalIt } from '../../support/utils';

Expand Down Expand Up @@ -267,7 +267,7 @@ describe('The Discover app', () => {
expect(variables.query.report_number).to.equal(23);
expect(variables.set).deep.eq({
flag: true,
date_modified: format(now, 'yyyy-MM-dd'),
date_modified: now.toISOString(),
epoch_date_modified: getUnixTime(now),
});
});
Expand All @@ -280,7 +280,7 @@ describe('The Discover app', () => {
);

expectedReport.modifiedBy = '';
expectedReport.date_modified = format(now, 'yyyy-MM-dd');
expectedReport.date_modified = now.toISOString();
expectedReport.epoch_date_modified = getUnixTime(now);

expect(input).to.deep.eq(expectedReport);
Expand Down
19 changes: 19 additions & 0 deletions site/gatsby-site/cypress/e2e/integration/entities.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,23 @@ describe('Entities page', () => {
cy.visit(url);
cy.get('[data-cy="row"]').first().contains('a', 'Facebook').should('be.visible');
});

conditionalIt(
!Cypress.env('isEmptyEnvironment') && Cypress.env('e2eUsername') && Cypress.env('e2ePassword'),
'Should display Edit button only for Admin users',
() => {
cy.visit(url);
cy.get('[data-cy="edit-entity-btn"]').should('not.exist');

cy.login(Cypress.env('e2eUsername'), Cypress.env('e2ePassword'));
cy.visit(url);
cy.get('[data-cy="edit-entity-btn"]')
.first()
.should('have.attr', 'href', '/entities/edit?entity_id=facebook');
cy.get('[data-cy="edit-entity-btn"]').first().click();
cy.waitForStableDOM();
cy.location('pathname').should('eq', '/entities/edit/');
cy.location('search').should('eq', '?entity_id=facebook');
}
);
});
23 changes: 22 additions & 1 deletion site/gatsby-site/cypress/e2e/integration/entity.cy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { maybeIt } from '../../support/utils';
import { conditionalIt, maybeIt } from '../../support/utils';
import emptySubscriptionsData from '../../fixtures/subscriptions/empty-subscriptions.json';
import subscriptionsData from '../../fixtures/subscriptions/subscriptions.json';
const { SUBSCRIPTION_TYPE } = require('../../../src/utils/subscriptions');
Expand Down Expand Up @@ -118,4 +118,25 @@ describe('Individual Entity page', () => {
.contains(`Please log in to subscribe`)
.should('exist');
});

conditionalIt(
!Cypress.env('isEmptyEnvironment') && Cypress.env('e2eUsername') && Cypress.env('e2ePassword'),
'Should display Edit button only for Admin users',
() => {
cy.visit(url);
cy.get('[data-cy="edit-entity-btn"]').should('not.exist');

cy.login(Cypress.env('e2eUsername'), Cypress.env('e2ePassword'));
cy.visit(url);
cy.get('[data-cy="edit-entity-btn"]').should(
'have.attr',
'href',
`/entities/edit?entity_id=${entity.entity_id}`
);
cy.get('[data-cy="edit-entity-btn"]').click();
cy.waitForStableDOM();
cy.location('pathname').should('eq', '/entities/edit/');
cy.location('search').should('eq', `?entity_id=${entity.entity_id}`);
}
);
});
Loading

0 comments on commit 2993e79

Please sign in to comment.