Skip to content

Commit 739c354

Browse files
committed
test: cover remote form touched behaviour
1 parent 0462f82 commit 739c354

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<script>
2+
import { touched_form } from './touched.remote.js';
3+
import { tick } from 'svelte';
4+
5+
const markNameTouched = async () => {
6+
touched_form.fields.name.set('example');
7+
await tick();
8+
};
9+
</script>
10+
11+
<h1>Remote Form Touched Test</h1>
12+
13+
<p id="touched-name">Name touched: {touched_form.fields.name.touched() ? 'yes' : 'no'}</p>
14+
<p id="touched-age">Age touched: {touched_form.fields.age.touched() ? 'yes' : 'no'}</p>
15+
16+
<button id="set-btn" type="button" on:click={markNameTouched}> set name programmatically </button>
17+
18+
<form {...touched_form}>
19+
<label>
20+
Name
21+
<input id="name-input" {...touched_form.fields.name.as('text')} />
22+
</label>
23+
24+
<label>
25+
Age
26+
<input id="age-input" {...touched_form.fields.age.as('number')} />
27+
</label>
28+
29+
<button id="reset-btn" type="reset">Reset</button>
30+
</form>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { form } from '$app/server';
2+
import * as v from 'valibot';
3+
4+
export const touched_form = form(
5+
v.object({
6+
name: v.optional(v.string()),
7+
age: v.optional(v.number())
8+
}),
9+
(data) => ({ submitted: data })
10+
);

packages/kit/test/apps/basics/test/test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,6 +1982,30 @@ test.describe('remote functions', () => {
19821982
expect(JSON.parse(arrayValue)).toEqual([{ leaf: 'array-0-leaf' }, { leaf: 'array-1-leaf' }]);
19831983
});
19841984

1985+
test('form fields touched tracks interactions', async ({ page, javaScriptEnabled }) => {
1986+
if (!javaScriptEnabled) return;
1987+
1988+
await page.goto('/remote/form/touched');
1989+
1990+
const nameTouched = page.locator('#touched-name');
1991+
const ageTouched = page.locator('#touched-age');
1992+
1993+
await expect(nameTouched).toHaveText('Name touched: no');
1994+
await expect(ageTouched).toHaveText('Age touched: no');
1995+
1996+
await page.click('#set-btn');
1997+
await expect(nameTouched).toHaveText('Name touched: yes');
1998+
1999+
await page.click('#reset-btn');
2000+
await expect(nameTouched).toHaveText('Name touched: no');
2001+
2002+
await page.fill('#age-input', '42');
2003+
await expect(ageTouched).toHaveText('Age touched: yes');
2004+
2005+
await page.click('#reset-btn');
2006+
await expect(ageTouched).toHaveText('Age touched: no');
2007+
});
2008+
19852009
test('selects are not nuked when unrelated controls change', async ({
19862010
page,
19872011
javaScriptEnabled

0 commit comments

Comments
 (0)