|
1 | 1 | <?php |
2 | 2 |
|
| 3 | +use Illuminate\Support\Traits\Macroable; |
| 4 | +use Illuminate\Testing\TestComponent; |
3 | 5 | use PHPUnit\Framework\AssertionFailedError; |
4 | 6 | use Sinnbeck\DomAssertions\Asserts\AssertElement; |
5 | 7 | use Tests\Views\Components\BrokenComponent; |
|
9 | 11 | use Tests\Views\Components\LivewireComponent; |
10 | 12 | use Tests\Views\Components\NestedComponent; |
11 | 13 |
|
| 14 | +$testComponentMacroable = in_array(Macroable::class, class_uses(TestComponent::class) ?? []); |
| 15 | +$testComponentMacroableMsg = 'Testing Blade components is unavailable in this version of Laravel'; |
| 16 | + |
12 | 17 | it('can handle an empty component', function () { |
13 | 18 | $this->component(EmptyComponent::class) |
14 | 19 | ->assertElementExists(); |
15 | 20 | })->throws( |
16 | 21 | AssertionFailedError::class, |
17 | 22 | 'The component is empty!' |
18 | | -); |
| 23 | +)->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
19 | 24 |
|
20 | 25 | it('can handle an empty body', function () { |
21 | 26 | $this->component(EmptyBodyComponent::class) |
22 | 27 | ->assertElementExists(); |
23 | 28 | })->throws( |
24 | 29 | AssertionFailedError::class, |
25 | 30 | 'No element found with selector: body' |
26 | | -); |
| 31 | +)->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
27 | 32 |
|
28 | 33 | it('can parse broken html', function () { |
29 | 34 | $this->component(BrokenComponent::class) |
30 | 35 | ->assertElementExists(); |
31 | | -}); |
| 36 | +})->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
32 | 37 |
|
33 | 38 | it('can find the element', function () { |
34 | 39 | $this->component(NestedComponent::class) |
35 | 40 | ->assertElementExists(); |
36 | | -}); |
| 41 | +})->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
37 | 42 |
|
38 | 43 | it('can find the body', function () { |
39 | 44 | $this->component(NestedComponent::class) |
40 | 45 | ->assertElementExists('body', function (AssertElement $assert) { |
41 | 46 | $assert->is('body'); |
42 | 47 | }); |
43 | | -}); |
| 48 | +})->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
44 | 49 |
|
45 | 50 | it('can check for html5', function () { |
46 | 51 | $this->component(Html5Component::class) |
47 | 52 | ->assertHtml5(); |
48 | | -}); |
| 53 | +})->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
49 | 54 |
|
50 | 55 | it('can fail checking for html5', function () { |
51 | 56 | $this->component(NestedComponent::class) |
52 | 57 | ->assertHtml5(); |
53 | 58 | })->throws( |
54 | 59 | AssertionFailedError::class, |
55 | 60 | 'Not a html5 doctype!' |
56 | | -); |
| 61 | +)->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
57 | 62 |
|
58 | 63 | it('can fail finding a class', function () { |
59 | 64 | $this->component(Html5Component::class) |
|
62 | 67 | $element->doesntHave('class'); |
63 | 68 | }); |
64 | 69 | }); |
65 | | -}); |
| 70 | +})->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
66 | 71 |
|
67 | 72 | it('can fail finding a href with exact match', function () { |
68 | 73 | $this->component(Html5Component::class) |
|
72 | 77 | ->doesntHave('href', '/bar'); |
73 | 78 | }); |
74 | 79 | }); |
75 | | -}); |
| 80 | +})->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
76 | 81 |
|
77 | 82 | it('can fail when finding a id that isnt expected', function () { |
78 | 83 | $this->component(Html5Component::class) |
|
84 | 89 | })->throws( |
85 | 90 | AssertionFailedError::class, |
86 | 91 | 'Found an attribute "id"' |
87 | | -); |
| 92 | +)->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
88 | 93 |
|
89 | 94 | it('can fail when finding a href with matching value that isnt expected', function () { |
90 | 95 | $this->component(Html5Component::class) |
|
96 | 101 | })->throws( |
97 | 102 | AssertionFailedError::class, |
98 | 103 | 'Found an attribute "href" with value "/foo"' |
99 | | -); |
| 104 | +)->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
100 | 105 |
|
101 | 106 | it('can find an element by selector', function () { |
102 | 107 | $this->component(Html5Component::class) |
103 | 108 | ->assertElementExists('#nav'); |
104 | | -}); |
| 109 | +})->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
105 | 110 |
|
106 | 111 | it('can fail finding anything', function () { |
107 | 112 | $this->component(Html5Component::class) |
108 | 113 | ->assertElementExists('div > nav'); |
109 | 114 | })->throws( |
110 | 115 | AssertionFailedError::class, |
111 | 116 | 'No element found with selector: div > nav' |
112 | | -); |
| 117 | +)->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
113 | 118 |
|
114 | 119 | it('can check the element has the correct type', function () { |
115 | 120 | $this->component(Html5Component::class) |
116 | 121 | ->assertElementExists('#nav', function (AssertElement $element) { |
117 | 122 | $element->is('nav'); |
118 | 123 | }); |
119 | | -}); |
| 124 | +})->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
120 | 125 |
|
121 | 126 | it('can fail matching element type', function () { |
122 | 127 | $this->component(Html5Component::class) |
|
126 | 131 | })->throws( |
127 | 132 | AssertionFailedError::class, |
128 | 133 | 'Element is not of type "div"' |
129 | | -); |
| 134 | +)->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
130 | 135 |
|
131 | 136 | it('can fail with wrong type of selector', function () { |
132 | 137 | $this->view('form') |
133 | 138 | ->assertElementExists(['div']); |
134 | | -})->throws(AssertionFailedError::class, 'Invalid selector!'); |
| 139 | +})->throws( |
| 140 | + AssertionFailedError::class, |
| 141 | + 'Invalid selector!' |
| 142 | +)->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
135 | 143 |
|
136 | 144 | it('can find a nested element', function () { |
137 | 145 | $this->component(Html5Component::class) |
138 | 146 | ->assertElementExists(function (AssertElement $element) { |
139 | 147 | $element->containsDiv(); |
140 | 148 | }); |
141 | | -}); |
| 149 | +})->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
142 | 150 |
|
143 | 151 | it('can find a nested element with content', function () { |
144 | 152 | $this->component(Html5Component::class) |
|
147 | 155 | 'class' => 'foobar', |
148 | 156 | ]); |
149 | 157 | }); |
150 | | -}); |
| 158 | +})->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
151 | 159 |
|
152 | 160 | it('can match text content', function () { |
153 | 161 | $this->component(Html5Component::class) |
154 | 162 | ->assertElementExists('span.bar', function (AssertElement $element) { |
155 | 163 | $element->has('text', 'Foo'); |
156 | 164 | }); |
157 | | -}); |
| 165 | +})->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
158 | 166 |
|
159 | 167 | it('can match text content with duplicate spaces and vertical whitespace', function () { |
160 | 168 | $this->component(Html5Component::class) |
161 | 169 | ->assertElementExists('p.foo.bar', function (AssertElement $element) { |
162 | 170 | $element->has('text', 'Foo Bar'); |
163 | 171 | }); |
164 | | -}); |
| 172 | +})->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
165 | 173 |
|
166 | 174 | it('can match text content containing a string', function () { |
167 | 175 | $this->component(Html5Component::class) |
168 | 176 | ->assertElementExists('p.foo.bar', function (AssertElement $element) { |
169 | 177 | $element->containsText('Bar'); |
170 | 178 | }); |
171 | | -}); |
| 179 | +})->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
172 | 180 |
|
173 | 181 | it('can match text content containing a string ignoring case', function () { |
174 | 182 | $this->component(Html5Component::class) |
175 | 183 | ->assertElementExists('p.foo.bar', function (AssertElement $element) { |
176 | 184 | $element->containsText('bar', true); |
177 | 185 | }); |
178 | | -}); |
| 186 | +})->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
179 | 187 |
|
180 | 188 | it('can match text content not containing a string', function () { |
181 | 189 | $this->component(Html5Component::class) |
182 | 190 | ->assertElementExists('p.foo.bar', function (AssertElement $element) { |
183 | 191 | $element->doesntContainText('bar'); |
184 | 192 | }); |
185 | | -}); |
| 193 | +})->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
186 | 194 |
|
187 | 195 | it('can match a class no matter the order', function () { |
188 | 196 | $this->component(Html5Component::class) |
|
194 | 202 | $span->has('class', 'foo bar'); |
195 | 203 | }); |
196 | 204 | }); |
197 | | -}); |
| 205 | +})->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
198 | 206 |
|
199 | 207 | it('can match a partial class', function () { |
200 | 208 | $this->component(Html5Component::class) |
|
206 | 214 | $span->has('class', 'bar'); |
207 | 215 | }); |
208 | 216 | }); |
209 | | -}); |
| 217 | +})->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
210 | 218 |
|
211 | 219 | it('can find multiple identical items', function () { |
212 | 220 | $this->component(Html5Component::class) |
213 | 221 | ->assertElementExists(function (AssertElement $element) { |
214 | 222 | $element->contains('div', [], 4); |
215 | 223 | }); |
216 | | -}); |
| 224 | +})->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
217 | 225 |
|
218 | 226 | it('can find multiple identical items simplified', function () { |
219 | 227 | $this->component(Html5Component::class) |
220 | 228 | ->assertElementExists(function (AssertElement $element) { |
221 | 229 | $element->contains('div', 4); |
222 | 230 | }); |
223 | | -}); |
| 231 | +})->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
224 | 232 |
|
225 | 233 | it('can find multiple identical items with content', function () { |
226 | 234 | $this->component(Html5Component::class) |
|
229 | 237 | 'x-data' => 'foobar', |
230 | 238 | ], 2); |
231 | 239 | }); |
232 | | -}); |
| 240 | +})->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
233 | 241 |
|
234 | 242 | it('can find multiple identical items with content ensuring no wrong matches', function () { |
235 | 243 | $this->component(Html5Component::class) |
|
238 | 246 | 'x-data' => 'foobar', |
239 | 247 | ], 1); |
240 | 248 | }); |
241 | | -}); |
| 249 | +})->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
242 | 250 |
|
243 | 251 | it('can fail finding a nested element with content', function () { |
244 | 252 | $this->component(Html5Component::class) |
|
247 | 255 | 'class' => 'foo', |
248 | 256 | ]); |
249 | 257 | }); |
250 | | -})->throws(AssertionFailedError::class, 'Could not find a matching "div" with data:'); |
| 258 | +})->throws( |
| 259 | + AssertionFailedError::class, |
| 260 | + 'Could not find a matching "div" with data:' |
| 261 | +)->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
251 | 262 |
|
252 | 263 | it('can find a nested element with content functional', function () { |
253 | 264 | $this->component(Html5Component::class) |
|
256 | 267 | $element->is('div'); |
257 | 268 | }); |
258 | 269 | }); |
259 | | -}); |
| 270 | +})->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
260 | 271 |
|
261 | 272 | it('can find a nested element multiple levels', function () { |
262 | 273 | $this->component(Html5Component::class) |
|
271 | 282 | }); |
272 | 283 | }); |
273 | 284 | }); |
274 | | -}); |
| 285 | +})->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
275 | 286 |
|
276 | 287 | it('can find a nested element multiple levels by query', function () { |
277 | 288 | $this->component(Html5Component::class) |
|
286 | 297 | }); |
287 | 298 | }); |
288 | 299 | }); |
289 | | -}); |
| 300 | +})->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
290 | 301 |
|
291 | 302 | it('can find a nested element multiple levels by query and attributes', function () { |
292 | 303 | $this->component(Html5Component::class) |
|
298 | 309 | ]); |
299 | 310 | }); |
300 | 311 | }); |
301 | | -}); |
| 312 | +})->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
302 | 313 |
|
303 | 314 | it('can find a nested element and ensure doesnt contain', function () { |
304 | 315 | $this->component(Html5Component::class) |
|
308 | 319 | $element->doesntContain('nav'); |
309 | 320 | }); |
310 | 321 | }); |
311 | | -}); |
| 322 | +})->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
312 | 323 |
|
313 | 324 | it('can fail finding an contained element', function () { |
314 | 325 | $this->component(Html5Component::class) |
|
320 | 331 | })->throws( |
321 | 332 | AssertionFailedError::class, |
322 | 333 | 'Found a matching element of type "div' |
323 | | -); |
| 334 | +)->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
324 | 335 |
|
325 | 336 | it('can fail finding an contained element with query', function () { |
326 | 337 | $this->component(Html5Component::class) |
|
332 | 343 | })->throws( |
333 | 344 | AssertionFailedError::class, |
334 | 345 | 'Found a matching element of type "div' |
335 | | -); |
| 346 | +)->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
336 | 347 |
|
337 | 348 | it('can match on livewire attributes', function () { |
338 | 349 | $this->component(LivewireComponent::class) |
339 | 350 | ->assertElementExists('[wire\:model="foo"]', function (AssertElement $element) { |
340 | 351 | $element->is('input'); |
341 | 352 | }); |
342 | | -}); |
| 353 | +})->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
343 | 354 |
|
344 | 355 | it('can match has on livewire attributes', function () { |
345 | 356 | $this->component(LivewireComponent::class) |
346 | 357 | ->assertElementExists('input', function (AssertElement $element) { |
347 | 358 | $element->has('wire:model', 'foo'); |
348 | 359 | }); |
349 | | -}); |
| 360 | +})->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
350 | 361 |
|
351 | 362 | it('can match on livewire with contains', function () { |
352 | 363 | $this->component(LivewireComponent::class) |
353 | 364 | ->assertElementExists(function (AssertElement $element) { |
354 | 365 | $element->contains('input[wire\:model="foo"]'); |
355 | 366 | }); |
356 | | -}); |
| 367 | +})->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
357 | 368 |
|
358 | 369 | it('can match on livewire contains as attribute', function () { |
359 | 370 | $this->component(LivewireComponent::class) |
|
362 | 373 | 'wire:model' => 'foo', |
363 | 374 | ]); |
364 | 375 | }); |
365 | | -}); |
| 376 | +})->skip(! $testComponentMacroable, $testComponentMacroableMsg); |
0 commit comments