Skip to content

Commit cf9cae5

Browse files
committed
Using /_components as the URL
1 parent a798d38 commit cf9cae5

File tree

6 files changed

+27
-27
lines changed

6 files changed

+27
-27
lines changed

src/LiveComponent/assets/test/controller/action.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('LiveController Action Tests', () => {
1919
const template = (data) => `
2020
<div
2121
data-controller="live"
22-
data-live-url-value="http://localhost/components/my_component"
22+
data-live-url-value="http://localhost/_components/my_component"
2323
>
2424
<label>
2525
Comments:
@@ -52,7 +52,7 @@ describe('LiveController Action Tests', () => {
5252
);
5353

5454
// ONLY a post is sent, not a re-render GET
55-
const postMock = fetchMock.postOnce('http://localhost/components/my_component/save', {
55+
const postMock = fetchMock.postOnce('http://localhost/_components/my_component/save', {
5656
html: template({ comments: 'hi weaver', isSaved: true }),
5757
data: { comments: 'hi weaver', isSaved: true }
5858
});

src/LiveComponent/assets/test/controller/csrf.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('LiveController CSRF Tests', () => {
1818
const template = (data) => `
1919
<div
2020
data-controller="live"
21-
data-live-url-value="http://localhost/components/my_component"
21+
data-live-url-value="http://localhost/_components/my_component"
2222
data-live-csrf-value="123TOKEN"
2323
>
2424
<label>
@@ -51,7 +51,7 @@ describe('LiveController CSRF Tests', () => {
5151
data
5252
);
5353

54-
const postMock = fetchMock.postOnce('http://localhost/components/my_component/save', {
54+
const postMock = fetchMock.postOnce('http://localhost/_components/my_component/save', {
5555
html: template({ comments: 'hi', isSaved: true }),
5656
data: { comments: 'hi', isSaved: true }
5757
});

src/LiveComponent/assets/test/controller/render.test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('LiveController rendering Tests', () => {
1919
const template = (data, includeLoading = false) => `
2020
<div
2121
data-controller="live"
22-
data-live-url-value="http://localhost/components/my_component"
22+
data-live-url-value="http://localhost/_components/my_component"
2323
>
2424
<!-- form field not mapped with data-model -->
2525
<label>
@@ -51,7 +51,7 @@ describe('LiveController rendering Tests', () => {
5151
data
5252
);
5353

54-
fetchMock.get('http://localhost/components/my_component?name=Ryan', {
54+
fetchMock.get('http://localhost/_components/my_component?name=Ryan', {
5555
html: '<div>aloha!</div>',
5656
data: { name: 'Kevin' }
5757
});
@@ -68,7 +68,7 @@ describe('LiveController rendering Tests', () => {
6868
data
6969
);
7070

71-
fetchMock.get('http://localhost/components/my_component?name=Ryan', {
71+
fetchMock.get('http://localhost/_components/my_component?name=Ryan', {
7272
html: template({ name: 'Kevin' }),
7373
data: { name: 'Kevin' }
7474
}, {
@@ -92,7 +92,7 @@ describe('LiveController rendering Tests', () => {
9292
data
9393
);
9494

95-
fetchMock.get('http://localhost/components/my_component?name=Ryan', {
95+
fetchMock.get('http://localhost/_components/my_component?name=Ryan', {
9696
html: template({ name: 'Kevin' }, true),
9797
data: { name: 'Kevin' }
9898
}, {
@@ -111,7 +111,7 @@ describe('LiveController rendering Tests', () => {
111111
return `
112112
<div
113113
data-controller="live"
114-
data-live-url-value="http://localhost/components/parent"
114+
data-live-url-value="http://localhost/_components/parent"
115115
>
116116
Title: ${data.title}
117117
@@ -135,7 +135,7 @@ describe('LiveController rendering Tests', () => {
135135
element.querySelector('[data-controller="live"]').dataset.liveDataValue = JSON.stringify(childData);
136136

137137
// child re-render: render with new name & an error class
138-
fetchMock.get('http://localhost/components/my_component?name=Ryan', {
138+
fetchMock.get('http://localhost/_components/my_component?name=Ryan', {
139139
html: template({ name: 'Kevin', hasError: true }),
140140
data: { name: 'Kevin', hasError: true }
141141
});
@@ -145,7 +145,7 @@ describe('LiveController rendering Tests', () => {
145145
await waitFor(() => expect(element).toHaveTextContent('Name: Kevin'));
146146

147147
// reload the parent template
148-
fetchMock.get('http://localhost/components/parent?title=Parent+component', {
148+
fetchMock.get('http://localhost/_components/parent?title=Parent+component', {
149149
html: parentTemplate({ title: 'Changed parent' }, { name: 'changed name'}),
150150
data: { title: 'Changed parent'}
151151
});
@@ -163,7 +163,7 @@ describe('LiveController rendering Tests', () => {
163163
data
164164
);
165165

166-
fetchMock.get('http://localhost/components/my_component?name=Ryan', {
166+
fetchMock.get('http://localhost/_components/my_component?name=Ryan', {
167167
html: '<div>aloha!</div>',
168168
data: { name: 'Kevin' }
169169
}, {

src/LiveComponent/src/Resources/config/routing/live_component.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
55
xsi:schemaLocation="http://symfony.com/schema/routing https://symfony.com/schema/routing/routing-1.0.xsd">
66

7-
<route id="live_component" path="/components/{component}/{action}">
7+
<route id="live_component" path="/_components/{component}/{action}">
88
<default key="action">get</default>
99
</route>
1010
</routes>

src/LiveComponent/tests/Functional/EventListener/LiveComponentSubscriberTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ public function can_render_component_as_html_or_json(): void
5555

5656
$this->browser()
5757
->throwExceptions()
58-
->get('/components/component1?'.http_build_query($dehydrated))
58+
->get('/_components/component1?'.http_build_query($dehydrated))
5959
->assertSuccessful()
6060
->assertHeaderContains('Content-Type', 'html')
6161
->assertContains('Prop1: '.$entity->id)
6262
->assertContains('Prop2: 2021-03-05 9:23')
6363
->assertContains('Prop3: value3')
6464
->assertContains('Prop4: (none)')
6565

66-
->get('/components/component1?'.http_build_query($dehydrated), ['headers' => ['Accept' => 'application/vnd.live-component+json']])
66+
->get('/_components/component1?'.http_build_query($dehydrated), ['headers' => ['Accept' => 'application/vnd.live-component+json']])
6767
->assertSuccessful()
6868
->assertHeaderEquals('Content-Type', 'application/vnd.live-component+json')
6969
->assertJsonMatches('keys(@)', ['html', 'data'])
@@ -99,26 +99,26 @@ public function can_execute_component_action(): void
9999

100100
$this->browser()
101101
->throwExceptions()
102-
->get('/components/component2?'.http_build_query($dehydrated))
102+
->get('/_components/component2?'.http_build_query($dehydrated))
103103
->assertSuccessful()
104104
->assertHeaderContains('Content-Type', 'html')
105105
->assertContains('Count: 1')
106106
->use(function(HtmlResponse $response) use (&$token) {
107107
// get a valid token to use for actions
108108
$token = $response->crawler()->filter('div')->first()->attr('data-live-csrf-value');
109109
})
110-
->post('/components/component2/increase?'.http_build_query($dehydrated), [
110+
->post('/_components/component2/increase?'.http_build_query($dehydrated), [
111111
'headers' => ['X-CSRF-TOKEN' => $token]
112112
])
113113
->assertSuccessful()
114114
->assertHeaderContains('Content-Type', 'html')
115115
->assertContains('Count: 2')
116116

117-
->get('/components/component2?'.http_build_query($dehydrated), ['headers' => ['Accept' => 'application/vnd.live-component+json']])
117+
->get('/_components/component2?'.http_build_query($dehydrated), ['headers' => ['Accept' => 'application/vnd.live-component+json']])
118118
->assertSuccessful()
119119
->assertJsonMatches('data.count', 1)
120120
->assertJsonMatches("contains(html, 'Count: 1')", true)
121-
->post('/components/component2/increase?'.http_build_query($dehydrated), [
121+
->post('/_components/component2/increase?'.http_build_query($dehydrated), [
122122
'headers' => [
123123
'Accept' => 'application/vnd.live-component+json',
124124
'X-CSRF-TOKEN' => $token,
@@ -136,7 +136,7 @@ public function can_execute_component_action(): void
136136
public function cannot_execute_component_action_for_get_request(): void
137137
{
138138
$this->browser()
139-
->get('/components/component2/increase')
139+
->get('/_components/component2/increase')
140140
->assertStatus(405)
141141
;
142142
}
@@ -147,7 +147,7 @@ public function cannot_execute_component_action_for_get_request(): void
147147
public function missing_csrf_token_for_component_action_fails(): void
148148
{
149149
$this->browser()
150-
->post('/components/component2/increase')
150+
->post('/_components/component2/increase')
151151
->assertStatus(400)
152152
;
153153
}
@@ -158,7 +158,7 @@ public function missing_csrf_token_for_component_action_fails(): void
158158
public function invalid_csrf_token_for_component_action_fails(): void
159159
{
160160
$this->browser()
161-
->post('/components/component2/increase', [
161+
->post('/_components/component2/increase', [
162162
'headers' => ['X-CSRF-TOKEN' => 'invalid']
163163
])
164164
->assertStatus(400)
@@ -187,7 +187,7 @@ public function before_re_render_hook_only_executed_during_ajax(): void
187187
->visit('/render-template/template1')
188188
->assertSuccessful()
189189
->assertSee('BeforeReRenderCalled: No')
190-
->get('/components/component2?'.http_build_query($dehydrated))
190+
->get('/_components/component2?'.http_build_query($dehydrated))
191191
->assertSuccessful()
192192
->assertSee('BeforeReRenderCalled: Yes')
193193
;
@@ -214,19 +214,19 @@ public function can_redirect_from_component_action(): void
214214

215215
$this->browser()
216216
->throwExceptions()
217-
->get('/components/component2?'.http_build_query($dehydrated))
217+
->get('/_components/component2?'.http_build_query($dehydrated))
218218
->assertSuccessful()
219219
->use(function(HtmlResponse $response) use (&$token) {
220220
// get a valid token to use for actions
221221
$token = $response->crawler()->filter('div')->first()->attr('data-live-csrf-value');
222222
})
223223
->interceptRedirects()
224-
->post('/components/component2/redirect?'.http_build_query($dehydrated), [
224+
->post('/_components/component2/redirect?'.http_build_query($dehydrated), [
225225
'headers' => ['X-CSRF-TOKEN' => $token]
226226
])
227227
->assertRedirectedTo('/')
228228

229-
->post('/components/component2/redirect?'.http_build_query($dehydrated), [
229+
->post('/_components/component2/redirect?'.http_build_query($dehydrated), [
230230
'headers' => [
231231
'Accept' => 'application/json',
232232
'X-CSRF-TOKEN' => $token,

src/LiveComponent/tests/Functional/Twig/LiveComponentExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function init_live_component(): void
3737
$data = \json_decode($div->attr('data-live-data-value'), true);
3838

3939
$this->assertSame('live', $div->attr('data-controller'));
40-
$this->assertSame('/components/component2', $div->attr('data-live-url-value'));
40+
$this->assertSame('/_components/component2', $div->attr('data-live-url-value'));
4141
$this->assertNotNull($div->attr('data-live-csrf-value'));
4242
$this->assertCount(2, $data);
4343
$this->assertSame(1, $data['count']);

0 commit comments

Comments
 (0)