From 15df3c0b618c6343acdb02f220659606428e8835 Mon Sep 17 00:00:00 2001
From: Jacek Kowalski <Jacek@jacekk.info>
Date: Sat, 18 Mar 2017 23:37:48 +0000
Subject: [PATCH] Execute functional tests using casperjs

---
 tests.js    |   45 ++++++++++++++++++++++
 .travis.yml |   17 ++++++++
 2 files changed, 62 insertions(+), 0 deletions(-)

diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..3b2dc96
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,17 @@
+language: php
+php:
+  - 5.4
+  - 5.5
+  - 5.6
+  - 7.0
+  - nightly
+
+sudo: required
+
+before_script:
+  - 'php -S 127.0.0.1:8080 &'
+  - 'nvm install stable'
+  - 'npm install casperjs'
+
+script:
+  - 'node_modules/casperjs/bin/casperjs tests.js'
diff --git a/tests.js b/tests.js
new file mode 100644
index 0000000..3d304b2
--- /dev/null
+++ b/tests.js
@@ -0,0 +1,45 @@
+casper.test.begin('Stop name autocompletion', 4, function(test) {
+	casper.start('http://127.0.0.1:8080/', function() {
+		test.assertTitleMatches(/^TTSS\s/, 'Page title: TTSS...');
+	});
+	
+	var autocomplete_pairs = [
+		['bag', 'Teatr Bagatela'],
+		['d g', 'Dworzec Główny'],
+		['świę', 'Plac Wszystkich Świętych'],
+	];
+	
+	autocomplete_pairs.forEach(function(value) {
+		casper.then(function() {
+			this.sendKeys('#stop-name', value[0], {reset: true});
+		}).wait(200, function() {
+			test.assertSelectorHasText(
+				'#stop-name-autocomplete > option',
+				value[1],
+				'Autocomplete: ' + value[1]
+			);
+		});
+	});
+	
+	casper.run(function() {
+		test.done();
+	});
+});
+
+casper.test.begin('Translation engine', 2, function(test) {
+	casper.start('http://127.0.0.1:8080/#!pl', function() {
+		test.assertTitleMatches(/odjazdy/i, 'Page title: ...odjazdy...');
+	});
+	
+	casper.wait(200, function() {
+		test.assertSelectorHasText(
+			'[data-translate=header_lines]',
+			'Linie',
+			'Translation: Lines -> Linie'
+		);
+	});
+	
+	casper.run(function() {
+		test.done();
+	});
+});

--
Gitblit v1.9.1