Skip to content

Commit b0a9c40

Browse files
committed
vue: move dynamic components test to dedicated file (which uses javascript)
1 parent 8ac4f49 commit b0a9c40

File tree

4 files changed

+72
-16
lines changed

4 files changed

+72
-16
lines changed

packages/vue3/test-app/Pages/FormHelper/Data.vue

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ const reassignSingle = () => {
3838
form.defaults('name', 'single value')
3939
}
4040
41-
const addCustomOtherProp = () => {
42-
form.custom.other_prop = 'dynamic_value' // Add nested dynamic property
43-
}
44-
4541
const formDataOutput = reactive({
4642
json: '',
4743
})
@@ -71,12 +67,7 @@ watch(
7167
<input type="checkbox" id="remember" name="remember" v-model="form.remember" />
7268
</label>
7369
<span class="remember_error" v-if="form.errors.remember">{{ form.errors.remember }}</span>
74-
<label>
75-
Accept Terms and Conditions
76-
<input type="checkbox" id="accept_tos" name="accept_tos" v-model="form.accept_tos" />
77-
</label>
78-
<span class="accept_tos_error" v-if="form.errors.accept_tos">{{ form.errors.accept_tos }}</span>
79-
70+
<!-- Accept Terms and Conditions and dynamic property logic removed -->
8071
<button @click="submit" class="submit">Submit form</button>
8172

8273
<button @click="resetAll" class="reset">Reset all data</button>
@@ -86,8 +77,6 @@ watch(
8677
<button @click="reassignObject" class="reassign-object">Reassign default values</button>
8778
<button @click="reassignSingle" class="reassign-single">Reassign single default</button>
8879

89-
<button @click="addCustomOtherProp" class="add-custom-other-prop">Add custom.other_prop</button>
90-
9180
<span class="errors-status">Form has {{ form.hasErrors ? '' : 'no ' }}errors</span>
9281

9382
<div id="form-data-output" data-test-id="form-data-output" style="display: none">{{ formDataOutput.json }}</div>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<script setup>
2+
import { useForm, usePage } from '@inertiajs/vue3'
3+
import { reactive, watch } from 'vue'
4+
5+
const form = useForm({
6+
name: 'foo',
7+
handle: 'example',
8+
remember: false,
9+
custom: {},
10+
})
11+
12+
const page = usePage()
13+
14+
const submit = () => {
15+
form.post(page.url)
16+
}
17+
18+
const addCustomOtherProp = () => {
19+
form.custom.other_prop = 'dynamic_value' // Add nested dynamic property
20+
}
21+
22+
const formDataOutput = reactive({
23+
json: '',
24+
})
25+
watch(
26+
() => form.data(),
27+
(newData) => {
28+
formDataOutput.json = JSON.stringify(newData)
29+
},
30+
{ deep: true, immediate: true },
31+
)
32+
</script>
33+
34+
<template>
35+
<div>
36+
<label>
37+
Full Name
38+
<input type="text" id="name" name="name" v-model="form.name" />
39+
</label>
40+
<span class="name_error" v-if="form.errors.name">{{ form.errors.name }}</span>
41+
42+
<label>
43+
Accept Terms and Conditions
44+
<input type="checkbox" id="accept_tos" name="accept_tos" v-model="form.accept_tos" />
45+
</label>
46+
<span class="accept_tos_error" v-if="form.errors.accept_tos">{{ form.errors.accept_tos }}</span>
47+
48+
<button @click="submit" class="submit">Submit form</button>
49+
50+
<button @click="addCustomOtherProp" class="add-custom-other-prop">Add custom.other_prop</button>
51+
52+
<div id="form-data-output" data-test-id="form-data-output" style="display: none">{{ formDataOutput.json }}</div>
53+
</div>
54+
</template>

tests/app/server.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,13 @@ app.post('/form-helper/data', (req, res) =>
157157
}),
158158
)
159159

160+
app.post('/form-helper/data-dynamic', (req, res) =>
161+
inertia.render(req, res, {
162+
component: 'FormHelper/DataDynamic',
163+
props: {},
164+
}),
165+
)
166+
160167
app.get('/form-helper/nested', (req, res) =>
161168
inertia.render(req, res, {
162169
component: 'FormHelper/Nested',
@@ -549,11 +556,17 @@ app.post('/form-component/progress', async (req, res) =>
549556
setTimeout(() => inertia.render(req, res, { component: 'FormComponent/Progress' }), 500),
550557
)
551558
app.get('/form-component/state', (req, res) => inertia.render(req, res, { component: 'FormComponent/State' }))
552-
app.get('/form-component/dotted-keys', (req, res) => inertia.render(req, res, { component: 'FormComponent/DottedKeys' }))
559+
app.get('/form-component/dotted-keys', (req, res) =>
560+
inertia.render(req, res, { component: 'FormComponent/DottedKeys' }),
561+
)
553562
app.get('/form-component/ref', (req, res) => inertia.render(req, res, { component: 'FormComponent/Ref' }))
554-
app.get('/form-component/uppercase-method', (req, res) => inertia.render(req, res, { component: 'FormComponent/UppercaseMethod' }))
563+
app.get('/form-component/uppercase-method', (req, res) =>
564+
inertia.render(req, res, { component: 'FormComponent/UppercaseMethod' }),
565+
)
555566

556-
app.get('/form-component/url/with/segements', (req, res) => inertia.render(req, res, { component: 'FormComponent/EmptyAction' }))
567+
app.get('/form-component/url/with/segements', (req, res) =>
568+
inertia.render(req, res, { component: 'FormComponent/EmptyAction' }),
569+
)
557570
app.post('/form-component/url/with/segements', async (req, res) =>
558571
inertia.render(req, res, {
559572
component: 'FormComponent/EmptyAction',

tests/form-component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ test.describe('Form Component', () => {
112112
test.describe('Dynamic Properties', () => {
113113
test.beforeEach(async ({ page }) => {
114114
pageLoads.watch(page)
115-
await page.goto('/form-helper/data') // Navigate to the FormHelper/Data page
115+
await page.goto('/form-helper/data-dynamic')
116116
})
117117

118118
test('initial data() output contains only initial properties', async ({ page }) => {

0 commit comments

Comments
 (0)