Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add next/previous incident buttons in cite header #2689

28 changes: 28 additions & 0 deletions site/gatsby-site/cypress/e2e/integration/cite.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,16 @@ describe('Cite pages', () => {
cy.contains('Previous Incident').should('be.visible').should('have.attr', 'href', '/cite/9');
});

it('Should render the header next/previous buttons', () => {
cy.visit(url);
cy.get(`[data-cy="header-previous-incident-link"]`)
.should('be.visible')
.should('have.attr', 'href', '/cite/9');
cy.get(`[data-cy="header-next-incident-link"]`)
.should('be.visible')
.should('have.attr', 'href', '/cite/11');
});

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

Expand All @@ -361,6 +371,24 @@ describe('Cite pages', () => {
});
});

it('Should disable Previous and Next incident buttons in header on first and last incidents', () => {
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');

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

cy.get(`[data-cy="header-next-incident-link"]`).should('not.exist');

cy.get(`[data-cy="header-previous-incident-link"]`)
.should('be.visible')
.should('have.attr', 'href', `/cite/${lastIncidentId - 1}`);
});

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

Expand Down
51 changes: 42 additions & 9 deletions site/gatsby-site/src/templates/citeTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ import { SUBSCRIPTION_TYPE } from 'utils/subscriptions';
import VariantList from 'components/variants/VariantList';
import Tools from 'components/cite/Tools';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faArrowLeft, faArrowRight } from '@fortawesome/free-solid-svg-icons';
import {
faCircleArrowLeft,
faCircleArrowRight,
faArrowLeft,
faArrowRight,
} from '@fortawesome/free-solid-svg-icons';
import ClassificationsEditor from 'components/taxa/ClassificationsEditor';
import ClassificationsDisplay from 'components/taxa/ClassificationsDisplay';

Expand Down Expand Up @@ -176,11 +181,40 @@ function CiteTemplate({
</div>
)}
{!readOnly && (
<SocialShareButtons
metaTitle={metaTitle}
path={locationPathName}
page="cite"
></SocialShareButtons>
<>
<SocialShareButtons
metaTitle={metaTitle}
path={locationPathName}
page="cite"
></SocialShareButtons>

<div className="ml-4 text-lg">
<a
data-cy="header-previous-incident-link"
title={t('Previous Incident')}
className={`${
prevIncident ? 'text-black hover:text-primary-blue' : 'text-gray-400'
} h-[50px] leading-[50px]`}
href={
prevIncident ? localizePath({ path: `/cite/${prevIncident}` }) : undefined
}
>
<FontAwesomeIcon icon={faCircleArrowLeft} className="mr-2" />
</a>
<a
data-cy="header-next-incident-link"
title={t('Next Incident')}
className={`${
nextIncident ? 'text-black hover:text-primary-blue' : 'text-gray-400'
} h-[50px] leading-[50px]`}
href={
nextIncident ? localizePath({ path: `/cite/${nextIncident}` }) : undefined
}
>
<FontAwesomeIcon icon={faCircleArrowRight} className="mr-2" />
</a>
</div>
</>
)}
</div>
</div>
Expand Down Expand Up @@ -347,12 +381,11 @@ function CiteTemplate({
className="xl:hidden"
/>
)}

{!readOnly && (
<div className="flex justify-between">
<Button
color={'gray'}
href={prevIncident && localizePath({ path: `/cite/${prevIncident}` })}
href={localizePath({ path: `/cite/${prevIncident}` })}
disabled={!prevIncident}
className="hover:no-underline"
>
Expand All @@ -361,7 +394,7 @@ function CiteTemplate({
</Button>
<Button
color={'gray'}
href={nextIncident && localizePath({ path: `/cite/${nextIncident}` })}
href={localizePath({ path: `/cite/${nextIncident}` })}
disabled={!nextIncident}
className="hover:no-underline"
>
Expand Down
Loading