diff --git a/web/gui-v2/src/components/ListView.test.js b/web/gui-v2/src/components/ListView.test.js index e904eff..c06df4d 100644 --- a/web/gui-v2/src/components/ListView.test.js +++ b/web/gui-v2/src/components/ListView.test.js @@ -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'; @@ -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); @@ -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); diff --git a/web/gui-v2/src/static_data/table_columns.js b/web/gui-v2/src/static_data/table_columns.js index d673bdc..7ad4b19 100644 --- a/web/gui-v2/src/static_data/table_columns.js +++ b/web/gui-v2/src/static_data/table_columns.js @@ -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) => ), diff --git a/web/gui-v2/src/test/mock-data.js b/web/gui-v2/src/test/mock-data.js new file mode 100644 index 0000000..df55c03 --- /dev/null +++ b/web/gui-v2/src/test/mock-data.js @@ -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 }, + }, + }, +];