Skip to content

Commit

Permalink
remove tests duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
Varixo committed Dec 25, 2024
1 parent 7160354 commit d266bdd
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 118 deletions.
110 changes: 72 additions & 38 deletions packages/qwik/src/core/tests/attributes.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,50 +119,84 @@ describe.each([
);
});

it('should bind checked attribute', async () => {
const BindCmp = component$(() => {
const show = useSignal(false);
return (
<>
<label for="toggle">
<input type="checkbox" bind:checked={show} />
Show conditional
</label>
<div>{show.value.toString()}</div>
</>
describe('binding', () => {
it('should bind checked attribute', async () => {
const BindCmp = component$(() => {
const show = useSignal(false);
return (
<>
<label for="toggle">
<input type="checkbox" bind:checked={show} />
Show conditional
</label>
<div>{show.value.toString()}</div>
</>
);
});

const { vNode, document } = await render(<BindCmp />, { debug });

expect(vNode).toMatchVDOM(
<Component ssr-required>
<Fragment ssr-required>
<label for="toggle">
<input type="checkbox" checked={false} />
{'Show conditional'}
</label>
<div>false</div>
</Fragment>
</Component>
);

// simulate checkbox click
const input = document.querySelector('input')!;
input.checked = true;
await trigger(document.body, 'input', 'input');

expect(vNode).toMatchVDOM(
<Component ssr-required>
<Fragment ssr-required>
<label for="toggle">
<input type="checkbox" checked={true} />
{'Show conditional'}
</label>
<div>true</div>
</Fragment>
</Component>
);
});

const { vNode, document } = await render(<BindCmp />, { debug });
it('should bind textarea value', async () => {
const Cmp = component$(() => {
const value = useSignal('123');
return (
<div>
<textarea bind:value={value} />
<input bind:value={value} />
</div>
);
});
const { document } = await render(<Cmp />, { debug });

expect(vNode).toMatchVDOM(
<Component ssr-required>
<Fragment ssr-required>
<label for="toggle">
<input type="checkbox" checked={false} />
{'Show conditional'}
</label>
<div>false</div>
</Fragment>
</Component>
);
await expect(document.querySelector('div')).toMatchDOM(
<div>
<textarea>123</textarea>
<input value="123" />
</div>
);

// simulate checkbox click
const input = document.querySelector('input')!;
input.checked = true;
await trigger(document.body, 'input', 'input');
// simulate input
const textarea = document.querySelector('textarea')!;
textarea.value = 'abcd';
await trigger(document.body, textarea, 'input');

expect(vNode).toMatchVDOM(
<Component ssr-required>
<Fragment ssr-required>
<label for="toggle">
<input type="checkbox" checked={true} />
{'Show conditional'}
</label>
<div>true</div>
</Fragment>
</Component>
);
await expect(document.querySelector('div')).toMatchDOM(
<div>
<textarea>abcd</textarea>
<input value="abcd" />
</div>
);
});
});

it('should render preventdefault attribute', async () => {
Expand Down
80 changes: 0 additions & 80 deletions packages/qwik/src/core/tests/use-signal.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -553,86 +553,6 @@ describe.each([
});
});

describe('binding', () => {
it('should bind checked attribute', async () => {
const BindCmp = component$(() => {
const show = useSignal(false);
return (
<>
<label for="toggle">
<input type="checkbox" bind:checked={show} />
Show conditional
</label>
<div>{show.value.toString()}</div>
</>
);
});

const { vNode, document } = await render(<BindCmp />, { debug });

expect(vNode).toMatchVDOM(
<Component ssr-required>
<Fragment ssr-required>
<label for="toggle">
<input type="checkbox" checked={false} />
{'Show conditional'}
</label>
<div>false</div>
</Fragment>
</Component>
);

// simulate checkbox click
const input = document.querySelector('input')!;
input.checked = true;
await trigger(document.body, 'input', 'input');

expect(vNode).toMatchVDOM(
<Component ssr-required>
<Fragment ssr-required>
<label for="toggle">
<input type="checkbox" checked={true} />
{'Show conditional'}
</label>
<div>true</div>
</Fragment>
</Component>
);
});

it('should bind textarea value', async () => {
const Cmp = component$(() => {
const value = useSignal('123');
return (
<div>
<textarea bind:value={value} />
<input bind:value={value} />
</div>
);
});
const { document } = await render(<Cmp />, { debug });

await expect(document.querySelector('div')).toMatchDOM(
<div>
<textarea>123</textarea>
<input value="123" />
</div>
);

// simulate input
const textarea = document.querySelector('textarea')!;
textarea.value = 'abcd';
await trigger(document.body, textarea, 'input');

await expect(document.querySelector('div')).toMatchDOM(
<div>
<textarea>abcd</textarea>
<input value="abcd" />
</div>
);
});
});

describe('regression', () => {
it('#4249 - should render signal text with double condition', async () => {
const Issue4249 = component$(() => {
Expand Down

0 comments on commit d266bdd

Please sign in to comment.