You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

176 lines
5.1 KiB

<?php
namespace Tests\Feature;
use fullMstr;
use Tests\BrowserKitTest as TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
class ManageMasterTest extends TestCase
{
use RefreshDatabase;
/** @test */
public function user_can_see_master_list_in_master_index_page()
{
$singleMstr = Master::factory()->create();
$this->loginAsUser();
$this->visitRoute('masters.index');
$this->see($singleMstr->name);
}
/** @test */
public function user_can_create_a_master()
{
$this->loginAsUser();
$this->visitRoute('masters.index');
$this->click(__('master.create'));
$this->seeRouteIs('masters.index', ['action' => 'create']);
$this->submitForm(__('master.create'), [
'name' => 'Master 1 name',
'description' => 'Master 1 description',
]);
$this->seeRouteIs('masters.index');
$this->seeInDatabase('masters', [
'name' => 'Master 1 name',
'description' => 'Master 1 description',
]);
}
private function getCreateFields(array $overrides = [])
{
return array_merge([
'name' => 'Master 1 name',
'description' => 'Master 1 description',
], $overrides);
}
/** @test */
public function validate_master_name_is_required()
{
$this->loginAsUser();
// name empty
$this->post(route('masters.store'), $this->getCreateFields(['name' => '']));
$this->assertSessionHasErrors('name');
}
/** @test */
public function validate_master_name_is_not_more_than_60_characters()
{
$this->loginAsUser();
// name 70 characters
$this->post(route('masters.store'), $this->getCreateFields([
'name' => str_repeat('Test Title', 7),
]));
$this->assertSessionHasErrors('name');
}
/** @test */
public function validate_master_description_is_not_more_than_255_characters()
{
$this->loginAsUser();
// description 256 characters
$this->post(route('masters.store'), $this->getCreateFields([
'description' => str_repeat('Long description', 16),
]));
$this->assertSessionHasErrors('description');
}
/** @test */
public function user_can_edit_a_master_within_search_query()
{
$this->loginAsUser();
$singleMstr = Master::factory()->create(['name' => 'Testing 123']);
$this->visitRoute('masters.index', ['q' => '123']);
$this->click('edit-master-'.$singleMstr->id);
$this->seeRouteIs('masters.index', ['action' => 'edit', 'id' => $singleMstr->id, 'q' => '123']);
$this->submitForm(__('master.update'), [
'name' => 'Master 1 name',
'description' => 'Master 1 description',
]);
$this->seeRouteIs('masters.index', ['q' => '123']);
$this->seeInDatabase('masters', [
'name' => 'Master 1 name',
'description' => 'Master 1 description',
]);
}
private function getEditFields(array $overrides = [])
{
return array_merge([
'name' => 'Master 1 name',
'description' => 'Master 1 description',
], $overrides);
}
/** @test */
public function validate_master_name_update_is_required()
{
$this->loginAsUser();
$master = Master::factory()->create(['name' => 'Testing 123']);
// name empty
$this->patch(route('masters.update', $master), $this->getEditFields(['name' => '']));
$this->assertSessionHasErrors('name');
}
/** @test */
public function validate_master_name_update_is_not_more_than_60_characters()
{
$this->loginAsUser();
$master = Master::factory()->create(['name' => 'Testing 123']);
// name 70 characters
$this->patch(route('masters.update', $master), $this->getEditFields([
'name' => str_repeat('Test Title', 7),
]));
$this->assertSessionHasErrors('name');
}
/** @test */
public function validate_master_description_update_is_not_more_than_255_characters()
{
$this->loginAsUser();
$master = Master::factory()->create(['name' => 'Testing 123']);
// description 256 characters
$this->patch(route('masters.update', $master), $this->getEditFields([
'description' => str_repeat('Long description', 16),
]));
$this->assertSessionHasErrors('description');
}
/** @test */
public function user_can_delete_a_master()
{
$this->loginAsUser();
$singleMstr = Master::factory()->create();
Master::factory()->create();
$this->visitRoute('masters.index', ['action' => 'edit', 'id' => $singleMstr->id]);
$this->click('del-master-'.$singleMstr->id);
$this->seeRouteIs('masters.index', ['action' => 'delete', 'id' => $singleMstr->id]);
$this->seeInDatabase('masters', [
'id' => $singleMstr->id,
]);
$this->press(__('app.delete_confirm_button'));
$this->dontSeeInDatabase('masters', [
'id' => $singleMstr->id,
]);
}
}