Skip to content

Commit

Permalink
Merge branch 'staging' into fix/translations-incidents-taxonomies
Browse files Browse the repository at this point in the history
  • Loading branch information
clari182 committed Apr 22, 2024
2 parents 49b3c60 + e834df1 commit 2418a83
Show file tree
Hide file tree
Showing 16 changed files with 213 additions and 30 deletions.
25 changes: 25 additions & 0 deletions site/gatsby-site/cypress/e2e/integration/apps/checklistsForm.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,31 @@ 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);

Expand Down
34 changes: 32 additions & 2 deletions site/gatsby-site/cypress/e2e/integration/cite.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ describe('Cite pages', () => {

let user;

let lastIncidentId;

before('before', function () {
// Skip all tests if the environment is empty since /cite/{incident_id} is not available
Cypress.env('isEmptyEnvironment') && this.skip();
Expand All @@ -32,10 +34,14 @@ describe('Cite pages', () => {
first_name
last_name
}
incidents(limit: 1, sortBy: INCIDENT_ID_DESC) {
incident_id
}
}
`,
}).then(({ data: { user: userData } }) => {
}).then(({ data: { user: userData, incidents: incidentsData } }) => {
user = userData;
lastIncidentId = incidentsData[0].incident_id;
});
});

Expand Down Expand Up @@ -323,14 +329,38 @@ 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('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
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,14 @@ describe('Social Share buttons on pages', { retries: { runMode: 4 } }, () => {

cy.get('[data-cy=btn-share-facebook]').first().click();
cy.get('@popup_facebook', { timeout: 8000 }).should('be.called');
cy.url().should('contain', `https://www.facebook.com/sharer/sharer.php?u=${canonicalUrl}`);
// Take into consideration that the Facebook share button can open a new window with two different URLs depending on the environment
cy.url().should(
'satisfy',
(url) =>
(url.includes('https://www.facebook.com/login.php') &&
url.includes('next=https%3A%2F%2Fwww.facebook.com%2Fsharer%2Fsharer.php')) ||
url.includes(`https://www.facebook.com/sharer/sharer.php?u=${canonicalUrl}`)
);
});
});
});
63 changes: 63 additions & 0 deletions site/gatsby-site/cypress/e2e/unit/functions/getUserAdminData.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const getUserAdminData = require('../../../../../realm/functions/getUserAdminData');

describe('getUserAdminData', () => {
it('Should not return data if different user id and no permissions', () => {
global.context = {
// @ts-ignore
functions: {
execute: cy.stub().resolves({}),
},
user: {
id: '2',
custom_data: {
roles: ['subscriber'],
},
},
};

cy.wrap(getUserAdminData({ userId: '1' })).then((response) => {
expect(global.context.functions.execute).to.not.called;
expect(response.email).to.be.null;
});
});

it('Should return data if user id is the same as current user', () => {
global.context = {
// @ts-ignore
functions: {
execute: cy.stub().resolves({ data: { email: '[email protected]' } }),
},
user: {
id: '1',
custom_data: {
roles: ['subscriber'],
},
},
};

cy.wrap(getUserAdminData({ userId: '1' })).then((response) => {
expect(global.context.functions.execute).to.have.been.calledOnce;
expect(response.email).to.equal('[email protected]');
});
});

it('Should return data if user is admin', () => {
global.context = {
// @ts-ignore
functions: {
execute: cy.stub().resolves({ data: { email: '[email protected]' } }),
},
user: {
id: '1',
custom_data: {
roles: ['admin'],
},
},
};

cy.wrap(getUserAdminData({ userId: '3211231' })).then((response) => {
expect(global.context.functions.execute).to.have.been.calledOnce;
expect(response.email).to.equal('[email protected]');
});
});
});
4 changes: 3 additions & 1 deletion site/gatsby-site/i18n/locales/es/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -548,5 +548,7 @@
"Inadequate Sequential Memory": "Memoria Secuencial Inadecuada",
"Spectrogram": "Espectrograma",
"Overfitting": "Sobreajuste",
"No classifications with this field": "No hay clasificaciones con este campo"
"No classifications with this field": "No hay clasificaciones con este campo",
"Language": "Idioma",
"Read the Source": "Leer la Fuente"
}
3 changes: 2 additions & 1 deletion site/gatsby-site/i18n/locales/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -536,5 +536,6 @@
"Inadequate Sequential Memory": "Mémoire Séquentielle Inadéquate",
"Spectrogram": "Spectrogramme",
"Overfitting": "Surajustement",
"No classifications with this field": "Aucune classification pour ce champ"
"No classifications with this field": "Aucune classification pour ce champ",
"Read the Source": "Lire la source"
}
10 changes: 8 additions & 2 deletions site/gatsby-site/i18n/locales/ja/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -522,5 +522,11 @@
"Inadequate Sequential Memory": "不適切な連続メモリ",
"Spectrogram": "スペクトログラム",
"Overfitting": "オーバーフィッティング",
"No classifications with this field": "このフィールドに分類はありません"
}
"No classifications with this field": "このフィールドに分類はありません",
"results found": "件の結果が見つかりました",
"More filters": "さらにフィルタ",
"Fewer filters": "フィルタを減らす",
"Tags": "タグ",
"Language": "言語",
"Read the Source": "情報源を読む"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const languages = require('../i18n/config.json');

/**
*
* @param {{context: {client: import('mongodb').MongoClient}}} context
*/

exports.up = async ({ context: { client } }) => {
const db = client.db('translations');

for (const language of languages) {
const name = `reports_${language.code}`;

console.log(`Deleting dummy translations from ${name}`);

const translations = db.collection(name);

const result = await translations.deleteMany({
text: /^translated-/,
});

console.log(`Deleted ${result.deletedCount} dummy translations for ${language.code}`);
}
};
4 changes: 2 additions & 2 deletions site/gatsby-site/src/components/discover/Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export default function Actions({ item, toggleFilterByIncidentId = null }) {
titleId="report-source"
icon={faNewspaper}
className="fa-newspaper"
title="Read the Source"
title={t('Read the Source')}
/>
</WebArchiveLink>

Expand Down Expand Up @@ -203,7 +203,7 @@ export default function Actions({ item, toggleFilterByIncidentId = null }) {
titleId="report-hashtag"
icon={faHashtag}
className="fa-hashtag"
title="Incident ID"
title={t('Incident ID')}
/>
{item.incident_id}
</CustomButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ function Attribute({ name, refinement, searchResults }) {
tabIndex={0}
onClick={() => setCollapsed((c) => !c)}
>
{name} ({refinement.items.length}){' '}
{name} (~
{refinement.items.reduce((a, c) => Math.max(a, c.count), refinement.items[0].count)}){' '}
<div className="inline-block">{collapsed ? <>+</> : <>-</>} </div>
</div>

Expand Down
12 changes: 9 additions & 3 deletions site/gatsby-site/src/components/landing/Sponsors.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,18 @@ export default function Sponsors({ sponsors = [] }) {
organization chartered to advance the AI Incident Database. The governance of the
Collaborative is architected around the participation in its impact programming.
For more details, we invite you to read the{' '}
<a href="https://docsend.com/view/a45p7mgh44nu8x7j">founding report</a> and learn
more on our{' '}
<a href="https://asset.cloudinary.com/pai/cf01cce1af65f5fbb3d71fa092d001db">
founding report
</a>{' '}
and learn more on our{' '}
<Link to="/about?lang=en#boardofdirectors">board and contributors</Link>.
</Trans>
</p>
<a href="https://docsend.com/view/a45p7mgh44nu8x7j" target="_blank" rel="noreferrer">
<a
href="https://asset.cloudinary.com/pai/cf01cce1af65f5fbb3d71fa092d001db"
target="_blank"
rel="noreferrer"
>
<StyledImageCover src="/images/reportcover.png" className="border-1" />
</a>
<p className="italic">
Expand Down
23 changes: 16 additions & 7 deletions site/gatsby-site/src/components/layout/Footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ import config from '../../../config';
import { LocalizedLink } from 'plugins/gatsby-theme-i18n';
import { Trans, useTranslation } from 'react-i18next';

function CommitSHA() {
return (
<div className="text-muted-gray text-xs" data-cy="commit-sha">
{process.env.GATSBY_COMMIT_SHA.toString().substring(0, 7)}
</div>
);
}

export default function Footer() {
const data = useStaticQuery(graphql`
query FooterQuery {
Expand Down Expand Up @@ -204,13 +212,13 @@ export default function Footer() {
</div>
)}

{i == footerContent.length - 1 && process.env.GATSBY_COMMIT_SHA && (
<li>
<div className="text-muted-gray text-xs" data-cy="commit-sha">
{process.env.GATSBY_COMMIT_SHA.toString().substring(0, 7)}
</div>
</li>
)}
{i == footerContent.length - 1 &&
allPrismicFooter.edges.length > 0 &&
process.env.GATSBY_COMMIT_SHA && (
<li>
<CommitSHA />
</li>
)}
</ul>
</div>
);
Expand Down Expand Up @@ -298,6 +306,7 @@ export default function Footer() {
/>
</a>
</div>
<CommitSHA />
</div>
)}
</footer>
Expand Down
2 changes: 1 addition & 1 deletion site/gatsby-site/src/components/taxa/TaxonomyForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ function FormField({
if (field?.complete_from?.current) {
for (const key of field.complete_from.current) {
if (formikValues[key]) {
combinedAttributedValues.push(formikValues[key]);
combinedAttributedValues = combinedAttributedValues.concat(formikValues[key]);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions site/gatsby-site/src/templates/citeTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ function CiteTemplate({
<div className="flex justify-between">
<Button
color={'gray'}
href={localizePath({ path: `/cite/${prevIncident}` })}
href={prevIncident && localizePath({ path: `/cite/${prevIncident}` })}
disabled={!prevIncident}
className="hover:no-underline"
>
Expand All @@ -361,7 +361,7 @@ function CiteTemplate({
</Button>
<Button
color={'gray'}
href={localizePath({ path: `/cite/${nextIncident}` })}
href={nextIncident && localizePath({ path: `/cite/${nextIncident}` })}
disabled={!nextIncident}
className="hover:no-underline"
>
Expand Down
2 changes: 1 addition & 1 deletion site/gatsby-site/src/templates/prismicDoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const Head = (props) => {
location: { pathname },
} = props;

const doc = props?.data?.doc;
const doc = props?.data?.doc || props?.data?.enDoc;

const metaTitle = doc?.data?.metatitle;

Expand Down
Loading

0 comments on commit 2418a83

Please sign in to comment.