| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- <?php
- use Webkul\Attribute\Models\AttributeFamily as AttributeFamilyModel;
- use function Pest\Laravel\deleteJson;
- use function Pest\Laravel\get;
- use function Pest\Laravel\getJson;
- use function Pest\Laravel\postJson;
- use function Pest\Laravel\putJson;
- it('should return attribute family listing page', function () {
- // Act and Assert.
- $this->loginAsAdmin();
- get(route('admin.catalog.families.index'))
- ->assertOk()
- ->assertSeeText(trans('admin::app.catalog.families.index.title'))
- ->assertSeeText(trans('admin::app.catalog.families.index.add'));
- });
- it('should return listing items of attribute family', function () {
- // Arrange.
- $attributeFamily = AttributeFamilyModel::factory()->create();
- // Act and Assert.
- $this->loginAsAdmin();
- getJson(route('admin.catalog.families.index'), [
- 'X-Requested-With' => 'XMLHttpRequest',
- ])
- ->assertOk()
- ->assertJsonPath('records.0.id', $attributeFamily->id)
- ->assertJsonPath('records.0.code', $attributeFamily->code)
- ->assertJsonPath('meta.total', 2);
- });
- it('should return attribute family create page', function () {
- // Act and Assert.
- $this->loginAsAdmin();
- get(route('admin.catalog.families.create'))
- ->assertOk()
- ->assertSeeText(trans('admin::app.catalog.families.create.title'))
- ->assertSeeText(trans('admin::app.catalog.families.create.back-btn'));
- });
- it('should store newly created attribute family', function () {
- // Act and Assert.
- $this->loginAsAdmin();
- postJson(route('admin.catalog.families.store'), [
- 'code' => $code = fake()->numerify('code########'),
- 'name' => $name = fake()->name(),
- 'attribute_groups' => [
- [
- 'code' => $code,
- 'name' => $name,
- 'column' => 1,
- ],
- ],
- ])
- ->assertRedirectToRoute('admin.catalog.families.index')
- ->isRedirection();
- $this->assertModelWise([
- AttributeFamilyModel::class => [
- [
- 'code' => $code,
- 'name' => $name,
- ],
- ],
- ]);
- });
- it('should fail the validation with errors when certain inputs are not provided when store in attribute family', function () {
- // Act and Assert.
- $this->loginAsAdmin();
- postJson(route('admin.catalog.families.store'))
- ->assertJsonValidationErrorFor('name')
- ->assertJsonValidationErrorFor('code')
- ->assertUnprocessable();
- });
- it('should return edit page of attribute families', function () {
- // Arrange.
- $attributeFamily = AttributeFamilyModel::factory()->create();
- // Act and Assert.
- $this->loginAsAdmin();
- get(route('admin.catalog.families.edit', $attributeFamily->id))
- ->assertOk()
- ->assertSeeText(trans('admin::app.catalog.families.edit.title'))
- ->assertSeeText(trans('admin::app.catalog.families.edit.back-btn'));
- });
- it('should fail the validation with errors when certain inputs are not provided when update in attribute family', function () {
- // Arrange.
- $attributeFamily = AttributeFamilyModel::factory()->create();
- // Act and Assert.
- $this->loginAsAdmin();
- putJson(route('admin.catalog.families.update', $attributeFamily->id))
- ->assertJsonValidationErrorFor('name')
- ->assertJsonValidationErrorFor('code')
- ->assertUnprocessable();
- });
- it('should update the existing attribute families', function () {
- // Arrange.
- $attributeFamily = AttributeFamilyModel::factory()->create();
- // Act and Assert.
- $this->loginAsAdmin();
- putJson(route('admin.catalog.families.update', $attributeFamily->id), $data = [
- 'code' => fake()->numerify('code#######'),
- 'name' => $attributeFamily->name,
- ])
- ->assertRedirectToRoute('admin.catalog.families.index')
- ->isRedirection();
- $this->assertModelWise([
- AttributeFamilyModel::class => [
- $data,
- ],
- ]);
- });
- it('should delete the existing attribute family', function () {
- // Arrange.
- $attributeFamily = AttributeFamilyModel::factory()->create();
- // Act and Assert.
- $this->loginAsAdmin();
- deleteJson(route('admin.catalog.families.delete', $attributeFamily->id))
- ->assertOk()
- ->assertSeeText(trans('admin::app.catalog.families.delete-success'));
- $this->assertDatabaseMissing('attribute_families', [
- 'id' => $attributeFamily->id,
- ]);
- });
- it('should not be able to delete the attribute family if the attribute family is the only one present', function () {
- // Act and Assert.
- $this->loginAsAdmin();
- deleteJson(route('admin.catalog.families.delete', $attributeFamilyId = 1))
- ->assertBadRequest()
- ->assertSeeText(trans('admin::app.catalog.families.last-delete-error'));
- $this->assertModelWise([
- AttributeFamilyModel::class => [
- [
- 'id' => $attributeFamilyId,
- ],
- ],
- ]);
- });
|