<commit_before><?php

namespace Tests\Browser;

use Coyote\Country;
use Coyote\Currency;
use Coyote\Firm;
use Coyote\Job;
use Coyote\Payment;
use Coyote\Plan;
use Coyote\User;
use Laravel\Dusk\Browser;
use function PHPSTORM_META\type;
use Tests\DuskTestCase;
use Faker\Factory;

class JobPostingTest extends DuskTestCase
{
    protected function setUp(): void
    {
        parent::setUp();

        $this->user = User::first();
    }

    public function testCreateJobOfferAsRegularUser()
    {
        $fake = Factory::create();

        $this->browse(function (Browser $browser) use ($fake) {
            $browser->loginAs(User::first());

            $browser->visit('/Praca/Submit')
                ->resize(1920, 1080)
                ->type('title', $title = $fake->text(50))
                ->type('salary_from', $salaryFrom = $fake->numberBetween(0, 999))
                ->type('salary_to', $salaryTo = $fake->numberBetween(1000, 2000))
                ->select('currency_id', Currency::CHF)
                ->type('email', $fake->email)
                ->assertDontSee('Zapisz i zakończ')
                ->press('Informacje o firmie')
                ->waitForLocation('/Praca/Submit/Firm')
                ->click('label[for="is_private_1"]')
                ->scrollTo('#footer-top')
                ->press('Podgląd')
                ->waitForLocation('/Praca/Submit/Preview')
                ->press('Opublikuj')
                ->waitForText('Powrót do ogłoszenia')
                ->clickLink('Powrót do ogłoszenia')
                ->assertSeeIn('.media-heading', $title)
                ->assertSeeIn('.salary', $salaryFrom)
                ->assertSeeIn('.salary', '₣');
        });
    }

    public function testCreateJobOfferAsFirm()
    {
        $fake = Factory::create();

        $this->browse(function (Browser $browser) use ($fake) {
            $browser->loginAs(User::first());

            $plan = Plan::where('name', 'Premium')->first();

            $browser->visit('/Praca/Submit')
                ->resize(1920, 1080)
                ->type('title', $title = $fake->text(50))
                ->value('input[name=plan_id]', $plan->id)
//                ->select('employment_id', 1)
                ->type('email', $fake->email)
                ->press('Informacje o firmie')
                ->waitForLocation('/Praca/Submit/Firm')
                ->assertRadioSelected('is_private', 0)
                ->click('label[for="is_agency_0"]')
                ->assertSee('Benefity')
                ->type('name', $firm = $fake->name)
                ->type('website', $website = 'http://4programmers.net')
                ->select('employees', 2)
                ->value('input[name=country]', 'Polska')
                ->value('input[name=city]', 'Wrocław')
                ->assertValue('input[name=country]', 'Polska')
                ->type('youtube_url', 'https://www.youtube.com/watch?v=fz2OUoJpR7k')
                ->scrollTo('#footer-top')
                ->press('Podgląd')
                ->waitForLocation('/Praca/Submit/Preview')
                ->press('Opublikuj')
                ->waitForText('Powrót do ogłoszenia')
                ->clickLink('Powrót do ogłoszenia')
                ->assertSeeIn('.media-heading', $title)
                ->assertSeeIn('.employer', $firm)
                ->assertSee($website);

//            $this->assertDatabaseHas('firms', ['name' => $firm, 'country_id' => 14, 'city' => 'Wrocław']);
            $this->assertDatabaseHas('firms', ['name' => $firm, 'youtube_url' => 'https://www.youtube.com/embed/fz2OUoJpR7k']);
        });
    }

    public function testCreateJobOfferAsSecondFirm()
    {
        $user = factory(User::class)->create();
        $firm = factory(Firm::class)->create(['user_id' => $user->id]);

        $this->browse(function (Browser $browser) use ($user, $firm) {
            $browser->loginAs($user);

            $fake = Factory::create();

            $browser->visit('/Praca/Submit')
                ->resize(1920, 1080)
                ->type('title', $title = $fake->text(50))
//                ->select('employment_id', 1)
                ->type('email', $fake->email)
                ->press('Informacje o firmie')
                ->waitForLocation('/Praca/Submit/Firm')
                ->assertInputValue('name', $firm->name)
                ->value('input[name=id]', '')
                ->type('website', $website = 'http://4programmers.net')
                ->type('name', 'New firm')
                ->scrollTo('#footer-top')
                ->press('Podgląd')
                ->waitForLocation('/Praca/Submit/Preview')
                ->assertSeeIn('.employer', 'New firm')
                ->press('Opublikuj')
                ->waitForText('Powrót do ogłoszenia')
                ->clickLink('Powrót do ogłoszenia')
                ->assertSeeIn('.media-heading', $title)
                ->assertSeeIn('.employer', 'New firm')
                ->assertSee($website);
        });
    }

    public function testCreatePrivateJobOfferDespiteHavingFirm()
    {
        $user = factory(User::class)->create();
        $firm = factory(Firm::class)->create(['user_id' => $user->id]);

        $this->browse(function (Browser $browser) use ($user, $firm) {
            $browser->loginAs($user);

            $fake = Factory::create();

            $browser->visit('/Praca/Submit')
                ->resize(1920, 1080)
                ->type('title', $title = $fake->text(50))
//                ->select('employment_id', 1)
                ->type('email', $fake->email)
                ->scrollTo('#footer-top')
                ->press('Informacje o firmie')
                ->waitForLocation('/Praca/Submit/Firm')
                ->click('label[for="is_private_1"]')
                ->press('Zapisz i zakończ')
                ->waitForText('Powrót do ogłoszenia')
                ->clickLink('Powrót do ogłoszenia')
                ->assertDontSee($firm->name);
        });
    }

    public function testCreateJobOfferWithErrors()
    {
        $user = factory(User::class)->create();

        $this->browse(function (Browser $browser) use ($user) {
            $browser->loginAs($user);
            $fake = Factory::create();

            $browser->visit('/Praca/Submit')
                ->resize(1920, 1080)
                ->assertInputValue('email', $user->email)
                ->scrollTo('#footer-top')
                ->press('Informacje o firmie')
                ->waitForText('Formularz zawiera błędy. Sprawdź poprawność wprowadzonych danych i spróbuj ponownie.')
                ->assertSee('Tytuł jest wymagany.')
                ->type('title', $fake->title)
                ->scrollTo('#footer-top')
                ->press('Informacje o firmie')
                ->waitForLocation('/Praca/Submit/Firm')
                ->press('Zapisz i zakończ')
                ->waitForText('Nazwa firmy jest wymagana.');
        });
    }

    public function testQuickCreateJobOffer()
    {
        $user = factory(User::class)->create();
        /** @var Firm $firm */
        $firm = factory(Firm::class)->create(['user_id' => $user->id]);

        $firm->benefits()->create(['name' => 'Game-boy']);<commit_msg>drobna poprawaa testow, scroll na sam dol<commit_after><?php

namespace Tests\Browser;

use Coyote\Country;
use Coyote\Currency;
use Coyote\Firm;
use Coyote\Job;
use Coyote\Payment;
use Coyote\Plan;
use Coyote\User;
use Laravel\Dusk\Browser;
use function PHPSTORM_META\type;
use Tests\DuskTestCase;
use Faker\Factory;

class JobPostingTest extends DuskTestCase
{
    protected function setUp(): void
    {
        parent::setUp();

        $this->user = User::first();
    }

    public function testCreateJobOfferAsRegularUser()
    {
        $fake = Factory::create();

        $this->browse(function (Browser $browser) use ($fake) {
            $browser->loginAs(User::first());

            $browser->visit('/Praca/Submit')
                ->resize(1920, 1080)
                ->type('title', $title = $fake->text(50))
                ->type('salary_from', $salaryFrom = $fake->numberBetween(0, 999))
                ->type('salary_to', $salaryTo = $fake->numberBetween(1000, 2000))
                ->select('currency_id', Currency::CHF)
                ->type('email', $fake->email)
                ->assertDontSee('Zapisz i zakończ')
                ->press('Informacje o firmie')
                ->waitForLocation('/Praca/Submit/Firm')
                ->click('label[for="is_private_1"]')
                ->scrollTo('#footer-top')
                ->press('Podgląd')
                ->waitForLocation('/Praca/Submit/Preview')
                ->press('Opublikuj')
                ->waitForText('Powrót do ogłoszenia')
                ->clickLink('Powrót do ogłoszenia')
                ->assertSeeIn('.media-heading', $title)
                ->assertSeeIn('.salary', $salaryFrom)
                ->assertSeeIn('.salary', '₣');
        });
    }

    public function testCreateJobOfferAsFirm()
    {
        $fake = Factory::create();

        $this->browse(function (Browser $browser) use ($fake) {
            $browser->loginAs(User::first());

            $plan = Plan::where('name', 'Premium')->first();

            $browser->visit('/Praca/Submit')
                ->resize(1920, 1080)
                ->type('title', $title = $fake->text(50))
                ->value('input[name=plan_id]', $plan->id)
//                ->select('employment_id', 1)
                ->type('email', $fake->email)
                ->press('Informacje o firmie')
                ->waitForLocation('/Praca/Submit/Firm')
                ->assertRadioSelected('is_private', 0)
                ->click('label[for="is_agency_0"]')
                ->assertSee('Benefity')
                ->type('name', $firm = $fake->name)
                ->type('website', $website = 'http://4programmers.net')
                ->select('employees', 2)
                ->value('input[name=country]', 'Polska')
                ->value('input[name=city]', 'Wrocław')
                ->assertValue('input[name=country]', 'Polska')
                ->type('youtube_url', 'https://www.youtube.com/watch?v=fz2OUoJpR7k')
                ->scrollTo('#footer-top')
                ->press('Podgląd')
                ->waitForLocation('/Praca/Submit/Preview')
                ->press('Opublikuj')
                ->waitForText('Powrót do ogłoszenia')
                ->clickLink('Powrót do ogłoszenia')
                ->assertSeeIn('.media-heading', $title)
                ->assertSeeIn('.employer', $firm)
                ->assertSee($website);

//            $this->assertDatabaseHas('firms', ['name' => $firm, 'country_id' => 14, 'city' => 'Wrocław']);
            $this->assertDatabaseHas('firms', ['name' => $firm, 'youtube_url' => 'https://www.youtube.com/embed/fz2OUoJpR7k']);
        });
    }

    public function testCreateJobOfferAsSecondFirm()
    {
        $user = factory(User::class)->create();
        $firm = factory(Firm::class)->create(['user_id' => $user->id]);

        $this->browse(function (Browser $browser) use ($user, $firm) {
            $browser->loginAs($user);

            $fake = Factory::create();

            $browser->visit('/Praca/Submit')
                ->resize(1920, 1080)
                ->type('title', $title = $fake->text(50))
//                ->select('employment_id', 1)
                ->type('email', $fake->email)
                ->press('Informacje o firmie')
                ->waitForLocation('/Praca/Submit/Firm')
                ->assertInputValue('name', $firm->name)
                ->value('input[name=id]', '')
                ->type('website', $website = 'http://4programmers.net')
                ->type('name', 'New firm')
                ->scrollTo('#footer-top')
                ->press('Podgląd')
                ->waitForLocation('/Praca/Submit/Preview')
                ->assertSeeIn('.employer', 'New firm')
                ->press('Opublikuj')
                ->waitForText('Powrót do ogłoszenia')
                ->clickLink('Powrót do ogłoszenia')
                ->assertSeeIn('.media-heading', $title)
                ->assertSeeIn('.employer', 'New firm')
                ->assertSee($website);
        });
    }

    public function testCreatePrivateJobOfferDespiteHavingFirm()
    {
        $user = factory(User::class)->create();
        $firm = factory(Firm::class)->create(['user_id' => $user->id]);

        $this->browse(function (Browser $browser) use ($user, $firm) {
            $browser->loginAs($user);

            $fake = Factory::create();

            $browser->visit('/Praca/Submit')
                ->resize(1920, 1080)
                ->type('title', $title = $fake->text(50))
//                ->select('employment_id', 1)
                ->type('email', $fake->email)
                ->scrollTo('#footer-top')
                ->press('Informacje o firmie')
                ->waitForLocation('/Praca/Submit/Firm')
                ->click('label[for="is_private_1"]')
                ->press('Zapisz i zakończ')
                ->waitForText('Powrót do ogłoszenia')
                ->clickLink('Powrót do ogłoszenia')
                ->assertDontSee($firm->name);
        });
    }

    public function testCreateJobOfferWithErrors()
    {
        $user = factory(User::class)->create();

        $this->browse(function (Browser $browser) use ($user) {
            $browser->loginAs($user);
            $fake = Factory::create();

            $browser->visit('/Praca/Submit')
                ->resize(1920, 1080)
                ->assertInputValue('email', $user->email)
                ->scrollTo('#footer-top')
                ->press('Informacje o firmie')
                ->waitForText('Formularz zawiera błędy. Sprawdź poprawność wprowadzonych danych i spróbuj ponownie.')
                ->assertSee('Tytuł jest wymagany.')
                ->type('title', $fake->title)
                ->scrollTo('#footer-top')
                ->press('Informacje o firmie')
                ->waitForLocation('/Praca/Submit/Firm')
                ->scrollTo('#footer-top')
                ->press('Zapisz i zakończ')
                ->waitForText('Nazwa firmy jest wymagana.');
        });
    }

    public function testQuickCreateJobOffer()
    {
        $user = factory(User::class)->create();
        /** @var Firm $firm */
        $firm = factory(Firm::class)->create(['user_id' => $user->id]);

        $firm->benefits()->create(['name' => 'Game-boy']);
{'fraction_non_alphanumeric': 0.17322780454232622, 'fraction_numerical': 0.010461114934618031, 'mean_word_length': 1.861559669161087, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 294, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2625917', 'n_tokens_mistral': 4580, 'n_tokens_neox': 4164, 'n_words': 668}