HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/fire-tech/fire-tech.nl/app/KommaApp/Shop/Tests/Browser/ProductTest.php
<?php

namespace App\KommaApp\Shop\Tests\Browser;

use App\KommaApp\Shop\Tests\Browser\Pages\ProductsSectionTestPage;
use App\KommaApp\Shop\Tests\DuskTestCase;
use App\KommaApp\Users\Models\User;
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
     */
    public function testProductsMenuItem()
    {
        $this->browse(function (Browser $browser) {
            $browser->loginAs(User::find(1))
                ->visit(new ProductsSectionTestPage())
                ->screenshot('testProductsMenuItem');
        });
    }

    /**
     * @group ProductSection
     * @test
     */
    public function testNewProductScreen()
    {
        $this->browse(function (Browser $browser) {
            $browser->loginAs(User::find(1))
                ->visit(new ProductsSectionTestPage())
                ->click('@addButton')
                ->assertSee('Nieuw product')
                ->screenshot($this->getName(false));
        });
    }

    /**
     * @group ProductSection
     * @test
     */
    public function testAddingOfEmptyProductFailure()
    {
        $this->browse(function (Browser $browser) {
            $browser->loginAs(User::find(1))
                ->visit(new ProductsSectionTestPage())
                ->click('@addButton')
                ->assertSee('Nieuw product')
                ->click('@saveButton')
                ->assertSee('titel is verplicht.')
                ->screenshot($this->getName(false));
        });
    }

    /**
     * @group ProductSection
     * @test
     */
    public function testAddingProductWithNameWithoutPrice()
    {
        $this->browse(function (Browser $browser) {
            $browser->loginAs(User::find(1))
                ->visit(new ProductsSectionTestPage())
                ->click('@addButton')
                ->assertSee('Nieuw product')
                ->type('input[data-forinput="Currency-price"]', '19,95')
                ->screenshot($this->getName(false))
                ->click('@saveButton')
                ->assertSee(__('titel is verplicht.'))
                ->screenshot($this->getName(false));
        });
    }

    /**
     * @group ProductSection
     * @test
     */
    public function testAddingProductWithPriceWithoutName()
    {
        $this->browse(function (Browser $browser) {
            $browser->loginAs(User::find(1))
                ->visit(new ProductsSectionTestPage())
                ->click('@addButton')
                ->assertSee('Nieuw product')
                ->type('TextField-title', 'Dusk test product')
                ->screenshot($this->getName(false))
                ->click('@saveButton')
                ->assertSee(__('basis prijs is verplicht.'))
                ->screenshot($this->getName(false));
        });
    }

    /**
     * @group ProductSection
     * @test
     */
    public function testAddingProductCorrectlyAndDeletingIt()
    {
        $productName = 'Dusk test product '.mt_rand(0, 99999);

        //Add
        $this->browse(function (Browser $browser) use ($productName) {
            $browser->loginAs(User::find(1))
                ->visit(new ProductsSectionTestPage())
                ->click('@addButton')
                ->assertSee('Nieuw product')
                ->type('TextField-title', $productName)
                ->type('input[data-forinput="Currency-price"]', '19,95')
                ->screenshot($this->getName(false))
                ->click('@saveButton')
                ->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('@searchInput', $productName)
            ->screenshot($this->getName(false).'-'.++$counter)
            ->assertSeeIn('#search-result-counter', '1')
            ->click('#products-searchlist > li.entities-list-item.active > a')
            ->screenshot($this->getName(false).'-'.++$counter)
            ->assertSeeIn('#entity > div.entity-header > div.entity-header-attributes > h2', $productName)
            ->click('@deleteButton')
            ->assertSee(__('kms/global.confirm_deletion'))
            ->click('@confirmYes')
            ->assertSee(__('kms/global.removed'))
            ->screenshot($this->getName(false).'-'.++$counter);
        });
    }

    /**
     * @group ProductSection
     * @test
     */
    public function testAddingQuantityDiscountToNewProduct()
    {
        $counter = 0;
        $productName = 'Dusk test product '.mt_rand(0, 99999);

        //Add with quantity discount
        $this->browse(function (Browser $browser) use ($productName) {
            $browser->loginAs(User::find(1))
                ->visit(new ProductsSectionTestPage())
                ->click('@addButton')
                ->assertSee('Nieuw product')
                ->type('TextField-title', $productName)
                ->type('input[data-forinput="Currency-price"]', '19,95')
                ->screenshot($this->getName(false))
                ->type('@quantityDiscountPriceInput', '0,99')
                ->type('@quantityDiscountQuantityInput', '25')
                ->click('@saveButton')
                ->assertSeeIn('#main-entities-list > ul',$productName)
                //Check that discount is saved correctly. Clear it and then save it again
                ->assertInputValue('@quantityDiscountPriceInput', '0.99') //Note the dot
                ->assertInputValue('@quantityDiscountQuantityInput', '25')
                ->type('@quantityDiscountPriceInput', '')
                ->type('@quantityDiscountQuantityInput', '')
                ->click('@saveButton')
                //Check that no discount is visible
                ->assertInputValue('@quantityDiscountPriceInput', '')
                ->assertInputValue('@quantityDiscountQuantityInput', '')
                ->screenshot($this->getName(false));
        });

        //Delete product
        $this->browse(function (Browser $browser) use ($productName, $counter) {
            $browser->visit(new ProductsSectionTestPage())
                ->type('@searchInput', $productName)
                ->screenshot($this->getName(false).'-'.++$counter)
                ->assertSeeIn('#search-result-counter', '1')
                ->click('#products-searchlist > li.entities-list-item.active > a')
                ->screenshot($this->getName(false).'-'.++$counter)
                ->assertSeeIn('#entity > div.entity-header > div.entity-header-attributes > h2', $productName)
                ->click('@deleteButton')
                ->assertSee(__('kms/global.confirm_deletion'))
                ->click('@confirmYes')
                ->assertSee(__('kms/global.removed'))
                ->screenshot($this->getName(false).'-'.++$counter);
        });
    }
}