-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
AttachmentTest.php
98 lines (85 loc) · 2.97 KB
/
AttachmentTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
namespace Tests\Browser;
use App\Models\FormSubmission;
use Laravel\Dusk\Browser;
use Tests\DuskTestCase;
class AttachmentTest extends DuskTestCase
{
public function setUp(): void
{
parent::setUp();
FormSubmission::truncate();
}
/**
* @test
*
* @dataProvider routeNames
*/
public function it_can_handle_a_single_upload(string $routeName)
{
$this->browse(function (Browser $browser) use ($routeName) {
$browser
->visit(route($routeName))
->type('name', 'My name')
->attach('@main-uploader', $this->getStubPath('space.png'))
->waitForText('Remove')
->waitUntilMissing('.media-library-progress-wrap.media-library-progress-wrap-loading')
->press('@submit')
->assertSee('Your form has been submitted');
$this->assertCount(1, FormSubmission::get());
$this->assertEquals('space.png', FormSubmission::first()->getFirstMedia('images')->file_name);
});
}
/**
* @test
*
* @dataProvider routeNames
*/
public function it_will_not_lose_the_uploaded_file_when_submitting_a_form_results_in_validation_errors(string $routeName)
{
$this->browse(function (Browser $browser) use ($routeName) {
$browser
->visit(route($routeName))
->attach('@main-uploader', $this->getStubPath('space.png'))
->waitForText('Remove')
->waitUntilMissing('.media-library-progress-wrap.media-library-progress-wrap-loading')
->press('@submit');
$this->assertCount(0, FormSubmission::all());
$browser
->assertSee('Please correct the errors in the form')
->waitForText('KB')
->assertVisible('@thumb')
->type('name', 'My name failing test')
->press('@submit')
->assertSee('Your form has been submitted');
$this->assertCount(1, FormSubmission::all());
$this->assertEquals('space.png', FormSubmission::first()->getFirstMedia('images')->file_name);
});
}
/**
* @test
*
* @dataProvider routeNames
*/
public function it_can_show_a_validation_error_on_replacement(string $routeName)
{
$this->browse(function (Browser $browser) use ($routeName) {
$browser
->visit(route($routeName))
->type('name', 'My name')
->attach('@main-uploader', $this->getStubPath('space.png'))
->pause(800)
->attach('@uploader', $this->getStubPath('data.json'))
->pause(200)
->assertSee('You must upload a file of type');
});
}
public function routeNames(): array
{
return [
['vue.attachment'],
['react.attachment'],
['blade.attachment'],
];
}
}