Compare commits

...

3 Commits

Author SHA1 Message Date
Kacper Donat
bcdc94384b add proxy support 2019-12-10 20:29:44 +01:00
Kacper Donat
2e2cf65a46 add test for one stop scenario 2019-12-10 17:51:15 +01:00
Kacper Donat
8cb1f9342c add some basic cypress test 2019-12-09 20:58:59 +01:00
17 changed files with 1396 additions and 53 deletions

6
cypress.json Normal file
View File

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

View File

@ -0,0 +1,21 @@
describe("Get departures for one stop", () => {
it("Sucessfully Loads", () => {
cy.visit('/');
});
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');
});
});

9
cypress/plugins/index.js Normal file
View File

@ -0,0 +1,9 @@
const wp = require('@cypress/webpack-preprocessor');
module.exports = (on) => {
const options = {
webpackOptions: require('../webpack.config'),
};
on('file:preprocessor', wp(options))
};

View File

@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add("login", (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })

20
cypress/support/index.ts Normal file
View File

@ -0,0 +1,20 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************
// Import commands.ts using ES2015 syntax:
import './commands'
// Alternatively you can use CommonJS syntax:
// require('./commands')

14
cypress/tsconfig.json Normal file
View File

@ -0,0 +1,14 @@
{
"extends": "../tsconfig",
"compilerOptions": {
"strict": true,
"baseUrl": "../node_modules",
"target": "es5",
"lib": ["es5", "dom"],
"types": ["cypress"],
"paths": {
"@app/*": ["../resources/ts/*"]
}
},
"include": ["**/*.ts"]
}

26
cypress/webpack.config.js Normal file
View File

@ -0,0 +1,26 @@
module.exports = {
mode: 'development',
// webpack will transpile TS and JS files
resolve: {
extensions: ['.ts', '.js']
},
module: {
rules: [
{
// every time webpack sees a TS file (except for node_modules)
// webpack will use "ts-loader" to transpile it to JavaScript
test: /\.ts$/,
exclude: [/node_modules/],
use: [
{
loader: 'ts-loader',
options: {
// skip typechecking for speed
transpileOnly: true,
}
}
]
}
]
}
};

View File

@ -34,13 +34,18 @@
"xpath": "^0.0.27" "xpath": "^0.0.27"
}, },
"dependencies": { "dependencies": {
"@cypress/webpack-preprocessor": "^4.1.1",
"babel-minify-webpack-plugin": "^0.3.1", "babel-minify-webpack-plugin": "^0.3.1",
"copy-webpack-plugin": "^4.5.2", "copy-webpack-plugin": "^4.5.2",
"cypress": "^3.7.0",
"imagemin-webpack-plugin": "^2.3.0", "imagemin-webpack-plugin": "^2.3.0",
"mini-css-extract-plugin": "^0.4.2", "mini-css-extract-plugin": "^0.4.2",
"vue2-leaflet": "^1.0.2", "vue2-leaflet": "^1.0.2",
"vuex": "^3.0.1", "vuex": "^3.0.1",
"vuex-class": "^0.3.1", "vuex-class": "^0.3.1",
"workbox-webpack-plugin": "^4.3.1" "workbox-webpack-plugin": "^4.3.1"
},
"scripts": {
"cypress": "cypress open"
} }
} }

View File

@ -24,6 +24,10 @@ if ($debug) {
Debug::enable(); Debug::enable();
} }
if (isset($_ENV['http_proxy'])) {
stream_context_set_default(['http' => ['proxy' => $_ENV['http_proxy']]]);
}
if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? false) { if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? false) {
Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST); Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
} }

View File

@ -22,7 +22,7 @@
</div> </div>
<ul class="stop-group__stops list-underlined"> <ul class="stop-group__stops list-underlined">
<li v-for="stop in group" :key="stop.id" class="d-flex"> <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']" /> <fa :icon="['fal', 'check']" />
</button> </button>
<stop :stop="stop" class="flex-grow-1"></stop> <stop :stop="stop" class="flex-grow-1"></stop>

View File

@ -51,7 +51,7 @@ class StopsController extends Controller
break; break;
default: default:
$result = $stops->getAllGroups(); $result = $stops->getAll();
} }
return $this->json($result->all()); return $this->json($result->all());

View File

@ -20,7 +20,7 @@ class GenericStopRepository extends DatabaseRepository implements StopRepository
public function getAllGroups(): Collection public function getAllGroups(): Collection
{ {
return $this->group($this->getAll()); return self::group($this->getAll());
} }
public function getById($id): ?Stop 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'])); $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 $stops->groupBy(function (Stop $stop) {
return $stop->getName(); return $stop->getName();

View File

@ -3,14 +3,17 @@
namespace App\Provider\Dummy; namespace App\Provider\Dummy;
use App\Model\Stop; use App\Model\Stop;
use App\Provider\Database\GenericStopRepository;
use App\Provider\StopRepository; use App\Provider\StopRepository;
use App\Service\Proxy\ReferenceFactory; use App\Service\Proxy\ReferenceFactory;
use Tightenco\Collect\Support\Collection; use Tightenco\Collect\Support\Collection;
use Kadet\Functional as f; use Kadet\Functional as f;
use Kadet\Functional\Predicates as p;
class DummyStopRepository implements StopRepository class DummyStopRepository implements StopRepository
{ {
private $reference; private $reference;
private $all;
/** /**
* DummyDepartureProviderRepository constructor. * DummyDepartureProviderRepository constructor.
@ -20,30 +23,42 @@ class DummyStopRepository implements StopRepository
public function __construct(ReferenceFactory $reference) public function __construct(ReferenceFactory $reference)
{ {
$this->reference = $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 public function getAll(): Collection
{ {
return collect(); return collect($this->all);
} }
public function getAllGroups(): Collection public function getAllGroups(): Collection
{ {
return collect(); return GenericStopRepository::group($this->getAll());
} }
public function getById($id): ?Stop 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 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 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

@ -52,7 +52,7 @@ class ZtmGdanskDepartureRepository implements DepartureRepository
'vehicle' => $this->reference->get(Vehicle::class, $delay['vehicleCode']), 'vehicle' => $this->reference->get(Vehicle::class, $delay['vehicleCode']),
'line' => $lines->get($delay['routeId']) ?: Line::createFromArray([ 'line' => $lines->get($delay['routeId']) ?: Line::createFromArray([
'symbol' => $delay['routeId'], 'symbol' => $delay['routeId'],
'type' => Line::TYPE_UNKNOWN 'type' => Line::TYPE_UNKNOWN,
]), ]),
]); ]);
})->values(); })->values();

View File

@ -40,7 +40,7 @@
</fold> </fold>
</section> </section>
<section class="section"> <section class="section" id="departures">
<header class="section__title flex"> <header class="section__title flex">
<h2> <h2>
<fa :icon="['fal', 'clock']" fixed-width></fa> <fa :icon="['fal', 'clock']" fixed-width></fa>
@ -100,7 +100,7 @@
</popper> </popper>
</header> </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"> <li v-for="stop in stops" :key="stop.id" class="d-flex align-items-center">
<button @click="remove(stop)" class="btn btn-action"> <button @click="remove(stop)" class="btn btn-action">
<fa :icon="['fal', 'times']"></fa> <fa :icon="['fal', 'times']"></fa>
@ -116,7 +116,7 @@
<fa :icon="['fal', 'search']" fixed-width class="mr-1"></fa> <fa :icon="['fal', 'search']" fixed-width class="mr-1"></fa>
Wybierz przystanki Wybierz przystanki
</h2> </h2>
<button class="btn btn-action" @click="visibility.picker = 'favourites'"> <button class="btn btn-action" @click="visibility.picker = 'favourites'" id="open_favourites_picker">
<fa :icon="['fal', 'star']" fixed-witdth></fa> <fa :icon="['fal', 'star']" fixed-witdth></fa>
</button> </button>
</template> </template>
@ -125,7 +125,7 @@
<fa :icon="['fal', 'star']" fixed-width class="mr-1"></fa> <fa :icon="['fal', 'star']" fixed-width class="mr-1"></fa>
Zapisane Zapisane
</h2> </h2>
<button class="btn btn-action" @click="visibility.picker = 'search'"> <button class="btn btn-action" @click="visibility.picker = 'search'" id="open_stop_search">
<fa :icon="['fal', 'search']" fixed-witdth></fa> <fa :icon="['fal', 'search']" fixed-witdth></fa>
</button> </button>
</template> </template>
@ -133,8 +133,8 @@
<div class="transition-box"> <div class="transition-box">
<transition name="fade"> <transition name="fade">
<keep-alive> <keep-alive>
<stop-finder @select="add" :blacklist="stops" v-if="visibility.picker === 'search'"></stop-finder> <stop-finder @select="add" :blacklist="stops" v-if="visibility.picker === 'search'" id="stop_search"></stop-finder>
<favourites v-else-if="visibility.picker === 'favourites'"></favourites> <favourites v-else-if="visibility.picker === 'favourites'" id="favourites_list"></favourites>
</keep-alive> </keep-alive>
</transition> </transition>
</div> </div>

View File

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

1267
yarn.lock

File diff suppressed because it is too large Load Diff