From 46c1ee734bbf5dcc0e591914ba03ef724fbf7d84 Mon Sep 17 00:00:00 2001 From: lizhensheng Date: Mon, 17 Jul 2023 11:28:52 +0800 Subject: [PATCH] [fix]: Pages snapshots inconsistent with different timestamps --- CHANGELOG.md | 1 + .../__test__/AuditResultCollection.test.tsx | 8 ++++++ .../Detail/__snapshots__/index.test.tsx.snap | 26 +------------------ src/page/Order/Detail/__testData__/index.tsx | 2 +- src/page/Order/Detail/index.test.tsx | 8 ++++++ 5 files changed, 19 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b36618e..7d507c78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,3 +25,4 @@ * [ ] [feature]: 重构项目概览页面 * [ ] [chore]: 界面优化长期任务【2.2307.0】 * [ ] [feature]: 新增自定义规则页面 +* [ ] [fix]: 在不同时间段执行 Order/Detail/index.test.tsx 和 AuditResultCollection.test.tsx 时, 生成的快照文件不一致. 原因: 这两个页面中有些按钮的状态需要通过当前时间和工单概览接口返回的数据源运维时间做判断, 由于在 test case 中未 mock 当前时间, 导致不同时间段的按钮状态不一致. diff --git a/src/page/Order/AuditResult/__test__/AuditResultCollection.test.tsx b/src/page/Order/AuditResult/__test__/AuditResultCollection.test.tsx index faa95c77..18f20d59 100644 --- a/src/page/Order/AuditResult/__test__/AuditResultCollection.test.tsx +++ b/src/page/Order/AuditResult/__test__/AuditResultCollection.test.tsx @@ -76,6 +76,8 @@ const workflowId = '22'; describe('test AuditResultCollection', () => { const mockSetAuditResultActiveKey = jest.fn(); const mockRefreshOrder = jest.fn(); + let nowSpy: jest.SpyInstance; + beforeEach(() => { mockUseStyle(); mockGetAllRules(); @@ -87,11 +89,17 @@ describe('test AuditResultCollection', () => { user: { username: 'admin' }, }) ); + nowSpy = jest + .spyOn(Date, 'now') + .mockImplementation(() => + new Date('2023-07-11T09:19:54+08:00').getTime() + ); }); afterEach(() => { jest.useRealTimers(); jest.clearAllTimers(); + nowSpy.mockRestore(); }); const mockSuccessMessage = () => { diff --git a/src/page/Order/Detail/__snapshots__/index.test.tsx.snap b/src/page/Order/Detail/__snapshots__/index.test.tsx.snap index 48e8b048..6ae4f7a8 100644 --- a/src/page/Order/Detail/__snapshots__/index.test.tsx.snap +++ b/src/page/Order/Detail/__snapshots__/index.test.tsx.snap @@ -2043,32 +2043,8 @@ exports[`Order/Detail should render on process order info by request 2`] = `
-
-
- - - - - - -
-
{ let getInstanceSummarySpy: jest.SpyInstance; const error = console.error; + let nowSpy: jest.SpyInstance; beforeEach(() => { console.error = jest.fn((message: any) => { @@ -78,6 +79,12 @@ describe('Order/Detail', () => { mockGetAllRules(); getInstanceSummarySpy = mockGetSummaryOfInstanceTasks(); jest.useFakeTimers(); + + nowSpy = jest + .spyOn(Date, 'now') + .mockImplementation(() => + new Date('2023-07-11T09:19:54+08:00').getTime() + ); }); afterEach(() => { @@ -85,6 +92,7 @@ describe('Order/Detail', () => { jest.clearAllTimers(); jest.clearAllMocks(); console.error = error; + nowSpy.mockRestore(); }); const mockCancelWorkflow = () => {