Skip to content

Commit

Permalink
Add Vue 3 Options API & Composition API tests
Browse files Browse the repository at this point in the history
Test Laravel Dusk assertVue() changes.
  • Loading branch information
derekmd committed Mar 24, 2022
1 parent 673ebf9 commit b111b48
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 21 deletions.
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@
"require-dev": {
"fakerphp/faker": "^1.9.1",
"laravel/breeze": "^1.8",
"laravel/dusk": "^6.22",
"laravel/dusk": "dev-vue-3-composition-api as 6.22",
"laravel/sail": "^1.0.1",
"mockery/mockery": "^1.4.4",
"nunomaduro/collision": "^6.1",
"phpunit/phpunit": "^9.5.10",
"spatie/laravel-ignition": "^1.0"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/derekmd/dusk"
}
],
"autoload": {
"psr-4": {
"App\\": "app/",
Expand Down
36 changes: 24 additions & 12 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion resources/js/Pages/Auth/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import BreezeInput from '@/Components/Input.vue';
import BreezeLabel from '@/Components/Label.vue';
import BreezeValidationErrors from '@/Components/ValidationErrors.vue';
import { Head, Link, useForm } from '@inertiajs/inertia-vue3';
import { computed } from 'vue'
defineProps({
const props = defineProps({
canResetPassword: Boolean,
status: String,
});
Expand All @@ -23,9 +24,12 @@ const submit = () => {
onFinish: () => form.reset('password'),
});
};
const cantResetPassword = computed(() => ! props.canResetPassword);
</script>

<template>
<div dusk="login">
<BreezeGuestLayout>
<Head title="Log in" />

Expand Down Expand Up @@ -64,4 +68,5 @@ const submit = () => {
</div>
</form>
</BreezeGuestLayout>
</div>
</template>
42 changes: 35 additions & 7 deletions resources/js/Pages/Welcome.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,42 @@
<script setup>
<script>
// Vue 3 Options API
import { Head, Link } from '@inertiajs/inertia-vue3';
defineProps({
canLogin: Boolean,
canRegister: Boolean,
laravelVersion: String,
phpVersion: String,
})
export default {
components: {
Head,
Link,
},
props: {
canLogin: Boolean,
canRegister: Boolean,
laravelVersion: String,
phpVersion: String,
},
computed: {
cantLogin() {
return ! this.canLogin;
}
}
}
// Vue 3 composition API
//
// <script setup>
// import { Head, Link } from '@inertiajs/inertia-vue3';
// defineProps({
// canLogin: Boolean,
// canRegister: Boolean,
// laravelVersion: String,
// phpVersion: String,
// })
</script>

<template>
<div dusk="homepage">
<Head title="Welcome" />

<div class="relative flex items-top justify-center min-h-screen bg-gray-100 dark:bg-gray-900 sm:items-center sm:pt-0">
Expand Down Expand Up @@ -121,6 +148,7 @@ defineProps({
</div>
</div>
</div>
</div>
</template>

<style scoped>
Expand Down
20 changes: 20 additions & 0 deletions tests/Browser/HomepageTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Tests\Browser;

use Illuminate\Foundation\Testing\DatabaseMigrations;
use Laravel\Dusk\Browser;
use Tests\DuskTestCase;

class HomepageTest extends DuskTestCase
{
public function testGuest()
{
$this->browse(function (Browser $browser) {
$browser->visit('/')
->assertSee('Laravel')
->assertVue('canLogin', true, '@homepage')
->assertVue('cantLogin', false, '@homepage');
});
}
}
23 changes: 23 additions & 0 deletions tests/Browser/LoginTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Tests\Browser;

use Illuminate\Foundation\Testing\DatabaseMigrations;
use Laravel\Dusk\Browser;
use Tests\DuskTestCase;

class LoginTest extends DuskTestCase
{
public function testEmailTyping()
{
$this->browse(function (Browser $browser) {
$browser->visit('/login')
->assertSee('Email')
->assertSee('Password')
->type('#email', 'foo@bar.com')
->assertVue('canResetPassword', true, '@login') // prop
->assertVue('cantResetPassword', false, '@login') // computed prop
->assertVue('form.email', 'foo@bar.com', '@login'); // reactive data
});
}
}

0 comments on commit b111b48

Please sign in to comment.