Skip to content

Commit

Permalink
Merge pull request #298 from actiontech/fix/test-snapshot-error
Browse files Browse the repository at this point in the history
[fix]: Pages snapshots inconsistent with different timestamps
  • Loading branch information
Rain-1214 authored Jul 17, 2023
2 parents 258f331 + 46c1ee7 commit d8eab78
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@
* [ ] [feature]: 重构项目概览页面 <https://github.com/actiontech/sqle-ui/pull/292>
* [ ] [chore]: 界面优化长期任务【2.2307.0】 <https://github.com/actiontech/sqle/issues/1658>
* [ ] [feature]: 新增自定义规则页面 <https://github.com/actiontech/sqle-ui/pull/294>
* [ ] [fix]: 在不同时间段执行 Order/Detail/index.test.tsx 和 AuditResultCollection.test.tsx 时, 生成的快照文件不一致. 原因: 这两个页面中有些按钮的状态需要通过当前时间和工单概览接口返回的数据源运维时间做判断, 由于在 test case 中未 mock 当前时间, 导致不同时间段的按钮状态不一致.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 = () => {
Expand Down
26 changes: 1 addition & 25 deletions src/page/Order/Detail/__snapshots__/index.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2043,32 +2043,8 @@ exports[`Order/Detail should render on process order info by request 2`] = `
<div
class="ant-spin-nested-loading"
>
<div>
<div
aria-busy="true"
aria-live="polite"
class="ant-spin ant-spin-spinning"
>
<span
class="ant-spin-dot ant-spin-dot-spin"
>
<i
class="ant-spin-dot-item"
/>
<i
class="ant-spin-dot-item"
/>
<i
class="ant-spin-dot-item"
/>
<i
class="ant-spin-dot-item"
/>
</span>
</div>
</div>
<div
class="ant-spin-container ant-spin-blur"
class="ant-spin-container"
>
<div
class="ant-page-header"
Expand Down
2 changes: 1 addition & 1 deletion src/page/Order/Detail/__testData__/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ export const workflowTasks: IGetWorkflowTasksItemV2[] = [
instance_maintenance_times: [
{
maintenance_start_time: { hour: 0, minute: 0 },
maintenance_stop_time: { hour: 20, minute: 0 },
maintenance_stop_time: { hour: 10, minute: 0 },
},
],
},
Expand Down
8 changes: 8 additions & 0 deletions src/page/Order/Detail/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ describe('Order/Detail', () => {

let getInstanceSummarySpy: jest.SpyInstance;
const error = console.error;
let nowSpy: jest.SpyInstance;

beforeEach(() => {
console.error = jest.fn((message: any) => {
Expand Down Expand Up @@ -78,13 +79,20 @@ 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(() => {
jest.useRealTimers();
jest.clearAllTimers();
jest.clearAllMocks();
console.error = error;
nowSpy.mockRestore();
});

const mockCancelWorkflow = () => {
Expand Down

0 comments on commit d8eab78

Please sign in to comment.