aboutsummaryrefslogtreecommitdiffstats
path: root/spec/javascripts
diff options
context:
space:
mode:
Diffstat (limited to 'spec/javascripts')
-rw-r--r--spec/javascripts/actions_spec.js71
-rw-r--r--spec/javascripts/reducers_spec.js178
-rw-r--r--spec/javascripts/spec_helper.js32
3 files changed, 281 insertions, 0 deletions
diff --git a/spec/javascripts/actions_spec.js b/spec/javascripts/actions_spec.js
new file mode 100644
index 000000000..55de1c31f
--- /dev/null
+++ b/spec/javascripts/actions_spec.js
@@ -0,0 +1,71 @@
+var actions = require('es6_browserified/actions')
+
+describe('actions', () => {
+ it('should create an action to add a stop', () => {
+ const expectedAction = {
+ type: 'ADD_STOP',
+ }
+ expect(actions.addStop()).toEqual(expectedAction)
+ })
+})
+describe('actions', () => {
+ it('should create an action to move up a stop', () => {
+ const index = 1
+ const expectedAction = {
+ type: 'MOVE_STOP_UP',
+ index
+ }
+ expect(actions.moveStopUp(index)).toEqual(expectedAction)
+ })
+})
+describe('actions', () => {
+ it('should create an action to move down a stop', () => {
+ const index = 1
+ const expectedAction = {
+ type: 'MOVE_STOP_DOWN',
+ index
+ }
+ expect(actions.moveStopDown(index)).toEqual(expectedAction)
+ })
+})
+describe('actions', () => {
+ it('should create an action to delete a stop', () => {
+ const index = 1
+ const expectedAction = {
+ type: 'DELETE_STOP',
+ index
+ }
+ expect(actions.deleteStop(index)).toEqual(expectedAction)
+ })
+})
+describe('actions', () => {
+ it('should create an action to update the value of a stop', () => {
+ const text = 'updated text'
+ const index = 1
+ const expectedAction = {
+ type: 'UPDATE_INPUT_VALUE',
+ index,
+ text
+ }
+ expect(actions.updateInputValue(index, text)).toEqual(expectedAction)
+ })
+})
+
+describe('actions', () => {
+ it('should create an action to update the up select of a stop', () => {
+ const event = {
+ currentTarget: {
+ value: 'forbidden',
+ id: 'up'
+ }
+ }
+ const index = 1
+ const expectedAction = {
+ type :'UPDATE_SELECT_VALUE',
+ select_id: 'up',
+ select_value: 'forbidden',
+ index
+ }
+ expect(actions.updateSelectValue(event, index)).toEqual(expectedAction)
+ })
+})
diff --git a/spec/javascripts/reducers_spec.js b/spec/javascripts/reducers_spec.js
new file mode 100644
index 000000000..a4880e73e
--- /dev/null
+++ b/spec/javascripts/reducers_spec.js
@@ -0,0 +1,178 @@
+var reducer = require('es6_browserified/reducers/todos')
+let state = []
+describe('stops reducer', () => {
+ beforeEach(()=>{
+ state = [
+ {
+ text: 'first',
+ index: 0,
+ for_boarding: 'normal',
+ for_alighting: 'normal'
+ },
+ {
+ text: 'second',
+ index: 1,
+ for_boarding: 'normal',
+ for_alighting: 'normal'
+ }
+ ]
+ })
+
+ it('should return the initial state', () => {
+ expect(
+ reducer(undefined, {})
+ ).toEqual([])
+ })
+
+ it('should handle ADD_STOP', () => {
+ expect(
+ reducer(state, {
+ type: 'ADD_STOP'
+ })
+ ).toEqual(
+ [
+ {
+ text: 'first',
+ index: 0,
+ for_boarding: 'normal',
+ for_alighting: 'normal'
+ },
+ {
+ text: 'second',
+ index: 1,
+ for_boarding: 'normal',
+ for_alighting: 'normal'
+ },
+ {
+ text: '',
+ index: 2,
+ for_boarding: 'normal',
+ for_alighting: 'normal'
+ }
+ ]
+ )
+ })
+
+ it('should handle MOVE_UP_STOP', () => {
+ expect(
+ reducer(state, {
+ type: 'MOVE_STOP_UP',
+ index: 1
+ })
+ ).toEqual(
+ [
+ {
+ text: 'second',
+ index: 1,
+ for_boarding: 'normal',
+ for_alighting: 'normal'
+ },
+ {
+ text: 'first',
+ index: 0,
+ for_boarding: 'normal',
+ for_alighting: 'normal'
+ }
+ ]
+ )
+ })
+
+ it('should handle MOVE_DOWN_STOP', () => {
+ expect(
+ reducer(state, {
+ type: 'MOVE_STOP_DOWN',
+ index: 0
+ })
+ ).toEqual(
+ [
+ {
+ text: 'second',
+ index: 1,
+ for_boarding: 'normal',
+ for_alighting: 'normal'
+ },
+ {
+ text: 'first',
+ index: 0,
+ for_boarding: 'normal',
+ for_alighting: 'normal'
+ }
+ ]
+ )
+ })
+
+ it('should handle DELETE_STOP', () => {
+ expect(
+ reducer(state, {
+ type: 'DELETE_STOP',
+ index: 1
+ })
+ ).toEqual(
+ [
+ {
+ text: 'first',
+ index: 0,
+ for_boarding: 'normal',
+ for_alighting: 'normal'
+ }
+ ]
+ )
+ })
+
+ //TODO unskip when es6 is properly functionnal
+ xit('should handle UPDATE_INPUT_VALUE', () => {
+ expect(
+ reducer(state, {
+ type: 'UPDATE_INPUT_VALUE',
+ index: 0,
+ text: {
+ text: "new value",
+ stoparea_id: 1
+ }
+ })
+ ).toEqual(
+ [
+ {
+ text: 'new value',
+ index: 0,
+ stoparea_id: 1,
+ for_boarding: 'normal',
+ for_alighting: 'normal'
+ },
+ {
+ text: 'second',
+ index: 1,
+ for_boarding: 'normal',
+ for_alighting: 'normal'
+ }
+ ]
+ )
+ })
+
+ xit('should handle UPDATE_SELECT_VALUE', () => {
+ expect(
+ reducer(state, {
+ type :'UPDATE_SELECT_VALUE',
+ select_id: 'for_boarding',
+ select_value: 'prohibited',
+ index: 0
+ })
+ ).toEqual(
+ [
+ {
+ text: 'new value',
+ index: 0,
+ stoparea_id: 1,
+ for_boarding: 'prohibited',
+ for_alighting: 'normal'
+ },
+ {
+ text: 'second',
+ index: 1,
+ for_boarding: 'normal',
+ for_alighting: 'normal'
+ }
+ ]
+ )
+ })
+})
diff --git a/spec/javascripts/spec_helper.js b/spec/javascripts/spec_helper.js
new file mode 100644
index 000000000..71d30ff8d
--- /dev/null
+++ b/spec/javascripts/spec_helper.js
@@ -0,0 +1,32 @@
+// Teaspoon includes some support files, but you can use anything from your own support path too.
+// require support/jasmine-jquery-1.7.0
+// require support/jasmine-jquery-2.0.0
+// require support/jasmine-jquery-2.1.0
+// require support/sinon
+// require support/your-support-file
+//
+// PhantomJS (Teaspoons default driver) doesn't have support for Function.prototype.bind, which has caused confusion.
+// Use this polyfill to avoid the confusion.
+//= require support/phantomjs-shims
+//
+// You can require your own javascript files here. By default this will include everything in application, however you
+// may get better load performance if you require the specific files that are being used in the spec that tests them.
+//= require application
+//
+// Deferring execution
+// If you're using CommonJS, RequireJS or some other asynchronous library you can defer execution. Call
+// Teaspoon.execute() after everything has been loaded. Simple example of a timeout:
+//
+// Teaspoon.defer = true
+// setTimeout(Teaspoon.execute, 1000)
+//
+// Matching files
+// By default Teaspoon will look for files that match _spec.{js,js.coffee,.coffee}. Add a filename_spec.js file in your
+// spec path and it'll be included in the default suite automatically. If you want to customize suites, check out the
+// configuration in teaspoon_env.rb
+//
+// Manifest
+// If you'd rather require your spec files manually (to control order for instance) you can disable the suite matcher in
+// the configuration and use this file as a manifest.
+//
+// For more information: http://github.com/modeset/teaspoon