Page MenuHomePhorge

CountrySelect.php
No OneTemporary

Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None

CountrySelect.php

<?php
namespace Tests\Browser\Components;
use Laravel\Dusk\Browser;
use Laravel\Dusk\Component as BaseComponent;
use PHPUnit\Framework\Assert as PHPUnit;
class CountrySelect extends BaseComponent
{
protected $selector;
protected $countries;
public function __construct($selector)
{
$this->selector = $selector;
$this->countries = include resource_path('countries.php');
}
/**
* Get the root selector for the component.
*
* @return string
*/
public function selector()
{
return $this->selector;
}
/**
* Assert that the browser page contains the component.
*
* @param Browser $browser
*/
public function assert($browser)
{
$browser->assertVisible($this->selector)
->assertMissing("{$this->selector} @dialog");
}
/**
* Get the element shortcuts for the component.
*
* @return array
*/
public function elements()
{
return [
'@link' => 'a',
'@dialog' => '.modal',
];
}
/**
* Assert selected countries on the map and in the link content
*/
public function assertCountries($browser, array $list)
{
if (empty($list)) {
$browser->assertSeeIn('@link', 'No restrictions')
->click('@link')
->with(new Dialog('@dialog'), static function ($browser) {
$browser->waitFor('.world-map > svg', 10);
$selected = $browser->elements('.world-map [aria-selected="true"]');
// There can be one country selected if current location has been
// recognized (i.e. the geo-location database is imported)
PHPUnit::assertTrue(count($selected) <= 1);
$browser->click('@button-cancel');
});
return;
}
$browser->assertSeeIn('@link', $this->countriesText($list))
->click('@link')
->with(new Dialog('@dialog'), static function ($browser) use ($list) {
$browser->waitFor('.world-map > svg', 10);
$selected = $browser->elements('.world-map [aria-selected="true"]');
// There can be one extra country selected if current location has been
// recognized (i.e. the geo-location database is imported)
PHPUnit::assertTrue(count($selected) == count($list) || count($selected) == count($list) + 1);
foreach ($list as $code) {
$browser->assertVisible('.world-map [cc="' . $code . '"]');
}
$browser->click('@button-cancel');
});
}
/**
* Update selected countries
*/
public function setCountries($browser, array $list)
{
$browser->click('@link')
->with(new Dialog('@dialog'), static function ($browser) use ($list) {
$browser->waitFor('.world-map > svg')
->execScript("\$('.world-map [cc]').attr('aria-selected', '')");
foreach ($list as $code) {
$browser->click('.world-map [cc="' . $code . '"]');
}
$browser->click('@button-action');
});
}
/**
* Get textual list of country names
*/
protected function countriesText(array $list): string
{
$names = [];
foreach ($list as $code) {
$names[] = $this->countries[$code][1];
}
return implode(', ', $names);
}
}

File Metadata

Mime Type
text/x-php
Expires
Fri, Apr 24, 1:48 PM (3 d, 19 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18861324
Default Alt Text
CountrySelect.php (3 KB)

Event Timeline