
import {expect} from 'chai';
import {List, Map} from 'immutable'

describe('immutability', () => {
  //learning test
  describe('is a number', () => {

    function increment(currentState) {
      return currentState + 1;
    }

    it('is immutable', () => {
      let state = 42;
      let nextNumber = increment(state);

      expect(nextNumber).to.equal(43);
      expect(state).to.equal(42);
    });
  });

  //List test
  describe('A List', () => {
    function AddMovie(currentState, movie) {
      return currentState.push(movie);
    }

    it('is immutable', () => {
      let state = List.of('Transporting', '28 Days Later');
      let nextState = AddMovie(state, 'Sunshine');

      expect(nextState).to.equal(List.of(
        'Transporting',
        '28 Days Later',
        'Sunshine'
      ));

      expect(state).to.equal(List.of('Transporting', '28 Days Later'));
    });
  });

  //Map test
  describe('a tree', () => {

    function addMovie(currentState, movie) {
      return currentState.set(
        'movies',
        currentState.get('movies').push(movie)
      );
    }

    it('is immutable', () => {
      let state = Map({
        movies: List.of('Trainspotting', '28 Days Later')
      });
      let nextState = addMovie(state, 'Sunshine');

      expect(nextState).to.equal(Map({
        movies: List.of(
          'Trainspotting',
          '28 Days Later',
          'Sunshine'
        )
      }));
      expect(state).to.equal(Map({
        movies: List.of(
          'Trainspotting',
          '28 Days Later'
        )
      }));
    });

  });

});

@@ -977,32 +977,34 @@
  movie) %7B%0A      
+/*
 return currentSt
@@ -1085,16 +1085,93 @@
       );
+*/%0A%0A      return currentState.update('movies', movies =%3E movies.push(movie));
 %0A    %7D%0A%0A

update immutibility test of immutablejs