Skip to content

Commit

Permalink
added test for home controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Ismaeel220 committed Mar 23, 2024
1 parent 746eca3 commit f49b1a8
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions WoodLess/tests/Feature/Controllers/HomeControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Tests\Feature\Controllers;

use App\Models\Category;
use App\Models\Product;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class HomeControllerTest extends TestCase
{
use RefreshDatabase;

/**
* Test if the index method returns the welcome view with categories and products.
*
* @return void
*/
public function test_index_returns_welcome_view_with_categories_and_products()
{
// Given some categories and products exist in the database
$categories = Category::factory()->count(3)->create();
$products = Product::factory()->count(5)->create();

// When a user visits the home page
$response = $this->get('/');

// Then they should see the welcome view with categories and products
$response->assertStatus(200)
->assertViewIs('welcome') // Assert that the view is correct
->assertViewHas('categories', $categories) // Assert that categories are passed to the view
->assertViewHas('products', $products); // Assert that products are passed to the view
}
}

0 comments on commit f49b1a8

Please sign in to comment.