Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions apps/web/src/modules/analyze/components/TableList.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { render } from '@testing-library/react';
import TableList from './TableList';
import { chartUserSettingState } from '@modules/analyze/store';

jest.mock('public/images/analyze/number-100.svg', () => ({
__esModule: true,
default: () => null,
}));
jest.mock('public/images/analyze/number-1.svg', () => ({
__esModule: true,
default: () => null,
}));

jest.mock('next-i18next', () => ({
useTranslation: () => ({ t: (key: string) => key }),
}));
jest.mock('next/link', () => ({
__esModule: true,
default: ({ children }: { children: React.ReactNode }) => children,
}));
jest.mock('@tanstack/react-query', () => ({
useQueries: () => [],
}));
jest.mock('@oss-compass/graphql', () => ({
useMetricModelsOverviewQuery: { getKey: () => ['k'], fetcher: () => () => null },
}));
jest.mock('@common/gqlClient', () => ({ __esModule: true, default: {} }));
jest.mock('@modules/analyze/hooks/useCompareItems', () => ({
__esModule: true,
default: () => ({ compareItems: [] }),
}));
jest.mock('@modules/analyze/hooks/useQueryMetricType', () => ({
__esModule: true,
default: () => 'contributor',
}));

describe('TableList', () => {
it('initializes the score system from the persisted user setting', () => {
// 用户在导航栏设置过 1 分制并已持久化:概览表格必须与图表一致地以 1 分制
// 渲染,而不是硬编码百分制再要求用户手动切换。
chartUserSettingState.onePointSys = true;
const { container } = render(<TableList />);
expect(container.textContent).toContain('analyze:mark.point');
expect(container.textContent).not.toContain('analyze:mark.percentage');
});
});
7 changes: 6 additions & 1 deletion apps/web/src/modules/analyze/components/TableList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,12 @@ const TrendsList: React.FC = () => {
scope: 'contributor',
},
];
const [onePointSys, setOnePointSys] = useState(false);
// 初值来自持久化的用户设置(导航栏可切换并写入 localStorage):与
// OverviewSummary/LineChart 的 useState(chartUserSettingState.onePointSys)
// 一致,避免表格以百分制渲染而上方图表以 1 分制渲染的不一致。
const [onePointSys, setOnePointSys] = useState(
chartUserSettingState.onePointSys
);

const { compareItems } = useCompareItems();
const snap = useSnapshot(chartUserSettingState);
Expand Down