File: D:/HostingSpaces/SBogers10/slenders.komma.pro/app/Komma/Shop/Tests/Browser/ProductTest.php
<?php
namespace App\Komma\Shop\Tests\Browser;
use App\Komma\Shop\Tests\Browser\Pages\ProductsSectionTestPage;
use App\Komma\Shop\Tests\DuskTestCase;
use App\Komma\Users\Models\KmsUser;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Laravel\Dusk\Browser;
class ProductTest extends DuskTestCase
{
use DatabaseTransactions; //Automatically rolls back database actions after tests
/**
* @group ProductSection
* @test
* @throws \Throwable
*/
public function testProductsMenuItem()
{
$this->browse(function (Browser $browser) {
$browser->loginAs(KmsUser::find(1), 'kms')
->visit(new ProductsSectionTestPage())
->screenshot('testProductsMenuItem');
});
}
/**
* @group ProductSection
* @test
* @throws \Throwable
*/
public function testNewProductScreen()
{
$this->browse(function (Browser $browser) {
$browser->loginAs(KmsUser::find(1), 'kms')
->visit(new ProductsSectionTestPage())
->click('@add_button')
->assertSee('Nieuw product')
->screenshot($this->getName(false));
});
}
/**
* @group ProductSection
* @test
* @throws \Throwable
*/
public function testAddingOfEmptyProductFailure()
{
$this->browse(function (Browser $browser) {
$browser->loginAs(KmsUser::find(1), 'kms')
->visit(new ProductsSectionTestPage())
->click('@add_button')
->assertSee('Nieuw product')
->click('@save_button')
->assertSee(__('validation.required', ['attribute' => __('shop/products.price')]))
->screenshot($this->getName(false));
});
}
/**
* @group ProductSection
* @test
* @throws \Throwable
*/
public function testAddingProductCorrectlyAndDeletingIt()
{
$productName = 'Dusk test product '.mt_rand(1111111, 99999999);
$counter = 0;
//Add
$this->browse(function (Browser $browser) use ($productName, $counter) {
$browser->loginAs(KmsUser::find(1), 'kms')
->visit(new ProductsSectionTestPage())
->click('@add_button')
->assertSee('Nieuw product')
->click('@entity_tab_nl')
->type('TextField-name-nl', $productName)
->screenshot($this->getName(false) . '-' . ++$counter)
->click('@entity_tab_algemeen')
->type('input[data-forinput="Currency-price"]', '19,95')
->screenshot($this->getName(false))
->click('@save_button')
->assertSeeIn('#main-entities-list > ul',$productName)
->screenshot($this->getName(false));
});
//Delete product
$counter = 0;
$this->browse(function (Browser $browser) use ($productName, $counter) {
$browser->visit(new ProductsSectionTestPage())
->type('@entity_search_input', $productName)
->screenshot($this->getName(false).'-'.++$counter)
->assertSeeIn('@search-result-counter', '1')
->pause(100)
->click('@found_search_item')
->screenshot($this->getName(false).'-'.++$counter)
->assertSeeIn('@entity_header', $productName)
->click('@delete_button')
->assertSee(__('kms/global.confirm_deletion'))
->click('@confirmation_confirm')
->assertSee(__('kms/global.removed'))
->screenshot($this->getName(false).'-'.++$counter);
});
}
/**
* @group ProductSection
* @preserveGlobalState disabled
* @test
*/
public function testAddingQuantityDiscountToNewProduct()
{
$this->catchExceptions(function() {
$counter = 0;
$productName = 'Dusk test product ' . mt_rand(0, 99999);//Add with quantity discount
$this->browse(function (Browser $browser) use ($productName, $counter) {
$browser->loginAs(KmsUser::find(1), 'kms')
->visit(new ProductsSectionTestPage())
->click('@add_button')
->assertSee('Nieuw product')
->click('@entity_tab_nl')
->type('TextField-name-nl', $productName)
->screenshot($this->getName(false) . '-' . ++$counter)
->click('@entity_tab_algemeen')
->type('input[data-forinput="Currency-price"]', '19,95')
->screenshot($this->getName(false))
->type('@Currency-quantity_price', '0,99')
->type('@TextField-quantity', '25')
->click('@save_button')
->assertSeeIn('#main-entities-list > ul', $productName)
//Check that discount is saved correctly. Clear it and then save it again
->assertInputValue('@Currency-quantity_price', '0.99')//Note the dot
->assertInputValue('@TextField-quantity', '25')
->type('@Currency-quantity_price', '')
->type('@TextField-quantity', '')
->click('@save_button')
//Check that no discount is visible
->assertInputValue('@Currency-quantity_price', '')
->assertInputValue('@TextField-quantity', '')
->screenshot($this->getName(false));
});//Delete product
$this->browse(function (Browser $browser) use ($productName, $counter) {
$browser->visit(new ProductsSectionTestPage())
->type('@entity_search_input', $productName)
->screenshot($this->getName(false) . '-' . ++$counter)
->assertSeeIn('@search-result-counter', '1')
->click('@found_search_item')
->screenshot($this->getName(false) . '-' . ++$counter)
->assertSeeIn('@entity_header', $productName)
->click('@delete_button')
->assertSee(__('kms/global.confirm_deletion'))
->click('@confirmation_confirm')
->assertSee(__('kms/global.removed'))
->screenshot($this->getName(false) . '-' . ++$counter);
});
});
}
}