Skip to content

Commit

Permalink
Merge branch 'master' into improve-aria-describedby
Browse files Browse the repository at this point in the history
  • Loading branch information
erik-epineer authored May 7, 2020
2 parents 1529dfb + c3c2ed5 commit a641b3b
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 3 deletions.
2 changes: 1 addition & 1 deletion resources/views/auth/login.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<header>{{ __('Login') }}</header>
<form method="POST" action="{{ route('kontour.login') }}">
@csrf
@include('kontour::forms.input', ['name' => 'email', 'type' => 'email', 'controlAttributes' => ['required', 'autocomplete' => 'email']])
@include('kontour::forms.email', ['controlAttributes' => ['required']])
@include('kontour::forms.input', ['name' => 'password', 'type' => 'password', 'controlAttributes' => ['required', 'autocomplete' => 'current-password']])
@include('kontour::forms.checkbox', ['name' => 'remember', 'label' => __('Remember Me')])
@component('kontour::buttons.generic')
Expand Down
2 changes: 1 addition & 1 deletion resources/views/auth/passwords/email.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<form method="POST" action="{{ route('kontour.password.email') }}">
@csrf
@include('kontour::forms.input', ['name' => 'email', 'type' => 'email', 'controlAttributes' => ['required', 'autocomplete' => 'email']])
@include('kontour::forms.email', ['controlAttributes' => ['required']])
@component('kontour::buttons.generic')
{{ __('Send Password Reset Link') }}
@endcomponent
Expand Down
2 changes: 1 addition & 1 deletion resources/views/auth/passwords/reset.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<form method="POST" action="{{ route('kontour.password.request') }}">
@csrf
<input type="hidden" name="token" value="{{ $token }}">
@include('kontour::forms.input', ['name' => 'email', 'type' => 'email', 'controlAttributes' => ['required', 'autocomplete' => 'email']])
@include('kontour::forms.email', ['controlAttributes' => ['required']])
@include('kontour::forms.input', ['name' => 'password', 'type' => 'password', 'controlAttributes' => ['required', 'autocomplete' => 'new-password']])
@include('kontour::forms.input', ['name' => 'password_confirmation', 'type' => 'password', 'controlAttributes' => ['required', 'autocomplete' => 'new-password']])
@component('kontour::buttons.generic')
Expand Down
5 changes: 5 additions & 0 deletions resources/views/forms/email.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@include('kontour::forms.input', ['type' => $type ?? 'email', 'name' => $name ?? 'email',
'controlAttributes' => array_merge(
['autocomplete' => 'email', 'autocapitalize' => 'none', 'autocorrect' => 'off'],
$controlAttributes ?? []
)])
89 changes: 89 additions & 0 deletions tests/Feature/FormViewTests/EmailTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

namespace Kontenta\Kontour\Tests\Feature\FormViewTests;

use Illuminate\Support\Facades\View;
use Illuminate\Support\MessageBag;
use Kontenta\Kontour\Tests\IntegrationTest;

class EmailTest extends IntegrationTest
{
public static $defaultEmailAttributes = [
'autocomplete' => 'email',
'autocapitalize' => 'none',
'autocorrect' => 'off',
];

public function test_input_type_defaults_to_email()
{
$output = View::make('kontour::forms.email', [
'errors' => new MessageBag,
])->render();

$this->assertRegExp('/<input[\S\s]*type="email"[\S\s]*>/', $output);
}

public function test_input_type_can_be_specified()
{
$output = View::make('kontour::forms.email', [
'errors' => new MessageBag,
'type' => 'text',
])->render();

$this->assertRegExp('/<input[\S\s]*type="text"[\S\s]*>/', $output);
}

public function test_input_name_defaults_to_email()
{
$output = View::make('kontour::forms.email', [
'errors' => new MessageBag,
])->render();

$this->assertRegExp('/<input[\S\s]*name="email"[\S\s]*>/', $output);
}

public function test_input_name_can_be_specified()
{
$output = View::make('kontour::forms.email', [
'name' => 'test',
'errors' => new MessageBag,
])->render();

$this->assertRegExp('/<input[\S\s]*name="test"[\S\s]*>/', $output);
}

public function test_email_input_has_default_attributes()
{
$output = View::make('kontour::forms.email', [
'errors' => new MessageBag,
])->render();

foreach (self::$defaultEmailAttributes as $attribute => $default) {
$this->assertStringContainsString("$attribute=\"$default\"", $output);
}
}

public function test_control_attributes_can_be_set()
{
$output = View::make('kontour::forms.email', [
'errors' => new MessageBag,
'controlAttributes' => [
'autocomplete' => 'off',
'autocapitalize' => 'on',
'autocorrect' => 'on',
'required',
'a' => 'b',
]
])->render();

$this->assertRegExp('/\s+autocomplete="off"\W/', $output);
$this->assertRegExp('/\s+autocapitalize="on"\W/', $output);
$this->assertRegExp('/\s+autocorrect="on"\W/', $output);
$this->assertRegExp('/\s+required\W/', $output);
$this->assertRegExp('/\s+a="b"\W/', $output);

foreach (self::$defaultEmailAttributes as $attribute => $default) {
$this->assertStringNotContainsString("$attribute=\"$default\"", $output);
}
}
}

0 comments on commit a641b3b

Please sign in to comment.