CountryTest.php
3.31 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
namespace Tests\Browser;
use App\Country;
use Tests\Browser\Login\LoginAsAdmin;
use Tests\Browser\Pages\Country\CreatePage;
use Tests\Browser\Pages\Country\DetailPage;
use Tests\Browser\Pages\Country\ListingPage;
use Tests\Browser\Pages\Country\UpdatePage;
use Tests\DuskTestCase;
use Laravel\Dusk\Browser;
class CountryTest extends DuskTestCase
{
use LoginAsAdmin;
/**
* Test country listing.
*
* @return void
*
* @throws \Throwable
*/
public function testCountryListing()
{
$this->browse(function (Browser $browser) {
$browser->login()
->visit(new ListingPage());
});
}
/**
* Test create a country.
*
* @return void
*
* @throws \Throwable
*/
public function testCreateCountry()
{
$country = factory(Country::class)->make();
$this->browse(function (Browser $browser) use ($country) {
$browser->login()
->visit(new CreatePage())
->type('@input-name', $country->name)
->type('@input-ibge', $country->ibge)
->press('@button-save')
->on(new ListingPage());
});
}
/**
* Test update a country.
*
* @return void
*
* @throws \Throwable
*/
public function testUpdateCountry()
{
$country = factory(Country::class)->make();
$this->browse(function (Browser $browser) use ($country) {
$browser->login()
->visit(new UpdatePage(1)) // FIXME ID should be dynamic in the future
->type('@input-name', $country->name)
->type('@input-ibge', $country->ibge)
->press('@button-save')
->on(new ListingPage());
});
}
/**
* Test country flow.
*
* @return void
*
* @throws \Throwable
*/
public function testFlowForCountryPages()
{
$this->browse(function (Browser $browser) {
$country = factory(Country::class)->make();
$countryAfterUpdate = factory(Country::class)->make();
$browser->login();
$browser->visit(new ListingPage())
->press(' Novo ');
$browser->on(new CreatePage())
->type('@input-name', $country->name)
->type('@input-ibge', $country->ibge)
->press('@button-save');
$browser->on(new ListingPage())
->type('@input-name', $country->name)
->press('Buscar');
$browser->on(new ListingPage());
$countryId = $browser->resolver->findByText($country->name, 'a')->getAttribute('data-id');
$browser->clickLink($country->name);
$browser->on(new DetailPage($countryId))
->press(' Editar ');
$browser->on(new UpdatePage($countryId))
->type('@input-name', $countryAfterUpdate->name)
->type('@input-ibge', $countryAfterUpdate->ibge)
->press('@button-save');
$browser->on(new ListingPage())
->type('@input-name', $countryAfterUpdate->name)
->press('Buscar')
->clickLink($countryAfterUpdate->name);
$browser->on(new DetailPage($countryId));
});
}
}