Skip to content

Commit

Permalink
Merge pull request #2395 from responsible-ai-collaborative/staging
Browse files Browse the repository at this point in the history
Deploy to Production
  • Loading branch information
kepae authored Nov 14, 2023
2 parents f4875c0 + 7b03680 commit b67d77f
Show file tree
Hide file tree
Showing 35 changed files with 1,213 additions and 1,016 deletions.
2 changes: 2 additions & 0 deletions site/gatsby-site/cypress/e2e/integration/cite.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ describe('Cite pages', () => {
it('Should pre-fill submit report response form', () => {
cy.visit(url);

cy.waitForStableDOM();

cy.contains('New Response').scrollIntoView().click();

cy.waitForStableDOM();
Expand Down
32 changes: 20 additions & 12 deletions site/gatsby-site/cypress/e2e/integration/discover.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ describe('The Discover app', () => {

cy.waitForStableDOM();

cy.location('search', { timeout: 8000 }).should('contain', 'is_incident_report=true');

cy.get('div[data-cy="hits-container"]').should('not.exist');

cy.contains('Your search returned no results.').should('exist').and('be.visible');
Expand All @@ -33,16 +35,14 @@ describe('The Discover app', () => {
() => {
cy.visit(url);

cy.location('search', { timeout: 8000 }).should('contain', 'is_incident_report=true');

cy.waitForStableDOM();

cy.location('search', { timeout: 8000 }).should('contain', 'is_incident_report=true');

cy.contains('[data-cy="display-options"]', 'Incident Reports')
.should('exist')
.and('be.visible');

cy.waitForStableDOM();

cy.get('div[data-cy="hits-container"]').children().should('have.length.at.least', 28);
}
);
Expand Down Expand Up @@ -74,6 +74,8 @@ describe('The Discover app', () => {
() => {
cy.visit(url);

cy.waitForStableDOM();

cy.get('[data-cy=expand-filters]').click();

cy.waitForStableDOM();
Expand All @@ -88,6 +90,8 @@ describe('The Discover app', () => {

cy.get('[data-cy="incident_id-item"]:contains("34")', { timeout: 8000 }).first().click();

cy.waitForStableDOM();

cy.url().should('include', 'incident_id=34');

cy.waitForStableDOM();
Expand Down Expand Up @@ -137,6 +141,8 @@ describe('The Discover app', () => {

cy.get('[data-cy="tags-item"]:contains("response")', { timeout: 8000 }).first().click();

cy.waitForStableDOM();

cy.url().should('include', 'tags=response');

cy.waitForStableDOM();
Expand Down Expand Up @@ -288,6 +294,8 @@ describe('The Discover app', () => {

cy.contains('li', /^Issue Reports$/).click();

cy.waitForStableDOM();

cy.location('search', { timeout: 8000 }).should('contain', 'is_incident_report=false');

cy.waitForStableDOM();
Expand Down Expand Up @@ -411,10 +419,9 @@ describe('The Discover app', () => {
it('Should not add a trailing slash when loading the discover app', () => {
cy.visit(url);

cy.location('search', { timeout: 8000 }).should(
'equal',
'?display=details&is_incident_report=true&page=1&sortBy=instant_search-en-featured'
);
cy.waitForStableDOM();

cy.location('search', { timeout: 8000 }).should('equal', '?is_incident_report=true');
});

conditionalIt(!Cypress.env('isEmptyEnvironment'), 'Should export results to a CSV file', () => {
Expand Down Expand Up @@ -466,10 +473,9 @@ describe('The Discover app', () => {
it('Should set the sort with the value from the URL', () => {
cy.visit(url);

cy.location('search', { timeout: 8000 }).should(
'equal',
'?display=details&is_incident_report=true&page=1&sortBy=instant_search-en-featured'
);
cy.waitForStableDOM();

cy.location('search', { timeout: 8000 }).should('equal', '?is_incident_report=true');

cy.get('[data-cy="discover-sort"]').should('have.text', 'Relevance');

Expand Down Expand Up @@ -531,6 +537,8 @@ describe('The Discover app', () => {
.first()
.click();

cy.waitForStableDOM();

cy.url().should('include', 'source_domain=theguardian.com');

cy.waitForStableDOM();
Expand Down
24 changes: 15 additions & 9 deletions site/gatsby-site/cypress/e2e/integration/pages.cy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { switchLocalizedPath } from '../../../i18n';
import config from '../../../config';
import isString from 'lodash/isString';

describe('Pages', () => {
const baseUrl = config.gatsby.siteUrl;
Expand Down Expand Up @@ -67,15 +68,20 @@ describe('Pages', () => {
// check for runtime errors

cy.get('@consoleError').then((consoleError) => {
const noHydrationErrors = consoleError
.getCalls()
.every((call) =>
call.args.every(
(arg) => !arg.includes('did not match') || !arg.includes('Minified React error')
)
);

expect(noHydrationErrors, 'No hydration errors').to.be.true;
const errors = [];

consoleError.getCalls().forEach((call) =>
call.args.forEach((arg) => {
if (
isString(arg) &&
(arg.includes('did not match') || arg.includes('Minified React error'))
) {
errors.push(arg);
}
})
);

expect(errors.length, `No hydration errors:\n ${errors.join(', ')}`).to.eq(0);

// This should be enabled once the app is free of warnings

Expand Down
47 changes: 47 additions & 0 deletions site/gatsby-site/cypress/e2e/unit/discover/routing.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import parseURL from '../../../../../gatsby-site/src/components/discover/parseURL';
import createURL from '../../../../../gatsby-site/src/components/discover/createURL';
import { queryConfig } from '../../../../../gatsby-site/src/components/discover/queryParams';

chai.config.truncateThreshold = 0;

describe('Discover routing', () => {
it('Should parse back and forth a discover URL', () => {
const indexName = 'instant_search-en';

const location = {
search:
'?authors=Christopher%20Knaus%7C%7CSam%20Levin&classifications=CSETv0%3AIntent%3AAccident&epoch_date_published_max=1670371200&is_incident_report=true&page=1&s=tesla&sortBy=published-date-asc&source_domain=theguardian.com',
};

const result = parseURL({ location, indexName, queryConfig });

const state = result[indexName];

expect(state.query).to.eq('tesla');
expect(state.page).to.eq(1);
expect(state.sortBy).to.eq('published-date-asc');
expect(state.refinementList).to.deep.eq({
source_domain: ['theguardian.com'],
authors: ['Christopher Knaus', 'Sam Levin'],
classifications: ['CSETv0:Intent:Accident'],
is_incident_report: ['true'],
});
expect(state.range).to.deep.eq({
epoch_date_published: `:1670371200`,
});

expect(state.configure).to.deep.eq({
distinct: false,
hitsPerPage: 28,
});

const resultURL = createURL({
routeState: { [indexName]: state },
indexName,
locale: 'en',
queryConfig,
});

expect('?' + resultURL).to.eq(location.search);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,14 @@ const stubEverything = () => {
.returns({ toArray: () => subscriptionsToIncidentUpdates });
}

const incidentIds = pendingNotificationsToPromotedIncidents.map(
(pendingNotification) => pendingNotification.incident_id
);

stub
.withArgs({
type: SUBSCRIPTION_TYPE.submissionPromoted,
incident_id: { $in: incidentIds },
})
.as(`subscriptions.find("${SUBSCRIPTION_TYPE.submissionPromoted}")`)
.returns({ toArray: () => subscriptionsToPromotedIncidents });
Expand Down Expand Up @@ -450,6 +455,7 @@ describe('Functions', () => {

expect(subscriptionsCollection.find.getCall(5).args[0]).to.deep.equal({
type: SUBSCRIPTION_TYPE.submissionPromoted,
incident_id: { $in: [217] },
});

for (const subscription of subscriptionsToPromotedIncidents) {
Expand All @@ -465,8 +471,6 @@ describe('Functions', () => {
incident_id: pendingNotification.incident_id,
});

console.log('subscriptionsToPromotedIncidents', global.context.functions);

const userIds = subscriptionsToPromotedIncidents.map((subscription) => subscription.userId);

const incident = incidents.find((i) => i.incident_id == pendingNotification.incident_id);
Expand Down Expand Up @@ -785,7 +789,7 @@ describe('Functions', () => {
expect(notificationsCollection.updateOne.getCall(i).args[1].$set.processed).to.be.equal(
true
);
expect(notificationsCollection.updateOne.getCall(i).args[1].$set).not.to.have.ownProperty(
expect(notificationsCollection.updateOne.getCall(i).args[1].$set).to.have.ownProperty(
'sentDate'
);
}
Expand All @@ -804,9 +808,9 @@ describe('Functions', () => {
expect(notificationsCollection.updateOne.getCall(i + 2).args[1].$set.processed).to.be.equal(
true
);
expect(
notificationsCollection.updateOne.getCall(i + 2).args[1].$set
).not.to.have.ownProperty('sentDate');
expect(notificationsCollection.updateOne.getCall(i + 2).args[1].$set).to.have.ownProperty(
'sentDate'
);
}

for (let i = 0; i < pendingNotificationsToIncidentUpdates.length; i++) {
Expand All @@ -823,9 +827,9 @@ describe('Functions', () => {
expect(notificationsCollection.updateOne.getCall(i + 4).args[1].$set.processed).to.be.equal(
true
);
expect(
notificationsCollection.updateOne.getCall(i + 4).args[1].$set
).not.to.have.ownProperty('sentDate');
expect(notificationsCollection.updateOne.getCall(i + 4).args[1].$set).to.have.ownProperty(
'sentDate'
);
}

expect(
Expand Down
Loading

0 comments on commit b67d77f

Please sign in to comment.