Improved www.ttss.krakow.pl
2 files added
8 files modified
1 files deleted
178 ■■■■■ changed files
.travis.yml 9 ●●●● patch | view | raw | blame | history
common.js 4 ●●●● patch | view | raw | blame | history
index.html 4 ●●●● patch | view | raw | blame | history
index.js 4 ●●●● patch | view | raw | blame | history
map.html 4 ●●●● patch | view | raw | blame | history
map.js 10 ●●●● patch | view | raw | blame | history
nightwatch.conf.js 50 ●●●●● patch | view | raw | blame | history
stops/common.php 8 ●●●●● patch | view | raw | blame | history
stops/index.php 9 ●●●●● patch | view | raw | blame | history
tests.js 45 ●●●●● patch | view | raw | blame | history
tests/index.js 31 ●●●●● patch | view | raw | blame | history
.travis.yml
@@ -6,10 +6,15 @@
  - 7.0
  - nightly
addons:
  firefox: latest
  chrome: stable
before_script:
  - 'php -S 127.0.0.1:8080 &'
  - 'nvm install stable'
  - 'npm install casperjs'
  - 'npm install nightwatch selenium-server chromedriver geckodriver'
script:
  - 'node_modules/casperjs/bin/casperjs test tests.js'
  - 'node_modules/.bin/nightwatch -e chrome-headless'
  - 'node_modules/.bin/nightwatch -e firefox-headless'
common.js
@@ -115,6 +115,10 @@
 * PARSING *
 ***********/
function normalizeName(string) {
    return string.replace('.', '. ').replace('  ', ' ');
}
function parseStatus(status) {
    switch(status.status) {
        case 'STOPPING':
index.html
@@ -135,7 +135,7 @@
        </div>
        <script src="https://polyfill.io/v3/polyfill.min.js?features=Promise,XMLHttpRequest"></script>
        <script type="text/javascript" src="lang_pl.js?v8" id="lang_script"></script>
        <script type="text/javascript" src="common.js?v8"></script>
        <script type="text/javascript" src="index.js?v7"></script>
        <script type="text/javascript" src="common.js?v9"></script>
        <script type="text/javascript" src="index.js?v8"></script>
    </body>
</html>
index.js
@@ -115,8 +115,8 @@
            + '&mode=departure'
    ).done(function(data) {
        setText(times_stop_type, lang.types['s' + prefix]);
        setText(times_stop_name, data.stopName);
        setText(page_title, lang.page_title_stop_name.replace('$stop', data.stopName));
        setText(times_stop_name, normalizeName(data.stopName));
        setText(page_title, lang.page_title_stop_name.replace('$stop', normalizeName(data.stopName)));
        deleteChildren(times_alerts);
        deleteChildren(times_table);
        //deleteChildren(times_lines);
map.html
@@ -24,7 +24,7 @@
<script src="https://polyfill.io/v3/polyfill.min.js?features=Array.prototype.forEach,Array.prototype.includes,Array.prototype.map,Element.prototype.classList,Promise,String.prototype.startsWith,XMLHttpRequest,requestAnimationFrame"></script>
<script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v5.3.0/build/ol.js" integrity="sha384-iQkGyyH4ioz3m+maM3s9MX1Oq67mACa4B9Z3ovUv3Sv37LJ96fx3WnZfLoiC3Wfl" crossorigin="anonymous"></script>
<script tyle="text/javascript" src="lang_pl.js?v8" id="lang_script"></script>
<script tyle="text/javascript" src="common.js?v8"></script>
<script tyle="text/javascript" src="map.js?v20"></script>
<script tyle="text/javascript" src="common.js?v9"></script>
<script tyle="text/javascript" src="map.js?v21"></script>
</body>
</html>
map.js
@@ -278,7 +278,7 @@
            
            var vehicle_name_space = vehicle.name.indexOf(' ');
            vehicle.line = vehicle.name.substr(0, vehicle_name_space);
            vehicle.direction = vehicle.name.substr(vehicle_name_space+1);
            vehicle.direction = normalizeName(vehicle.name.substr(vehicle_name_space+1));
            if(special_directions[vehicle.direction]) {
                vehicle.line = special_directions[vehicle.direction];
            }
@@ -401,7 +401,7 @@
        for(var i = 0, il = all_departures.length; i < il; i++) {
            tr = document.createElement('tr');
            addCellWithText(tr, all_departures[i].actualTime || all_departures[i].plannedTime);
            addCellWithText(tr, all_departures[i].stop_seq_num + '. ' + all_departures[i].stop.name);
            addCellWithText(tr, all_departures[i].stop_seq_num + '. ' + normalizeName(all_departures[i].stop.name));
            
            if(i >= data.old.length) {
                stopsToMark.push('s' + ttss_type + all_departures[i].stop.id);
@@ -446,7 +446,7 @@
        for(var i = 0, il = all_departures.length; i < il; i++) {
            tr = document.createElement('tr');
            addCellWithText(tr, all_departures[i].patternText);
            dir_cell = addCellWithText(tr, all_departures[i].direction);
            dir_cell = addCellWithText(tr, normalizeName(all_departures[i].direction));
            vehicle = parseVehicle(all_departures[i].vehicleId);
            dir_cell.appendChild(displayVehicle(vehicle));
            status = parseStatus(all_departures[i]);
@@ -489,7 +489,7 @@
    var div = document.createElement('div');
    
    var typeName;
    var name = feature.get('name');
    var name = normalizeName(feature.get('name'));
    var additional;
    var table = document.createElement('table');
    var thead = document.createElement('thead');
@@ -654,7 +654,7 @@
            
            addElementWithText(a, 'span', typeName).className = 'small';
            a.appendChild(document.createTextNode(' '));
            addElementWithText(a, 'span', feature.get('name'));
            addElementWithText(a, 'span', normalizeName(feature.get('name')));
            
            div.appendChild(p);
        }
nightwatch.conf.js
New file
@@ -0,0 +1,50 @@
var seleniumServer = require('selenium-server');
var chromedriver = require('chromedriver');
var geckodriver = require('geckodriver');
module.exports = {
  src_folders: ['tests'],
  selenium: {
    start_process: true,
    server_path: seleniumServer.path,
    port: 4444,
    cli_args: {
      'webdriver.chrome.driver': chromedriver.path,
      'webdriver.gecko.driver': geckodriver.path,
    },
  },
  test_settings: {
    'chrome': {
      desiredCapabilities: {
        browserName: 'chrome',
      },
    },
    'chrome-headless': {
      desiredCapabilities: {
        browserName: 'chrome',
        chromeOptions: {
          args: [
            '--headless',
            '--no-sandbox',
            '--disable-gpu',
          ],
        },
      },
    },
    'firefox': {
      desiredCapabilities: {
        browserName: 'firefox',
      },
    },
    'firefox-headless': {
      desiredCapabilities: {
        browserName: 'firefox',
        'moz:firefoxOptions': {
          args: [
            '--headless',
          ],
        },
      },
    },
  },
};
stops/common.php
@@ -15,3 +15,11 @@
    
    return array_values($words);
}
function normalize_name($string) {
    return strtr(strtr($string, ['.' => '. ']), ['  ' => ' ']);
}
function normalize_name_cmp($string) {
    return normalize_name(mb_strtolower($string, 'UTF-8'));
}
stops/index.php
@@ -48,20 +48,21 @@
    
    // Build a structure for the UI
    $stop_list = [];
    $query_lower = mb_strtolower($_GET['query'], 'UTF-8');
    $query_lower = normalize_name_cmp($_GET['query']);
    foreach($ids as $id) {
        similar_text(
        $letters = similar_text(
            $query_lower,
            mb_strtolower($stops[$id], 'UTF-8'),
            normalize_name_cmp($stops[$id]),
            $percent
        );
        $percent += $letters * 100;
        // -5 due to UTF-8
        if(substr($stops[$id], -5) == '(nż)' && !$find_ondemand) {
            $percent /= 2;
        }
        $stop_list[] = [
            'id' => $id,
            'name' => $stops[$id],
            'name' => normalize_name($stops[$id]),
            'type' => 'stop',
            'relevance' => $percent,
        ];
tests.js
File was deleted
tests/index.js
New file
@@ -0,0 +1,31 @@
module.exports = {
    'Stop name autocompletion': function(browser) {
        browser.url('http://127.0.0.1:8080/');
        browser.getTitle(function(title) {
            this.assert.ok(title.includes('TTSS'));
        });
        var autocomplete_pairs = [
            ['baga', 'Teatr Bagatela'],
            ['d g', 'Dworzec Główny'],
            ['świę', 'Plac Wszystkich Świętych'],
            ['św g', 'Św. Gertrudy'],
            ['św.g', 'Św. Gertrudy'],
        ];
        autocomplete_pairs.forEach(function(value) {
            browser.clearValue('#stop-name');
            browser.setValue('#stop-name', value[0]);
            browser.pause(200);
            browser.expect.element('#stop-name-autocomplete > option:first-child').to.be.present.before(1000);
            browser.expect.element('#stop-name-autocomplete > option:first-child').text.to.include(value[1]).before(1000);
        });
    },
    'Translation engine': function(browser) {
        browser.url('http://127.0.0.1:8080/#!en');
        browser.pause(200);
        browser.getTitle(function(title) {
            this.assert.ok(title.includes('departures'));
        });
        browser.expect.element('[data-translate=header_line]').text.to.include('Line');
    },
};