|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\Feature\Backend; |
| 4 | + |
| 5 | +use Tests\TestCase; |
| 6 | +use App\Models\Faqs\Faq; |
| 7 | + |
| 8 | +class ManageFaqsTest extends TestCase |
| 9 | +{ |
| 10 | + /** @test */ |
| 11 | + public function a_user_can_view_faqs_index_page() |
| 12 | + { |
| 13 | + $this->actingAs($this->admin) |
| 14 | + ->get(route('admin.faqs.index')) |
| 15 | + ->assertViewIs('backend.faqs.index') |
| 16 | + ->assertSee(trans('labels.backend.faqs.management')) |
| 17 | + ->assertSee(trans('labels.backend.faqs.table.question')) |
| 18 | + ->assertSee(trans('labels.backend.faqs.table.answer')) |
| 19 | + ->assertSee(trans('labels.backend.faqs.table.status')) |
| 20 | + ->assertSee('Export') |
| 21 | + ->assertSee('Action'); |
| 22 | + } |
| 23 | + |
| 24 | + /** @test */ |
| 25 | + public function a_user_can_create_faq() |
| 26 | + { |
| 27 | + $faq = make(Faq::class); |
| 28 | + |
| 29 | + $this->actingAs($this->admin) |
| 30 | + ->post(route('admin.faqs.store'), $faq->toArray()); |
| 31 | + |
| 32 | + $this->assertDatabaseHas(config('module.faqs.table'), ['question' => $faq->question, 'answer' => $faq->answer]); |
| 33 | + } |
| 34 | + |
| 35 | + /** @test */ |
| 36 | + public function it_requires_question_while_creating() |
| 37 | + { |
| 38 | + $faq = make(Faq::class, ['question' => '']); |
| 39 | + |
| 40 | + $this->actingAs($this->admin) |
| 41 | + ->withExceptionHandling() |
| 42 | + ->post(route('admin.faqs.store'), $faq->toArray()) |
| 43 | + ->assertSessionHasErrors('question'); |
| 44 | + } |
| 45 | + |
| 46 | + |
| 47 | + /** @test */ |
| 48 | + public function it_requires_answer_while_creating() |
| 49 | + { |
| 50 | + $faq = make(Faq::class, ['answer' => '']); |
| 51 | + |
| 52 | + $this->actingAs($this->admin) |
| 53 | + ->withExceptionHandling() |
| 54 | + ->post(route('admin.faqs.store'), $faq->toArray()) |
| 55 | + ->assertSessionHasErrors('answer'); |
| 56 | + } |
| 57 | + |
| 58 | + /** @test */ |
| 59 | + public function it_requires_question_while_updating() |
| 60 | + { |
| 61 | + $faq = create(Faq::class); |
| 62 | + |
| 63 | + $this->actingAs($this->admin) |
| 64 | + ->withExceptionHandling() |
| 65 | + ->patch(route('admin.faqs.update', $faq), ['question' => '', 'answer' => $faq->answer]) |
| 66 | + ->assertSessionHasErrors('question'); |
| 67 | + } |
| 68 | + |
| 69 | + /** @test */ |
| 70 | + public function it_requires_answer_while_updating() |
| 71 | + { |
| 72 | + $faq = create(Faq::class); |
| 73 | + |
| 74 | + $this->actingAs($this->admin) |
| 75 | + ->withExceptionHandling() |
| 76 | + ->patch(route('admin.faqs.update', $faq), ['question' => $faq->question, 'answer' => '']) |
| 77 | + ->assertSessionHasErrors('answer'); |
| 78 | + } |
| 79 | + |
| 80 | + /** @test */ |
| 81 | + public function a_user_can_update_faq() |
| 82 | + { |
| 83 | + $faq = create(Faq::class); |
| 84 | + |
| 85 | + $changed_question = "What is Life?"; |
| 86 | + $changed_answer = $faq->answer; |
| 87 | + $this->actingAs($this->admin) |
| 88 | + ->patch(route('admin.faqs.update', $faq), ['question' => $changed_question, 'answer' => $changed_answer]); |
| 89 | + |
| 90 | + $this->assertDatabaseHas(config('module.faqs.table'), ['id' => $faq->id, 'question' => $changed_question, 'answer' => $changed_answer]); |
| 91 | + } |
| 92 | + |
| 93 | + /** @test */ |
| 94 | + public function a_user_can_delete_faq() |
| 95 | + { |
| 96 | + $faq = create(Faq::class); |
| 97 | + |
| 98 | + $this->actingAs($this->admin) |
| 99 | + ->delete(route('admin.faqs.destroy' , $faq)); |
| 100 | + |
| 101 | + $this->assertDatabaseMissing(config('module.faqs.table'), ['id' => $faq->id, 'deleted_at' => null]); |
| 102 | + } |
| 103 | +} |
0 commit comments