Skip to content

Commit

Permalink
Merge branch 'master' into FDG-9101-Cypress-Debt-Explainer
Browse files Browse the repository at this point in the history
  • Loading branch information
patienceog committed Jan 9, 2025
2 parents de68b13 + 67ded62 commit b89a0ab
Show file tree
Hide file tree
Showing 28 changed files with 478 additions and 116 deletions.
130 changes: 130 additions & 0 deletions cypress/e2e/about-us/about-us-links.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
describe('About Us Links interaction flow', () => {
beforeEach(() => {
cy.visit('/about-us/');
});

it('Navigates to the About Us page', () => {
cy.findAllByText('About Fiscal Data').should('exist');
});

it('Validates all links on the page function as intended', () => {
const links: object[] = [
{
name: 'Bureau of the Fiscal Service (Fiscal Service)',
url: 'https://fiscal.treasury.gov/about.html',
external: true,
},
{
name: 'getting started section',
url: 'api-documentation/#getting-started',
external: false,
},
{
name: 'International Monetary Fund (IMF)',
url: 'https://www.imf.org/en/home',
external: true,
},
{
name: 'Special Data Dissemination Standard (SDDS)',
url:
'https://www.imf.org/en/About/Factsheets/Sheets/2023/Standards-for-data-dissemination#:~:text=The%20Special%20Data%20Dissemination%20System,access%20to%20international%20capital%20markets.',
external: true,
},
{
name: 'Monthly Statement of the Public Debt (MSPD)',
url: 'datasets/monthly-statement-public-debt/summary-of-treasury-securities-outstanding',
external: false,
},
{
name: 'Monthly Treasury Statement (MTS)',
url: 'datasets/monthly-treasury-statement/summary-of-receipts-outlays-and-the-deficit-surplus-of-the-u-s-government',
external: false,
},
{
name: 'IMF SDDS website',
url:
'https://www.imf.org/en/About/Factsheets/Sheets/2023/Standards-for-data-dissemination#:~:text=The%20Special%20Data%20Dissemination%20System,access%20to%20international%20capital%20markets.',
external: true,
},
{
name: 'API Documentation',
url: 'api-documentation/',
external: false,
},
];

links.forEach(link => {
if (link.external) {
cy.findByRole('link', { name: link.name }).should('have.attr', 'href', link.url);
} else {
cy.findByRole('link', { name: link.name }).click();
cy.url().should('include', link.url);
cy.visit('/about-us/');
}
});
});

it('Validates duplicate links', () => {
const duplicateLinks: object[] = [
{
name: 'visit their Contact Us page',
url: 'https://fiscal.treasury.gov/top/contact.html',
external: true,
},
{
name: 'Economic Impact Payments Page',
url: 'http://www.irs.gov/coronavirus-tax-relief-and-economic-impact-payments',
external: true,
},
{
name: "Where's My Refund?",
url: 'https://www.irs.gov/refunds',
external: true,
},
{
name: 'contact the Bureau of the Fiscal Service',
url: 'https://fiscal.treasury.gov/contact/',
external: true,
},
{
name: 'visit their Contact Us page',
url: 'https://fiscal.treasury.gov/top/contact.html',
external: true,
},
{
name: 'Economic Impact Payments Page',
url: 'http://www.irs.gov/coronavirus-tax-relief-and-economic-impact-payments',
external: true,
},
];

duplicateLinks.forEach(link => {
const dupes = cy.findAllByRole('link', { name: link.name });

dupes.each(dupe => {
cy.wrap(dupe).should('have.attr', 'href', link.url);
});
});
});

it('Validates download links', () => {
const downloadLinks: object[] = [
{
name: 'Open Data Policy',
url: '/data/about-us/901-1 Open Data Policy.pdf',
},
{
name: 'https://fiscaldata.treasury.gov/static-data/reports-statements/mts/imf/cgd.xml',
url: 'https://fiscaldata.treasury.gov/static-data/reports-statements/mts/imf/cgd.xml',
},
{
name: 'https://fiscaldata.treasury.gov/static-data/reports-statements/mts/imf/cgo.xml',
url: 'https://fiscaldata.treasury.gov/static-data/reports-statements/mts/imf/cgo.xml',
},
];

downloadLinks.forEach(link => {
cy.findByRole('link', { name: link.name }).should('have.attr', 'href', link.url);
});
});
});
48 changes: 48 additions & 0 deletions cypress/e2e/about-us/about-us-sub-nav.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
describe('About us interaction flow', () => {
beforeEach(() => {
cy.visit('/about-us/').wait(1500);
});

it('Verifies about us page loads', () => {
cy.findAllByText('About Fiscal Data').should('exist');
});
it('Verifies about us sub nav interaction flow FAQ', () => {
cy.findByTitle('Why do some datasets...')
.should('exist')
.click();
cy.url().should('include', '/#why-datasets-go-further-than-others');
});
it('Verifies keyboard interaction about us sub nav interaction flow FAQ', () => {
cy.findByTitle('I’m new to using APIs...')
.should('exist')
.focus()
.type('{enter}');
cy.url().should('include', '/#new-to-apis');
});
it('Verifies about us sub nav interaction flow About Fiscal Data', () => {
cy.findByTitle('Background')
.should('exist')
.click();
cy.url().should('include', '/#background');
});
it('Verifies keyboard interaction about us sub nav interaction flow About Fiscal Data', () => {
cy.findByTitle('Mission')
.should('exist')
.focus()
.type('{enter}');
cy.url().should('include', '/#mission');
});
it('Verifies about us sub nav interaction flow Contact Us', () => {
cy.findByTitle('Contact Us')
.should('exist')
.click();
cy.url().should('include', '/#contact-us');
});
it('Verifies keyboard interaction about us sub nav interaction flow About Contact Us', () => {
cy.findByTitle('Contact Us')
.should('exist')
.focus()
.type('{enter}');
cy.url().should('include', '/#contact-us');
});
});
20 changes: 20 additions & 0 deletions cypress/e2e/dataset-detail-page/ddp-related-dataset.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
describe('DDP related dataset go to the correct datasets', () => {
beforeEach(() => {
cy.visit('/datasets/monthly-treasury-statement/summary-of-receipts-outlays-and-the-deficit-surplus-of-the-u-s-government').wait(3000);
});
it('Validates the DDP page loads', () => {
cy.findByTitle('Monthly Treasury Statement (MTS)').should('be.visible');
cy.findAllByText('Debt to the Penny')
.eq(1)
.click();
cy.url().should('include', '/debt-to-the-penny');
cy.findAllByText('Daily Treasury Statement (DTS)')
.eq(1)
.click();
cy.url().should('include', '/daily-treasury-statement/operating-cash-balance');
cy.findAllByText('Monthly Treasury Statement (MTS)')
.eq(1)
.click();
cy.url().should('include', '/summary-of-receipts-outlays-and-the-deficit-surplus-of-the-u-s-government');
});
});
59 changes: 59 additions & 0 deletions cypress/e2e/glossary terms/glossary-terms.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
describe('Glossary terms interaction flow', () => {
beforeEach(() => {
cy.visit('/').wait(3000);
cy.findAllByText('Resources').click();
cy.findAllByText('Glossary')
.click()
.wait(3000);
});
it('Verifies Glossary opens and closes correctly', () => {
cy.findByText('Search the glossary').should('exist');
cy.findByLabelText('Close glossary').click();
cy.findByText('Search the glossary').should('not.exist');
});

it('Search bar search and Back to list interaction', () => {
cy.findAllByLabelText('Search the glossary').should('be.visible');
cy.findAllByLabelText('Search the glossary')
.eq(1)
.type('Revenue');
cy.findAllByText('Back to list')
.should('exist')
.click();
cy.findAllByLabelText('Search the glossary')
.eq(1)
.type('Debt Ceiling')
.click();
cy.findAllByText('Back to list')
.should('exist')
.click();
});
it('Search bar click into a selected search', () => {
cy.findAllByLabelText('Search the glossary')
.eq(1)
.type('Debt Ceiling');
cy.findAllByText('Debt Ceiling')
.should('exist')
.click();
cy.findAllByText(
'This is the maximum amount of money the federal government is allowed to borrow without receiving additional authority from Congress.'
).should('exist');
});
it('Search bar interaction with Floating Rate Notes and external link', () => {
cy.findAllByLabelText('Search the glossary')
.eq(1) // Target the correct search bar
.should('be.visible')
.type('Floating Rate Notes');
cy.findAllByText('Floating Rate Notes')
.should('exist')
.click();
cy.findAllByText('TreasuryDirect')
.should('exist')
.invoke('attr', 'href')
.should('include', '/marketable-securities/floating-rate-notes/');

cy.findAllByText('TreasuryDirect')
.invoke('removeAttr', 'target')
.click();
});
});
11 changes: 9 additions & 2 deletions src/components/anchor-text/anchor-text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@ import CustomLink from '../links/custom-link/custom-link';
type IAnchorText = {
link: string;
text: string;
onAnchorClick?: (anchorId: string) => void;
};

const AnchorText = ({ link, text }: IAnchorText): JSX.Element => {
const AnchorText = ({ link, text, onAnchorClick }: IAnchorText): JSX.Element => {
const handleClick = () => {
if (onAnchorClick) {
onAnchorClick(link);
}
};

return (
<sup>
<CustomLink url="#footnote" id={link} data-testid="anchor-text">
<CustomLink url="#footnote" id={link} data-testid="anchor-text" onClick={handleClick}>
{text}
</CustomLink>
</sup>
Expand Down
32 changes: 22 additions & 10 deletions src/components/anchor-text/anchor.spec.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
import React from 'react';
import { render } from '@testing-library/react';
import { render, fireEvent } from '@testing-library/react';
import AnchorText from './anchor-text';

const mockFootnote = {
text: 'Test Footnote Text',
link: 'testFootnote',
body:
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque vulputate odio a enim hendrerit interdum. Duis volutpat, nibh porttitor pellentesque mattis, mi justo',
};
jest.mock('../links/custom-link/custom-link', () => {
return ({ onClick, children, 'data-testid': dataTestId }) => {
return (
<button onClick={onClick} data-testid={dataTestId}>
{children}
</button>
);
};
});

describe('Anchor Text', () => {
it('it renders the Anchor Text component', () => {
const { getByTestId } = render(<AnchorText link={mockFootnote.link} text={mockFootnote.text} />);
describe('AnchorText', () => {
it('renders the Anchor Text component', () => {
const { getByTestId } = render(<AnchorText link="testFootnote" text="Test Footnote Text" />);
expect(getByTestId('anchor-text')).toBeInTheDocument();
});

it('calls onAnchorClick with the link when clicked', () => {
const mockClickHandler = jest.fn();
const { getByTestId } = render(<AnchorText link="testFootnote" text="Test Footnote Text" onAnchorClick={mockClickHandler} />);
fireEvent.click(getByTestId('anchor-text'));

expect(mockClickHandler).toHaveBeenCalledWith('testFootnote');
expect(mockClickHandler).toHaveBeenCalledTimes(1);
});
});
4 changes: 3 additions & 1 deletion src/components/api-documentation/aggregation/aggregation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ const Aggregation = () => {
and summing of their numeric values, etc. You should use this when searching for the sum total of a specific field.
</p>
<p>For example, the API call for the sum total of the opening monthly balance within the Daily Treasury Statement dataset would read as:</p>
<code className={`${code} ${marginBottom}`}>{baseApiUrl}/v1/accounting/dts/dts_table_2?fields=record_date,transaction_today_amt</code>
<code className={`${code} ${marginBottom}`}>
{baseApiUrl}/v1/accounting/dts/deposits_withdrawals_operating_cash?fields=record_date,transaction_today_amt
</code>
<p>
Running this API call will yield a sum of all the totals in the selected field. In this case, the call yields the total sum of all opening
monthly balances over the course of all dates available in the dataset.
Expand Down
22 changes: 14 additions & 8 deletions src/components/api-documentation/examples/examples.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const Examples = () => {
<code className="large">
{baseApiUrl}
/v1/accounting/od/rates_of_exchange?fields=country_currency_desc,exchange_rate,
record_date&filter=country_currency_desc:in:(Canada-Dollar,Mexico-Peso), record_date:gte:2020-01-01
record_date&filter=country_currency_desc:in:(Canada-Dollar,Mexico-Peso),record_date:gte:2020-01-01
</code>
</SectionContent>
<SectionContent title="Sorting" id="examples-sorting" headingLevel={3}>
Expand All @@ -49,8 +49,8 @@ const Examples = () => {
<li>return the most recent data first , i.e., return data sorted by year (descending order) and then month (descending order)</li>
</ul>
<code className="large">
{baseApiUrl}/v2/accounting/od/debt_to_penny?fields=record_calendar_year,
record_calendar_month&sort=-record_calendar_year,-record_calendar_month
{baseApiUrl}
/v2/accounting/od/debt_to_penny?fields=record_calendar_year,record_calendar_month&sort=-record_calendar_year,-record_calendar_month
</code>
</SectionContent>
<SectionContent title="Format" id="examples-format" headingLevel={3}>
Expand All @@ -69,13 +69,19 @@ const Examples = () => {
<code className="large">{baseApiUrl}/v1/debt/top/top_state?page[number]=10&page[size]=50</code>
</SectionContent>
<SectionContent title="Aggregation" id="examples-aggregation" headingLevel={3}>
<span>More documentation is expected to be added about aggregation.</span>
</SectionContent>
<SectionContent title="Pivoting" id="examples-pivoting" headingLevel={3}>
<span>More documentation is expected to be added about pivoting.</span>
<span>For the Daily Treasury Statement dataset, </span>
<ul>
<li>Return the sum of all transactions today amounts for each transaction type on each record date</li>
</ul>
<code className="large">
{baseApiUrl}/v1/accounting/dts/deposits_withdrawals_operating_cash?fields=record_date,transaction_type,transaction_today_amt
</code>
</SectionContent>
<SectionContent title="Multi-dimension Datasets" id="examples-multi-dimension-datasets" headingLevel={3}>
<span>More documentation is expected to be added about multi-dimension datasets.</span>
<span>
Many Fiscal Data datasets contain multiple tables or APIs, which relate to each other. Please see the Data Dictionary, Data Tables,
Metadata, and Notes & Known Limitations tabs within the dataset properties section of each dataset page for more information.
</span>
</SectionContent>
</>
);
Expand Down
6 changes: 0 additions & 6 deletions src/components/api-documentation/examples/examples.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ describe('API Documentation Examples', () => {
expect(heading.children[0]).toBe(title);
});

it('creates the Pivoting section with the desired id, heading tag and title', () => {
const title = 'Pivoting';
const heading = instance.findByProps({ id: 'examples-pivoting' }).findByType('h3');
expect(heading.children[0]).toBe(title);
});

it('creates the Multi-dimension Datasets section with the desired id, heading tag and title', () => {
const title = 'Multi-dimension Datasets';
const heading = instance.findByProps({ id: 'examples-multi-dimension-datasets' }).findByType('h3');
Expand Down
Loading

0 comments on commit b89a0ab

Please sign in to comment.