From 03f1295194fa74d2c03220307caedaf6bf5ee975 Mon Sep 17 00:00:00 2001 From: EwelinaLasowy Date: Mon, 14 Mar 2022 14:24:22 +0100 Subject: [PATCH] #17 - Laravel Dusk tests --- .env.dusk.local | 4 +- .../Providers/DuskServiceProvider.php | 24 ++++++ composer.json | 6 +- composer.lock | 4 +- config/app.php | 1 + package-lock.json | 2 +- resources/js/Pages/VacationRequest/Create.vue | 12 ++- resources/js/Pages/VacationRequest/Index.vue | 1 + resources/js/Shared/MainMenu.vue | 13 +-- tests/Browser/AuthenticationTest.php | 39 --------- tests/Browser/VacationRequestTest.php | 84 +++++++++++++++++++ tests/Browser/console/.gitignore | 2 + 12 files changed, 135 insertions(+), 57 deletions(-) create mode 100644 app/Architecture/Providers/DuskServiceProvider.php delete mode 100644 tests/Browser/AuthenticationTest.php create mode 100644 tests/Browser/VacationRequestTest.php create mode 100644 tests/Browser/console/.gitignore diff --git a/.env.dusk.local b/.env.dusk.local index 48c004f..02f1317 100644 --- a/.env.dusk.local +++ b/.env.dusk.local @@ -19,8 +19,8 @@ DB_PASSWORD=password BROADCAST_DRIVER=log CACHE_DRIVER=array -QUEUE_CONNECTION=redis -SESSION_DRIVER=redis +QUEUE_CONNECTION=sync +SESSION_DRIVER=file SESSION_LIFETIME=120 FILESYSTEM_DISK=local MAIL_MAILER=array diff --git a/app/Architecture/Providers/DuskServiceProvider.php b/app/Architecture/Providers/DuskServiceProvider.php new file mode 100644 index 0000000..6e0d42f --- /dev/null +++ b/app/Architecture/Providers/DuskServiceProvider.php @@ -0,0 +1,24 @@ +select("div.flatpickr-calendar > div.flatpickr-months select", $month - 1); + return $this; + }); + + Browser::macro("fillDay", function ($day) { + $this->click("div.flatpickr-calendar.animate.arrowTop.arrowLeft.open > div.flatpickr-innerContainer > div > div.flatpickr-days > div > span:nth-child({$day})"); + return $this; + }); + } +} diff --git a/composer.json b/composer.json index 0238916..ad7bbb5 100644 --- a/composer.json +++ b/composer.json @@ -24,12 +24,12 @@ }, "require-dev": { "blumilksoftware/codestyle": "^0.10.0", - "spatie/laravel-ignition": "^1.0", "fakerphp/faker": "^1.9.1", - "laravel/dusk": "^6.21", + "laravel/dusk": "^6.22", "mockery/mockery": "^1.4.4", "nunomaduro/collision": "^6.1", - "phpunit/phpunit": "^9.5.10" + "phpunit/phpunit": "^9.5.10", + "spatie/laravel-ignition": "^1.0" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 6f6abe7..3a6f4a6 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "937eef6310bd4bb12f1d0ccb623946d1", + "content-hash": "9dcd821442cec43ff77ef5045cd041c8", "packages": [ { "name": "asm89/stack-cors", @@ -10986,5 +10986,5 @@ "ext-pdo": "*" }, "platform-dev": [], - "plugin-api-version": "2.1.0" + "plugin-api-version": "2.2.0" } diff --git a/config/app.php b/config/app.php index a5d12a9..3a7ca30 100644 --- a/config/app.php +++ b/config/app.php @@ -44,5 +44,6 @@ return [ Toby\Architecture\Providers\TelescopeServiceProvider::class, Toby\Architecture\Providers\ObserverServiceProvider::class, Barryvdh\DomPDF\ServiceProvider::class, + Toby\Architecture\Providers\DuskServiceProvider::class, ], ]; diff --git a/package-lock.json b/package-lock.json index eb8a495..84ee482 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "toby", + "name": "application", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/resources/js/Pages/VacationRequest/Create.vue b/resources/js/Pages/VacationRequest/Create.vue index e0139d5..23f9675 100644 --- a/resources/js/Pages/VacationRequest/Create.vue +++ b/resources/js/Pages/VacationRequest/Create.vue @@ -121,7 +121,7 @@ >
-
+
{{ auth.user.name }}
@@ -139,6 +139,7 @@
{{ form.type.label }} @@ -154,6 +155,7 @@ >
  • {{ type.label }} @@ -194,7 +196,7 @@ > Planowany urlop od -
    +
    -
    +
    @@ -296,6 +299,7 @@ type="submit" :disabled="form.processing" class="inline-flex justify-center py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-blumilk-600 hover:bg-blumilk-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blumilk-500" + dusk="save-button" > Zapisz diff --git a/resources/js/Pages/VacationRequest/Index.vue b/resources/js/Pages/VacationRequest/Index.vue index 600dec2..a91cc7e 100644 --- a/resources/js/Pages/VacationRequest/Index.vue +++ b/resources/js/Pages/VacationRequest/Index.vue @@ -11,6 +11,7 @@ Dodaj wniosek diff --git a/resources/js/Shared/MainMenu.vue b/resources/js/Shared/MainMenu.vue index 5bd78cf..eb03cf0 100644 --- a/resources/js/Shared/MainMenu.vue +++ b/resources/js/Shared/MainMenu.vue @@ -119,6 +119,7 @@ v-for="item in navigation" :key="item.name" :href="item.href" + :dusk="item.dusk" :class="[$page.url === item.href ? 'bg-blumilk-800 text-white' : 'text-blumilk-100 hover:text-white hover:bg-blumilk-600', 'group flex items-center px-2 py-2 text-sm leading-6 font-medium rounded-md']" > [ - {name: 'Moje wnioski', href: '/vacation-requests/me', icon: DocumentTextIcon, can: true}, - {name: 'Wnioski urlopowe', href: '/vacation-requests', icon: CollectionIcon, can: auth.value.can.listAllVacationRequests}, - {name: 'Kalendarz urlopów', href: '/vacation-calendar', icon: CalendarIcon, can: true}, - {name: 'Dni wolne', href: '/holidays', icon: StarIcon, can: true}, - {name: 'Limity urlopów', href: '/vacation-limits', icon: SunIcon, can: auth.value.can.manageVacationLimits}, - {name: 'Użytkownicy', href: '/users', icon: UserGroupIcon, can: auth.value.can.manageUsers}, + {name: 'Moje wnioski', href: '/vacation-requests/me', icon: DocumentTextIcon, can: true, dusk: 'my-vacation-requests-menu-item'}, + {name: 'Wnioski urlopowe', href: '/vacation-requests', icon: CollectionIcon, can: auth.value.can.listAllVacationRequests, dusk: 'vacation-requests-menu-item'}, + {name: 'Kalendarz urlopów', href: '/vacation-calendar', icon: CalendarIcon, can: true, dusk: 'vacation-calendar-menu-item'}, + {name: 'Dni wolne', href: '/holidays', icon: StarIcon, can: true, dusk: 'holidays-menu-item'}, + {name: 'Limity urlopów', href: '/vacation-limits', icon: SunIcon, can: auth.value.can.manageVacationLimits, dusk: 'vacation-limits-menu-item'}, + {name: 'Użytkownicy', href: '/users', icon: UserGroupIcon, can: auth.value.can.manageUsers, dusk: 'users-menu-item'}, ].filter(item => item.can)) const userNavigation = [ diff --git a/tests/Browser/AuthenticationTest.php b/tests/Browser/AuthenticationTest.php deleted file mode 100644 index 49799b4..0000000 --- a/tests/Browser/AuthenticationTest.php +++ /dev/null @@ -1,39 +0,0 @@ -user = User::factory()->create(); - } - - public function testUserCanLogout(): void - { - $this->browse(function (Browser $browser): void { - $browser->loginAs($this->user) - ->visit(new HomePage()) - ->assertVisible("@user-menu") - ->click("@user-menu") - ->assertVisible("@user-menu-list") - ->assertSee("Sign out") - ->press("Sign out") - ->on(new HomePage()) - ->waitFor("@login-link"); - }); - } -} diff --git a/tests/Browser/VacationRequestTest.php b/tests/Browser/VacationRequestTest.php new file mode 100644 index 0000000..76f2bcd --- /dev/null +++ b/tests/Browser/VacationRequestTest.php @@ -0,0 +1,84 @@ +createCurrentYearPeriod(); + + $currentYearPeriod = YearPeriod::query()->where("year", 2022)->first(); + + $this->employee = User::factory([ + "first_name" => "Jan", + "last_name" => "Kowalski", + "email" => env("LOCAL_EMAIL_FOR_LOGIN_VIA_GOOGLE"), + "employment_form" => EmploymentForm::EmploymentContract, + "position" => "programista", + "role" => Role::Employee, + "employment_date" => Carbon::createFromDate(2022, 01, 03), + "remember_token" => Str::random(10), + ]) + ->create(); + + + VacationLimit::factory([ + "days" => 26, + ]) + ->for($currentYearPeriod) + ->for($this->employee) + ->create(); + } + + public function testUserCanCreateVacationRequest(): void + { + $this->browse(function (Browser $browser): void { + $browser->loginAs($this->employee) + ->visit(new HomePage()) + ->click("@my-vacation-requests-menu-item") + ->waitForLocation("/vacation-requests/me") + ->click("@create-vacation-request-button") + ->waitForLocation("/vacation-requests/create") + ->assertSeeIn("@name-input", $this->employee->fullName) + ->click("@type-select") + ->assertVisible("@type-options") + ->click("@vacation") + ->click("@date-from-input") + ->fillMonth("2") + ->fillDay("22") +// ->clickAndWaitForReload("@save-button"); + ->press("Zapisz"); + +// ->waitForLocation("/vacation-requests/1") +// ->screenshot("xd") +// ; + }); + $vacationRequest = VacationRequest::query()->first(); + dd($vacationRequest); + + } +} diff --git a/tests/Browser/console/.gitignore b/tests/Browser/console/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/tests/Browser/console/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore