Skip to content

Commit

Permalink
Merge pull request #496 from georgetown-cset/482-mock-data-for-tests
Browse files Browse the repository at this point in the history
Mock company list data
  • Loading branch information
jmelot authored Dec 6, 2024
2 parents d5ea82b + c97107d commit a24a03a
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 6 deletions.
18 changes: 13 additions & 5 deletions web/gui-v2/src/components/ListView.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ import {
waitForElementToBeRemoved,
} from '@testing-library/react';

import { MOCK_COMPANIES } from '../test/mock-data';
jest.mock("../static_data/data", () => {
return {
__esModule: true,
company_data: MOCK_COMPANIES,
};
});

import { emotionCache, userEventSetup } from '../util/testing';
import ListView from './ListView';
import { exportsForTestingOnly } from './ListViewTable';
Expand All @@ -25,16 +33,16 @@ describe("ListView", () => {
);

// Filter by China and verify that the count updates
expect(screen.getByText('Viewing 691 companies')).toBeVisible();
expect(screen.getByText('Viewing 4 companies')).toBeVisible();
const regionHeader = screen.getByRole('columnheader', { name: /country/i });
await user.click(getByRole(regionHeader, 'button', { name: /open/i }));
const menu = screen.getByRole('listbox');
await user.click(getByText(menu, 'China'));
expect(screen.getByText('Viewing 43 of 691 companies')).toBeVisible();
await user.click(getByText(menu, 'United States'));
expect(screen.getByText('Viewing 2 of 4 companies')).toBeVisible();

// Reset the filters and verify that the count updates
await user.click(screen.getByRole('button', { name: /reset filters/i }));
expect(screen.getByText('Viewing 691 companies')).toBeVisible();
expect(screen.getByText('Viewing 4 companies')).toBeVisible();
}, 20000);


Expand All @@ -49,7 +57,7 @@ describe("ListView", () => {
await user.click(getByRole(companyHeader, 'combobox'));
const menu = screen.getByRole('listbox');
await user.click(getByText(menu, 'S&P 500'));
expect(screen.getByText('Viewing 500 of 691 companies')).toBeVisible();
expect(screen.getByText('Viewing 2 of 4 companies')).toBeVisible();
}, 20000);


Expand Down
2 changes: 1 addition & 1 deletion web/gui-v2/src/static_data/table_columns.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const generateSliderColDef = (dataKey, dataSubkey, extractFn, formatFn) => {
dataKey,
dataSubkey,
extract: extractFn ?? ((_val, row) => {
const res = row[dataKey][dataSubkey].total;
const res = row?.[dataKey]?.[dataSubkey]?.total;
return res === null ? 0 : res;
}),
format: formatFn ?? ((_val, row) => <CellStat data={row[dataKey][dataSubkey]} />),
Expand Down
87 changes: 87 additions & 0 deletions web/gui-v2/src/test/mock-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@

export const MOCK_COMPANIES = [
{
cset_id: 1,
name: "ABC Corporation",
continent: "North America",
country: "United States",
linkedin: [ "https://example.com" ],
groups: {
sp500: true,
genAI: false,
},
articles: {
ai_publications: { rank: 1, total: 5678 },
},
patents: {
ai_patents: { rank: 3, total: 777 },
},
other_metrics: {
ai_jobs: { rank: 8, total: 45 },
tt1_jobs: { rank: 2, total: 250 },
},
},
{
cset_id: 2,
name: "DEF Corporation",
continent: "Europe",
country: "Luxembourg",
linkedin: [ "https://example.com" ],
groups: {
sp500: true,
genAI: true,
},
articles: {
ai_publications: { rank: 5, total: 1115 },
},
patents: {
ai_patents: { rank: 2, total: 999 },
},
other_metrics: {
ai_jobs: { rank: 3, total: 150 },
tt1_jobs: { rank: 7, total: 97 },
},
},
{
cset_id: 3,
name: "GHI Incorporated",
continent: "North America",
country: "Canada",
linkedin: [ "https://example.com" ],
groups: {
sp500: false,
genAI: true,
},
articles: {
ai_publications: { rank: 8, total: 56 },
},
patents: {
ai_patents: { rank: 14, total: 120 },
},
other_metrics: {
ai_jobs: { rank: 21, total: 12 },
tt1_jobs: { rank: 41, total: 22 },
},
},
{
cset_id: 4,
name: "The JKL Company",
continent: "North America",
country: "United States",
linkedin: [ "https://example.com" ],
groups: {
sp500: false,
genAI: false,
},
articles: {
ai_publications: { rank: 99, total: 1 },
},
patents: {
ai_patents: { rank: 12, total: 135 },
},
other_metrics: {
ai_jobs: { rank: 75, total: 1 },
tt1_jobs: { rank: 36, total: 29 },
},
},
];

0 comments on commit a24a03a

Please sign in to comment.