|
94 | 94 | $bedroom = Item::factory()->for($user->currentTeam)->location()->create(['name' => 'Bedroom']); |
95 | 95 | $closet = Item::factory()->for($user->currentTeam)->bin()->childOf($bedroom)->create(['name' => 'Right Closet']); |
96 | 96 | $tote = Item::factory()->for($user->currentTeam)->bin()->childOf($closet)->create(['name' => 'Game Tote']); |
| 97 | + $game = Item::factory()->for($user->currentTeam)->bin()->childOf($tote)->create(['name' => 'Catan']); |
97 | 98 |
|
98 | 99 | Livewire::actingAs($user) |
99 | 100 | ->test('pages::inventory.index') |
|
128 | 129 | ->assertSeeHtml('<span>Right Closet</span>') |
129 | 130 | ->assertDontSeeHtml('<span>Game Tote</span>'); |
130 | 131 | }); |
| 132 | + |
| 133 | + test('clicking item without children redirects to show', function () { |
| 134 | + $user = User::factory()->withTeam()->create(); |
| 135 | + $parent = Item::factory()->for($user->currentTeam)->location()->create(['name' => 'Bedroom']); |
| 136 | + $child = Item::factory()->for($user->currentTeam)->childOf($parent)->bin()->create(['name' => 'Closet']); |
| 137 | + |
| 138 | + Livewire::actingAs($user) |
| 139 | + ->test('pages::inventory.index') |
| 140 | + ->call('navigateDown', $parent->id) |
| 141 | + ->call('navigateDown', $child->id) |
| 142 | + ->assertRedirect(route('inventory.show', ['item' => $child])); |
| 143 | + }); |
131 | 144 | }); |
132 | 145 |
|
133 | 146 | describe('can create and edit', function () { |
134 | 147 | test('create pre-fills parent_id with current parentId', function () { |
135 | 148 | $user = User::factory()->withTeam()->create(); |
136 | 149 | $parent = Item::factory()->for($user->currentTeam)->location()->create(['name' => 'Bedroom']); |
| 150 | + Item::factory()->for($user->currentTeam)->childOf($parent)->bin()->create(['name' => 'Tote']); |
137 | 151 |
|
138 | 152 | Livewire::actingAs($user) |
139 | 153 | ->test('pages::inventory.index') |
|
498 | 512 |
|
499 | 513 | Livewire::actingAs($user) |
500 | 514 | ->test('pages::inventory.index') |
501 | | - ->call('navigateDown', $parent->id) |
| 515 | + ->set('parentId', $parent->id) |
502 | 516 | ->set('importForm.file', amazonFixtureUpload()) |
503 | 517 | ->call('import') |
504 | 518 | ->assertHasNoErrors(); |
|
536 | 550 | ->assertHasErrors('importForm.file'); |
537 | 551 | }); |
538 | 552 | }); |
| 553 | + |
| 554 | +describe('can generate qr codes', function () { |
| 555 | + test('can show qr code for an item', function () { |
| 556 | + $user = User::factory()->withTeam()->create(); |
| 557 | + $item = Item::factory()->for($user->currentTeam)->create(['name' => 'Guitar']); |
| 558 | + |
| 559 | + Livewire::actingAs($user) |
| 560 | + ->test('pages::inventory.index') |
| 561 | + ->call('showQrCode', $item->id) |
| 562 | + ->assertSet('qrCode.name', 'Guitar') |
| 563 | + ->assertNotSet('qrCode.svg', ''); |
| 564 | + }); |
| 565 | + |
| 566 | + test('qr code svg contains valid svg markup', function () { |
| 567 | + $user = User::factory()->withTeam()->create(); |
| 568 | + $item = Item::factory()->for($user->currentTeam)->create(); |
| 569 | + |
| 570 | + $component = Livewire::actingAs($user) |
| 571 | + ->test('pages::inventory.index') |
| 572 | + ->call('showQrCode', $item->id); |
| 573 | + |
| 574 | + expect($component->get('qrCode.svg'))->toContain('<svg'); |
| 575 | + }); |
| 576 | + |
| 577 | + test('cannot show qr code for an item from another team', function () { |
| 578 | + $user = User::factory()->withTeam()->create(); |
| 579 | + $otherItem = Item::factory()->create(); |
| 580 | + |
| 581 | + Livewire::actingAs($user) |
| 582 | + ->test('pages::inventory.index') |
| 583 | + ->call('showQrCode', $otherItem->id); |
| 584 | + })->throws(ModelNotFoundException::class); |
| 585 | +}); |
0 commit comments