File: D:/HostingSpaces/ZelfVerkopen/zelfverkopen.nl/app/KommaApp/Shop/Tests/Browser/ProductGroupTest.php
<?php
namespace App\KommaApp\Shop\Tests\Browser;
use App\KommaApp\Shop\Products\Product\Product;
use App\KommaApp\Shop\Tests\Browser\Pages\ProductGroupSectionTestPage;
use App\KommaApp\Shop\Tests\DuskTestCase;
use App\KommaApp\Users\Models\User;
use Laravel\Dusk\Browser;
class ProductGroupTest extends DuskTestCase
{
// use DatabaseTransactions; //Automatically rolls back database actions after tests
/**
* @group ProductGroupSection
* @test
*/
public function testProductsGroupMenuItem()
{
$this->browse(function (Browser $browser) {
$browser->loginAs(User::find(1))
->visit(new ProductGroupSectionTestPage())
->screenshot($this->getName(false));
});
}
/**
* @group ProductGroupSection
* @test
*/
public function testNewProductGroupScreen()
{
$this->browse(function (Browser $browser) {
$browser->loginAs(User::find(1))
->visit(new ProductGroupSectionTestPage())
->click('@addButton')
->assertSee('Nieuwe product groep')
->screenshot($this->getName(false));
});
}
/**
* @group ProductGroupSection
* @test
*/
public function testAddingOfEmptyProductGroupFailure()
{
$this->browse(function (Browser $browser) {
$browser->loginAs(User::find(1))
->visit(new ProductGroupSectionTestPage())
->click('@addButton')
->assertSee('Nieuwe product groep')
->click('@saveButton')
->assertSee('titel is verplicht.')
->screenshot($this->getName(false));
});
}
/**
* @group ProductGroupSection
* @test
*/
public function testAddingProductGroupCorrectlyAndDeletingIt()
{
$productGroupName = 'Dusk test product group ' . mt_rand(0, 99999);
//Create 2 products that we add to the group for testing purposes
$product = factory(Product::class)->create();
$product2 = factory(Product::class)->create();
//Add
$counter = 0;
$this->browse(function (Browser $browser) use ($productGroupName, $counter, $product, $product2) {
$browser->loginAs(User::find(1))
->visit(new ProductGroupSectionTestPage())
->click('@addButton')
->assertSee('Nieuwe product groep')
->type('TextField-title', $productGroupName)
->screenshot($this->getName(false) . '-' . ++$counter)
->type('#AutocompleteInput-products-fake', $product->title)->pause(350)
->keys('#AutocompleteInput-products-fake', '{down}')->pause(350)
->keys('#AutocompleteInput-products-fake', '{enter}')->pause(350)
->assertSee($product->title)
->screenshot($this->getName(false) . '-' . ++$counter)
->type('#AutocompleteInput-products-fake', $product2->title)->pause(350)
->keys('#AutocompleteInput-products-fake', '{down}')->pause(350)
->keys('#AutocompleteInput-products-fake', '{enter}')->pause(350)
->assertSee($product2->title)
->screenshot($this->getName(false) . '-' . ++$counter)
->click('@saveButton')
->assertSeeIn('#main-entities-list > ul', $productGroupName)
->screenshot($this->getName(false));
});
//Delete product group
$counter = 0;
$this->browse(function (Browser $browser) use ($productGroupName, $counter) {
$browser->visit(new ProductGroupSectionTestPage())
->type('@searchInput', $productGroupName)
->screenshot($this->getName(false) . '-' . ++$counter)
->assertSeeIn('#search-result-counter', '1')
->click('#productgroups-searchlist > li.entities-list-item.active > a')
->screenshot($this->getName(false) . '-' . ++$counter)
->assertSeeIn('#entity > div.entity-header > div.entity-header-attributes > h2', $productGroupName)
->click('@deleteButton')
->assertSee(__('kms/global.removed'))
->screenshot($this->getName(false) . '-' . ++$counter);
});
$product->delete();
$product2->delete();
}
}