add test for one stop scenario

This commit is contained in:
Kacper Donat 2019-12-10 17:51:15 +01:00
parent 8cb1f9342c
commit 2e2cf65a46
7 changed files with 52 additions and 19 deletions

View File

@ -1,5 +1,6 @@
{
"supportFile": "cypress/support/index.ts",
"fixturesFolder": false,
"baseUrl": "http://czydojade.localhost:8080"
"baseUrl": "http://czydojade.localhost:8080/dummy/",
"modifyObstructiveCode": false
}

View File

@ -1,10 +1,26 @@
describe("The Start Page", () => {
describe("Get departures for one stop", () => {
it("Sucessfully Loads", () => {
cy.visit('/dummy');
cy.visit('/');
});
it("Allows to open favourites window", () => {
cy.get('#open_favourites_picker').click();
cy.get('#favourites_list').should('exist');
})
it("Allows to search", () => {
cy.get('.finder input').type("Lipo");
cy.get('.finder__stops ul li:first-child').should('contain.text', 'Lipowa')
});
it('Allows to pick a stop', () => {
cy.get('.finder__stops ul li:first-child button[data-action="add"]').click();
cy.get('#stops li:first-child').should('contain.text', 'Lipowa')
});
it ('Shows departures from picked stop', () => {
cy.get('#departures .departures .stop__name').should('contain.text', 'Lipowa');
});
// it("Allows to open favourites window", () => {
// cy.get('#open_favourites_picker').click();
// cy.get('#favourites_list').should('exist');
// })
});

View File

@ -22,7 +22,7 @@
</div>
<ul class="stop-group__stops list-underlined">
<li v-for="stop in group" :key="stop.id" class="d-flex">
<button @click="select(stop, $event)" class="btn btn-action">
<button @click="select(stop, $event)" class="btn btn-action" data-action="add">
<fa :icon="['fal', 'check']" />
</button>
<stop :stop="stop" class="flex-grow-1"></stop>

View File

@ -20,7 +20,7 @@ class GenericStopRepository extends DatabaseRepository implements StopRepository
public function getAllGroups(): Collection
{
return $this->group($this->getAll());
return self::group($this->getAll());
}
public function getById($id): ?Stop
@ -49,10 +49,10 @@ class GenericStopRepository extends DatabaseRepository implements StopRepository
$stops = collect($query->execute([':name' => "%$name%"]))->map(f\ref([$this, 'convert']));
return $this->group($stops);
return self::group($stops);
}
private function group(Collection $stops)
public static function group(Collection $stops)
{
return $stops->groupBy(function (Stop $stop) {
return $stop->getName();

View File

@ -3,14 +3,17 @@
namespace App\Provider\Dummy;
use App\Model\Stop;
use App\Provider\Database\GenericStopRepository;
use App\Provider\StopRepository;
use App\Service\Proxy\ReferenceFactory;
use Tightenco\Collect\Support\Collection;
use Kadet\Functional as f;
use Kadet\Functional\Predicates as p;
class DummyStopRepository implements StopRepository
{
private $reference;
private $all;
/**
* DummyDepartureProviderRepository constructor.
@ -20,30 +23,42 @@ class DummyStopRepository implements StopRepository
public function __construct(ReferenceFactory $reference)
{
$this->reference = $reference;
$this->all = collect([
Stop::createFromArray(['id' => 1, 'name' => 'Lipowa', 'variant' => '01', 'onDemand' => true, 'latitude' => 0, 'longitude' => 0 ]),
Stop::createFromArray(['id' => 2, 'name' => 'Bukowa', 'variant' => '01', 'onDemand' => false ]),
Stop::createFromArray(['id' => 3, 'name' => 'Kasztanowa', 'variant' => '01', 'onDemand' => false ]),
Stop::createFromArray(['id' => 4, 'name' => 'Brzozowa', 'variant' => '01', 'onDemand' => false ]),
Stop::createFromArray(['id' => 5, 'name' => 'Brzozowa', 'variant' => '02', 'onDemand' => false ]),
]);
}
public function getAll(): Collection
{
return collect();
return collect($this->all);
}
public function getAllGroups(): Collection
{
return collect();
return GenericStopRepository::group($this->getAll());
}
public function getById($id): ?Stop
{
return Stop::createFromArray(['id' => $id, 'name' => 'lorem']);
return $this->all->first(p\property('id', p\equals($id)));
}
public function getManyById($ids): Collection
{
return collect($ids)->map(f\ref([ $this, 'getById' ]));
return $this->all->filter(p\property('id', function ($id) use ($ids) {
return in_array($id, $ids);
}));
}
public function findGroupsByName(string $name): Collection
{
return collect();
return GenericStopRepository::group($this->all->filter(p\property('name', function ($stopName) use ($name) {
return stripos($stopName, $name) !== false;
})));
}
}

View File

@ -40,7 +40,7 @@
</fold>
</section>
<section class="section">
<section class="section" id="departures">
<header class="section__title flex">
<h2>
<fa :icon="['fal', 'clock']" fixed-width></fa>
@ -100,7 +100,7 @@
</popper>
</header>
<ul class="picker__stops list-underlined">
<ul class="picker__stops list-underlined" id="stops">
<li v-for="stop in stops" :key="stop.id" class="d-flex align-items-center">
<button @click="remove(stop)" class="btn btn-action">
<fa :icon="['fal', 'times']"></fa>

View File

@ -9,5 +9,6 @@
"moduleResolution": "node",
"downlevelIteration": true
},
"files": ["resources/ts/app.ts"]
"files": ["resources/ts/app.ts"],
"include": ["resources/ts/**/*.ts"]
}