test: make testing more stable (#2277)
This commit is contained in:
parent
d80213be5e
commit
1f91ebc65e
@ -53,28 +53,16 @@ describe('Checkbox.Group', () => {
|
|||||||
const option1 = screen.getByLabelText('选项1');
|
const option1 = screen.getByLabelText('选项1');
|
||||||
const option2 = screen.getByLabelText('选项2');
|
const option2 = screen.getByLabelText('选项2');
|
||||||
await userEvent.click(option1);
|
await userEvent.click(option1);
|
||||||
expect(container.querySelectorAll('.ant-tag')).toMatchInlineSnapshot(`
|
expect(Array.from(container.querySelectorAll('.ant-tag')).map((el) => el.innerHTML)).toMatchInlineSnapshot(`
|
||||||
NodeList [
|
[
|
||||||
<span
|
"选项1",
|
||||||
class="ant-tag ant-tag-red css-dev-only-do-not-override-14wwjjs"
|
|
||||||
>
|
|
||||||
选项1
|
|
||||||
</span>,
|
|
||||||
]
|
]
|
||||||
`);
|
`);
|
||||||
await userEvent.click(option2);
|
await userEvent.click(option2);
|
||||||
expect(container.querySelectorAll('.ant-tag')).toMatchInlineSnapshot(`
|
expect(Array.from(container.querySelectorAll('.ant-tag')).map((el) => el.innerHTML)).toMatchInlineSnapshot(`
|
||||||
NodeList [
|
[
|
||||||
<span
|
"选项1",
|
||||||
class="ant-tag ant-tag-red css-dev-only-do-not-override-14wwjjs"
|
"选项2",
|
||||||
>
|
|
||||||
选项1
|
|
||||||
</span>,
|
|
||||||
<span
|
|
||||||
class="ant-tag ant-tag-blue css-dev-only-do-not-override-14wwjjs"
|
|
||||||
>
|
|
||||||
选项2
|
|
||||||
</span>,
|
|
||||||
]
|
]
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
@ -39,31 +39,7 @@ describe('Input.TextArea', () => {
|
|||||||
fireEvent.change(textarea, { target: { value: 'Hello World, Hello World' } });
|
fireEvent.change(textarea, { target: { value: 'Hello World, Hello World' } });
|
||||||
|
|
||||||
expect(textarea.value).toBe('Hello World, Hello World');
|
expect(textarea.value).toBe('Hello World, Hello World');
|
||||||
expect(screen.getAllByText('Hello World, Hello World')).toMatchInlineSnapshot(`
|
expect(screen.getAllByText('Hello World, Hello World')).toHaveLength(4);
|
||||||
[
|
|
||||||
<textarea
|
|
||||||
class="ant-input css-dev-only-do-not-override-14wwjjs"
|
|
||||||
style="resize: none; height: -70px; min-height: -14px; max-height: -70px;"
|
|
||||||
>
|
|
||||||
Hello World, Hello World
|
|
||||||
</textarea>,
|
|
||||||
<div
|
|
||||||
style="line-height: 1.612;"
|
|
||||||
>
|
|
||||||
Hello World, Hello World
|
|
||||||
</div>,
|
|
||||||
<div
|
|
||||||
style="overflow: hidden; overflow-wrap: break-word; text-overflow: ellipsis; white-space: nowrap; word-break: break-all;"
|
|
||||||
>
|
|
||||||
Hello World, Hello World
|
|
||||||
</div>,
|
|
||||||
<div
|
|
||||||
style="line-height: 1.612;"
|
|
||||||
>
|
|
||||||
Hello World, Hello World
|
|
||||||
</div>,
|
|
||||||
]
|
|
||||||
`);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not display undefined', () => {
|
it('should not display undefined', () => {
|
||||||
@ -88,16 +64,7 @@ describe('Input.URL', () => {
|
|||||||
const input = container.querySelector('input') as HTMLInputElement;
|
const input = container.querySelector('input') as HTMLInputElement;
|
||||||
await userEvent.type(input, 'https://www.nocobase.com');
|
await userEvent.type(input, 'https://www.nocobase.com');
|
||||||
expect(input.value).toBe('https://www.nocobase.com');
|
expect(input.value).toBe('https://www.nocobase.com');
|
||||||
expect(screen.getByText('https://www.nocobase.com')).toMatchInlineSnapshot(`
|
expect(screen.getByText('https://www.nocobase.com')).toBeInTheDocument();
|
||||||
<a
|
|
||||||
class="ant-typography ant-typography-ellipsis ant-typography-single-line ant-typography-ellipsis-single-line css-dev-only-do-not-override-14wwjjs"
|
|
||||||
href="https://www.nocobase.com"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
target="_blank"
|
|
||||||
>
|
|
||||||
https://www.nocobase.com
|
|
||||||
</a>
|
|
||||||
`);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should display the error when the value is invalid', async () => {
|
it('should display the error when the value is invalid', async () => {
|
||||||
@ -106,16 +73,7 @@ describe('Input.URL', () => {
|
|||||||
const input = container.querySelector('input') as HTMLInputElement;
|
const input = container.querySelector('input') as HTMLInputElement;
|
||||||
await userEvent.type(input, 'abcd');
|
await userEvent.type(input, 'abcd');
|
||||||
expect(input.value).toBe('abcd');
|
expect(input.value).toBe('abcd');
|
||||||
expect(screen.getByText('abcd')).toMatchInlineSnapshot(`
|
expect(screen.getByText('abcd')).toBeInTheDocument();
|
||||||
<a
|
|
||||||
class="ant-typography ant-typography-ellipsis ant-typography-single-line ant-typography-ellipsis-single-line css-dev-only-do-not-override-14wwjjs"
|
|
||||||
href="abcd"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
target="_blank"
|
|
||||||
>
|
|
||||||
abcd
|
|
||||||
</a>
|
|
||||||
`);
|
|
||||||
|
|
||||||
// show error message
|
// show error message
|
||||||
expect(screen.getByText('The field value is a invalid url').innerHTML).toBe('The field value is a invalid url');
|
expect(screen.getByText('The field value is a invalid url').innerHTML).toBe('The field value is a invalid url');
|
||||||
|
@ -1,134 +0,0 @@
|
|||||||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
||||||
|
|
||||||
exports[`Password > should works with checkStrength 1`] = `
|
|
||||||
<div>
|
|
||||||
<div
|
|
||||||
class="ant-formily-item ant-formily-item-layout-horizontal ant-formily-item-feedback-layout-loose ant-formily-item-label-align-right ant-formily-item-control-align-left css-dev-only-do-not-override-14wwjjs"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="ant-formily-item-label"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="ant-formily-item-label-content"
|
|
||||||
>
|
|
||||||
<span>
|
|
||||||
<label>
|
|
||||||
Editable
|
|
||||||
</label>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<span
|
|
||||||
class="ant-formily-item-colon"
|
|
||||||
>
|
|
||||||
:
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
class="ant-formily-item-control"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="ant-formily-item-control-content"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="ant-formily-item-control-content-component"
|
|
||||||
>
|
|
||||||
<span>
|
|
||||||
<span
|
|
||||||
class="ant-input-affix-wrapper ant-input-password css-dev-only-do-not-override-14wwjjs"
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
class="ant-input css-dev-only-do-not-override-14wwjjs"
|
|
||||||
type="password"
|
|
||||||
value="123456"
|
|
||||||
/>
|
|
||||||
<span
|
|
||||||
class="ant-input-suffix"
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
aria-label="eye-invisible"
|
|
||||||
class="anticon anticon-eye-invisible ant-input-password-icon"
|
|
||||||
role="img"
|
|
||||||
tabindex="-1"
|
|
||||||
>
|
|
||||||
<svg
|
|
||||||
aria-hidden="true"
|
|
||||||
data-icon="eye-invisible"
|
|
||||||
fill="currentColor"
|
|
||||||
focusable="false"
|
|
||||||
height="1em"
|
|
||||||
viewBox="64 64 896 896"
|
|
||||||
width="1em"
|
|
||||||
>
|
|
||||||
<path
|
|
||||||
d="M942.2 486.2Q889.47 375.11 816.7 305l-50.88 50.88C807.31 395.53 843.45 447.4 874.7 512 791.5 684.2 673.4 766 512 766q-72.67 0-133.87-22.38L323 798.75Q408 838 512 838q288.3 0 430.2-300.3a60.29 60.29 0 000-51.5zm-63.57-320.64L836 122.88a8 8 0 00-11.32 0L715.31 232.2Q624.86 186 512 186q-288.3 0-430.2 300.3a60.3 60.3 0 000 51.5q56.69 119.4 136.5 191.41L112.48 835a8 8 0 000 11.31L155.17 889a8 8 0 0011.31 0l712.15-712.12a8 8 0 000-11.32zM149.3 512C232.6 339.8 350.7 258 512 258c54.54 0 104.13 9.36 149.12 28.39l-70.3 70.3a176 176 0 00-238.13 238.13l-83.42 83.42C223.1 637.49 183.3 582.28 149.3 512zm246.7 0a112.11 112.11 0 01146.2-106.69L401.31 546.2A112 112 0 01396 512z"
|
|
||||||
/>
|
|
||||||
<path
|
|
||||||
d="M508 624c-3.46 0-6.87-.16-10.25-.47l-52.82 52.82a176.09 176.09 0 00227.42-227.42l-52.82 52.82c.31 3.38.47 6.79.47 10.25a111.94 111.94 0 01-112 112z"
|
|
||||||
/>
|
|
||||||
</svg>
|
|
||||||
</span>
|
|
||||||
</span>
|
|
||||||
</span>
|
|
||||||
<div
|
|
||||||
style="background: rgb(224, 224, 224); margin-bottom: 3px; position: relative;"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
style="position: absolute; z-index: 1; height: 8px; top: 0px; background: rgb(255, 255, 255); width: 1px; transform: translate(-50%, 0); left: 20%;"
|
|
||||||
/>
|
|
||||||
<div
|
|
||||||
style="position: absolute; z-index: 1; height: 8px; top: 0px; background: rgb(255, 255, 255); width: 1px; transform: translate(-50%, 0); left: 40%;"
|
|
||||||
/>
|
|
||||||
<div
|
|
||||||
style="position: absolute; z-index: 1; height: 8px; top: 0px; background: rgb(255, 255, 255); width: 1px; transform: translate(-50%, 0); left: 60%;"
|
|
||||||
/>
|
|
||||||
<div
|
|
||||||
style="position: absolute; z-index: 1; height: 8px; top: 0px; background: rgb(255, 255, 255); width: 1px; transform: translate(-50%, 0); left: 80%;"
|
|
||||||
/>
|
|
||||||
<div
|
|
||||||
style="position: relative; transition: all 0.35s ease-in-out; height: 8px; width: 100%; margin-top: 5px; clip-path: polygon(0 0,20% 0,20% 100%,0 100%);"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
class="ant-formily-item ant-formily-item-layout-horizontal ant-formily-item-feedback-layout-loose ant-formily-item-label-align-right ant-formily-item-control-align-left css-dev-only-do-not-override-14wwjjs"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="ant-formily-item-label"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="ant-formily-item-label-content"
|
|
||||||
>
|
|
||||||
<span>
|
|
||||||
<label>
|
|
||||||
Read pretty
|
|
||||||
</label>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<span
|
|
||||||
class="ant-formily-item-colon"
|
|
||||||
>
|
|
||||||
:
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
class="ant-formily-item-control"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="ant-formily-item-control-content"
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
class="ant-formily-item-control-content-component"
|
|
||||||
>
|
|
||||||
<div>
|
|
||||||
********
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`;
|
|
@ -17,6 +17,6 @@ describe('Password', () => {
|
|||||||
const { container } = render(<App2 />);
|
const { container } = render(<App2 />);
|
||||||
const input = container.querySelector('input') as HTMLInputElement;
|
const input = container.querySelector('input') as HTMLInputElement;
|
||||||
fireEvent.change(input, { target: { value: '123456' } });
|
fireEvent.change(input, { target: { value: '123456' } });
|
||||||
expect(container).toMatchSnapshot();
|
expect(screen.getByText('********')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -13,14 +13,7 @@ describe('Variable', () => {
|
|||||||
await userEvent.click(screen.getByText('x'));
|
await userEvent.click(screen.getByText('x'));
|
||||||
await userEvent.click(screen.getByText('v1'));
|
await userEvent.click(screen.getByText('v1'));
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(screen.getByText('v1', { selector: '.ant-tag' })).toMatchInlineSnapshot(`
|
expect(screen.getByText('v1', { selector: '.ant-tag' }).innerHTML).toMatchInlineSnapshot('"v1"');
|
||||||
<span
|
|
||||||
class="ant-tag ant-tag-blue css-dev-only-do-not-override-14wwjjs"
|
|
||||||
contenteditable="false"
|
|
||||||
>
|
|
||||||
v1
|
|
||||||
</span>
|
|
||||||
`);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -35,20 +28,7 @@ describe('Variable', () => {
|
|||||||
await userEvent.click(variableSelector);
|
await userEvent.click(variableSelector);
|
||||||
await userEvent.click(screen.getByText('v1'));
|
await userEvent.click(screen.getByText('v1'));
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(input).toMatchInlineSnapshot(`
|
expect(input.innerHTML).toMatchInlineSnapshot('"<span class=\\"ant-tag ant-tag-blue\\" contenteditable=\\"false\\" data-variable=\\"v1\\">v1</span>"');
|
||||||
<div
|
|
||||||
class="css-dev-only-do-not-override-14wwjjs ant-input css-1p5yrh5"
|
|
||||||
contenteditable="true"
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
class="ant-tag ant-tag-blue"
|
|
||||||
contenteditable="false"
|
|
||||||
data-variable="v1"
|
|
||||||
>
|
|
||||||
v1
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
`);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user