create(['role' => UserRole::SuperAdmin]); $this->actingAs($user, 'backend'); }); it('can access index', function (): void { /** @var \Tests\TestCase $this */ // WHEN $response = $this->get('/bo/faqs'); // THEN expect($response->status())->toBe(200); $response->assertViewIs('bo.faqs.index'); }); it('can access create', function (): void { /** @var \Tests\TestCase $this */ // WHEN $response = $this->get('/bo/faqs/create'); // THEN expect($response->status())->toBe(200); $response->assertViewIs('bo.faqs.create'); }); it('can store a faq', function (): void { /** @var \Tests\TestCase $this */ // GIVEN $data = [ 'question' => 'How does it work?', 'answer' => '

Like this.

', ]; // WHEN $response = $this->post('/bo/faqs', $data); // THEN $faq = Faq::query()->firstOrFail(); expect($faq->question)->toBe('How does it work?'); expect($faq->answer)->toBe('

Like this.

'); $response->assertRedirect("/bo/faqs/{$faq->id}/edit"); }); it('can access edit', function (): void { /** @var \Tests\TestCase $this */ // GIVEN $faq = new Faq(); $faq->question = 'What is this?'; $faq->answer = 'This is an answer.'; $faq->save(); // WHEN $response = $this->get("/bo/faqs/{$faq->id}/edit"); // THEN expect($response->status())->toBe(200); $response->assertViewIs('bo.faqs.edit'); }); it('can update a faq', function (): void { /** @var \Tests\TestCase $this */ // GIVEN $faq = new Faq(); $faq->question = 'Initial question?'; $faq->answer = 'Initial answer.'; $faq->save(); $data = [ 'question' => 'Updated question?', 'answer' => '

Updated answer.

', ]; // WHEN $response = $this->put("/bo/faqs/{$faq->id}", $data); // THEN $faq->refresh(); expect($faq->question)->toBe('Updated question?'); expect($faq->answer)->toBe('

Updated answer.

'); $response->assertRedirect("/bo/faqs/{$faq->id}/edit"); }); it('can delete a faq', function (): void { /** @var \Tests\TestCase $this */ // GIVEN $faq = new Faq(); $faq->question = 'Question to delete?'; $faq->answer = 'Answer to delete.'; $faq->save(); // WHEN $response = $this->delete("/bo/faqs/{$faq->id}"); // THEN expect(Faq::query()->find($faq->id))->toBeNull(); $response->assertRedirect('/bo/faqs'); }); it('can change order', function (): void { /** @var \Tests\TestCase $this */ // GIVEN $faq = new Faq(); $faq->question = 'Question to reorder?'; $faq->answer = 'Answer to reorder.'; $faq->save(); // WHEN $response = $this->patch("/bo/faqs/{$faq->id}/up"); // THEN expect($response->status())->toBe(302); }); });