From ef356ff393845b3c98d3a7ad16ff074984e80239 Mon Sep 17 00:00:00 2001 From: panchongyang <58692407+panchongyang@users.noreply.github.com> Date: Wed, 23 Nov 2022 14:03:49 +0800 Subject: [PATCH] Fixed unit test (#53) * fix: Fixed datetime unit-test timezone * fix: Fixed unit-test --- package.json | 3 +- src/components/Rule/RuleContent.test.tsx | 26 +- .../__snapshots__/RuleContent.test.tsx.snap | 941 +----------------- src/components/Rule/condition.test.tsx | 12 +- 4 files changed, 29 insertions(+), 953 deletions(-) diff --git a/package.json b/package.json index 63f22eb9..b82ed818 100644 --- a/package.json +++ b/package.json @@ -71,7 +71,8 @@ "start": "semantic-ui-css-patch && craco start", "build": "semantic-ui-css-patch && craco build", "test": "craco test", - "test:cov": "craco test --coverage --no-cache --watchAll", + "test:cov": "craco test --coverage --no-cache --watchAll=false", + "test:u": "craco test -u", "eject": "craco eject", "analyze": "source-map-explorer 'build/static/js/*.js'" }, diff --git a/src/components/Rule/RuleContent.test.tsx b/src/components/Rule/RuleContent.test.tsx index c5946ac3..035350ac 100644 --- a/src/components/Rule/RuleContent.test.tsx +++ b/src/components/Rule/RuleContent.test.tsx @@ -7,6 +7,7 @@ import RuleContent from '.'; import { IntlWrapper } from 'components/utils/wrapper'; import { hooksFormContainer, ruleContainer, segmentContainer, variationContainer } from 'pages/targeting/provider'; import sleep from 'utils/sleep'; +import { act } from 'react-test-renderer'; const RuleData = { id: 'testId1', @@ -127,18 +128,18 @@ test('RuleContent opt', (done) => { } ); - await userEvent.click(screen.getByText('Add')); - await sleep(500); - expect(baseElement).toMatchSnapshot(); - await userEvent.click(screen.getByText('number')); - await userEvent.click(screen.getByText('datetime')); - await userEvent.click(screen.getByText('semver')); - await userEvent.click(screen.getByText('segment')); - - const serve = screen.getAllByText('Please select').pop(); - serve && (await userEvent.click(serve)); - userEvent.click(screen.getByText('a percentage rollout')); - + await act(async () => { + await userEvent.click(screen.getByText('Add')); + expect(baseElement).toMatchSnapshot(); + await userEvent.click(screen.getByText('number')); + await userEvent.click(screen.getByText('semver')); + await userEvent.click(screen.getByText('segment')); + + const serve = screen.getAllByText('Please select').pop(); + serve && (await userEvent.click(serve)); + userEvent.click(screen.getByText('a percentage rollout')); + }); + const ele = document.createElement('div'); ele.innerHTML = baseElement.innerHTML .replaceAll(/(\d\d\/\d\d\/\d\d\d\d )*\d\d:\d\d:\d\d/g, 'test_value') @@ -146,7 +147,6 @@ test('RuleContent opt', (done) => { return ` name="test-name-${i}"`; }) .replaceAll(' rdtActive rdtToday', ''); - expect(ele).toMatchSnapshot(); done(); diff --git a/src/components/Rule/__snapshots__/RuleContent.test.tsx.snap b/src/components/Rule/__snapshots__/RuleContent.test.tsx.snap index e7df0a11..309b38f5 100644 --- a/src/components/Rule/__snapshots__/RuleContent.test.tsx.snap +++ b/src/components/Rule/__snapshots__/RuleContent.test.tsx.snap @@ -579,937 +579,6 @@ exports[`RuleContent opt 2`] = ` name="test-name-4436" role="listbox" tabindex="0" - > -
- - ‹ - - | -- November 2022 - | -- - › - - | -||||
---|---|---|---|---|---|---|
- Su - | -- Mo - | -- Tu - | -- We - | -- Th - | -- Fr - | -- Sa - | -
- 30 - | -- 31 - | -- 1 - | -- 2 - | -- 3 - | -- 4 - | -- 5 - | -
- 6 - | -- 7 - | -- 8 - | -- 9 - | -- 10 - | -- 11 - | -- 12 - | -
- 13 - | -- 14 - | -- 15 - | -- 16 - | -- 17 - | -- 18 - | -- 19 - | -
- 20 - | -- 21 - | -- 22 - | -- 23 - | -- 24 - | -- 25 - | -- 26 - | -
- 27 - | -- 28 - | -- 29 - | -- 30 - | -- 1 - | -- 2 - | -- 3 - | -
- 4 - | -- 5 - | -- 6 - | -- 7 - | -- 8 - | -- 9 - | -- 10 - | -
- test_value - | -