Skip to content

Commit

Permalink
Fixed unit test (#53)
Browse files Browse the repository at this point in the history
* fix: Fixed datetime unit-test timezone

* fix: Fixed unit-test
  • Loading branch information
panchongyang authored Nov 23, 2022
1 parent 99a1c56 commit ef356ff
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 953 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
},
Expand Down
26 changes: 13 additions & 13 deletions src/components/Rule/RuleContent.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -127,26 +128,25 @@ 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')
.replaceAll(/\sname="rule_testId1_[\w-]+\w" /g, (_, i) => {
return ` name="test-name-${i}"`;
})
.replaceAll(' rdtActive rdtToday', '');

expect(ele).toMatchSnapshot();

done();
Expand Down
Loading

0 comments on commit ef356ff

Please sign in to comment.