describe('mapStateToProps', () => {
    const state = {
      allUsersMap: {
        a1b2c3: {userid: 'a1b2c3'}
      },
      loggedInUserId: 'a1b2c3',
      working: {
        fetchingUser: {inProgress: false}
      }
    };

    const tracked = mutationTracker.trackObj(state);
    const result = mapStateToProps({blip: state});

    it('should not mutate the state', () => {
      expect(mutationTracker.hasMutated(tracked)).to.be.false;
    });

    it('should be a function', () => {
      assert.isFunction(mapStateToProps);
    });

    it('should map allUsersMap.a1b2c3 to user', () => {
      expect(result.user).to.deep.equal(state.allUsersMap.a1b2c3);
    });

    it('should map working.fetchingUser.inProgress to fetchingUser', () => {
      expect(result.fetchingUser).to.equal(state.working.fetchingUser.inProgress);
    });
  });
Exemple #2
0
    it('should add logged in user to state without team or permissions attributes present', () => {
      let initialStateForTest = {};
      let tracked = mutationTracker.trackObj(initialStateForTest);

      let user = {
        userid: 'a1b2c3',
        name: 'Jenny',
        permissions: {
          a1b2c3: { root: {} }
        },
        team: [
          { userid: 'd4e5f6' }
        ]
      };

      let action = actions.sync.loginSuccess(user);

      let state = reducer(initialStateForTest, action);

      expect(Object.keys(state).length).to.equal(1);

      expect(state[user.userid].name).to.equal(user.name);
      expect(state[user.userid].team).to.be.undefined;
      expect(mutationTracker.hasMutated(tracked)).to.be.false;
    });
    it('should set state to null', () => {
      let initialStateForTest = [ 'a1b2c3', 'd4e5f6', 'x1y2z3' ];
      let tracked = mutationTracker.trackObj(initialStateForTest);
      
      let action = actions.sync.logoutRequest();

      let state = reducer(initialStateForTest, action);

      expect(state.length).to.equal(0);
      expect(mutationTracker.hasMutated(tracked)).to.be.false;
    });
    it('should set state to null', () => {
      let initialStateForTest = {
        'a1b2c3': { view: {}, note: {} },
        'd4e5f6': { view: {}, note: {} }
      };
      let tracked = mutationTracker.trackObj(initialStateForTest);
      let action = actions.sync.logoutRequest();

      let state = reducer(initialStateForTest, action);

      expect(Object.keys(state).length).to.equal(0);
      expect(mutationTracker.hasMutated(tracked)).to.be.false;
    });
  describe('mapStateToProps', () => {
    const state = {
      resentEmailVerification: false,
      sentEmailVerification: false,
      working: {
        resendingEmailVerification: {inProgress: true, notification: {type: 'alert', message: 'Hi!'}}
      }
    };

    const tracked = mutationTracker.trackObj(state);
    const result = mapStateToProps({blip: state});

    it('should not mutate the state', () => {
      expect(mutationTracker.hasMutated(tracked)).to.be.false;
    });

    it('should be a function', () => {
      assert.isFunction(mapStateToProps);
    });

    it('should map working.resendingEmailVerification.notification to notification', () => {
      expect(result.notification).to.equal(state.working.resendingEmailVerification.notification);
    });

    it('should map working.resendingEmailVerification.inProgress to working', () => {
      expect(result.working).to.equal(state.working.resendingEmailVerification.inProgress);
    });

    it('should map resentEmailVerification to resent', () => {
      expect(result.resent).to.equal(state.resentEmailVerification);
    });

    it('should map sentEmailVerification to sent', () => {
      expect(result.sent).to.equal(state.sentEmailVerification);
    });

    describe('when some state is `null`', () => {
      const state = {
        resentEmailVerification: false,
        sentEmailVerification: false,
        working: {
          resendingEmailVerification: {inProgress: true, notification: null}
        }
      };
      const result = mapStateToProps({blip: state});

      it('should map working.resendingEmailVerification.notification to notification', () => {
        expect(result.notification).to.be.null;
      });
    });
  });
    it('should set state to empty array', () => {
      let initialStateForTest = [
        { inviteid: 'xyz123zyx', email: 'g@g.com' },
        { inviteid: 'abc987cba', email: 'a@a.com' }
      ];
      let tracked = mutationTracker.trackObj(initialStateForTest);

      let action = actions.sync.logoutRequest();

      let state = reducer(initialStateForTest, action);

      expect(state.length).to.equal(0);
      expect(mutationTracker.hasMutated(tracked)).to.be.false;
    });
      it('should do nothing', () => {
        const user = {
          userid: 'd4e5f6'
        };

        let initialStateForTest = {};
        let tracked = mutationTracker.trackObj(initialStateForTest);

        let action = actions.sync.loginSuccess(user);

        let state = reducer(initialStateForTest, action);

        expect(Object.keys(state).length).to.equal(0);
        expect(mutationTracker.hasMutated(tracked)).to.be.false;
      });
    it('should remove member from hash map', () => {
      let patientId = 'x1y2z3';

      let initialStateForTest = [ 'a1b2c3', 'd4e5f6', 'x1y2z3' ];
      let tracked = mutationTracker.trackObj(initialStateForTest);
      
      let action = actions.sync.removeMembershipInOtherCareTeamSuccess(patientId);

      let state = reducer(initialStateForTest, action);

      expect(state.length).to.equal(2);
      expect(state[2]).to.be.undefined;
      expect(_.includes(state, patientId)).to.be.false;
      expect(mutationTracker.hasMutated(tracked)).to.be.false;
    });
Exemple #9
0
    it('should set state to a hash map of patients', () => {
      let initialStateForTest = {
        a1b2c3:  {userid: 'a1b2c3' }
      };

      let tracked = mutationTracker.trackObj(initialStateForTest);

      let action = actions.sync.logoutRequest()

      let state = reducer(initialStateForTest, action);

      expect(Object.keys(state).length).to.equal(0);
      expect(state).to.deep.equal({});
      expect(mutationTracker.hasMutated(tracked)).to.be.false;
    });
    it('should set root perms for newly create target patient', () => {
      const userid = 'a1b2c3';
      const patient = {};

      let initialStateForTest = {};
      let tracked = mutationTracker.trackObj(initialStateForTest);

      let action = actions.sync.setupDataStorageSuccess(userid, patient);

      let state = reducer(initialStateForTest, action);

      expect(Object.keys(state).length).to.equal(1);
      expect(Object.keys(state['a1b2c3']).length).to.equal(1);
      expect(state['a1b2c3'].root).to.exist;
      expect(mutationTracker.hasMutated(tracked)).to.be.false;
    });
 it('should handle SET_NEW_PATIENT_URL', () => {
   const NEW_PATIENT = 'http://www.acme.com/patients/new';
   const actionPayload = {url: NEW_PATIENT};
   expect(misc.blipUrls(undefined, {
     type: actionTypes.SET_NEW_PATIENT_URL,
     payload: actionPayload
   }).newPatient).to.equal(NEW_PATIENT);
   // test to be sure not *mutating* state object but rather returning new!
   let initialState = {};
   const tracked = mutationTracker.trackObj(initialState);
   misc.blipUrls(initialState, {
     type: actionTypes.SET_NEW_PATIENT_URL,
     payload: actionPayload
   });
   expect(mutationTracker.hasMutated(tracked)).to.be.false;
 });
 it('should handle SET_FORGOT_PASSWORD_URL', () => {
   const FORGOT_PWD = 'http://www.acme.com/forgot-password';
   const actionPayload = {url: FORGOT_PWD};
   expect(misc.blipUrls(undefined, {
     type: actionTypes.SET_FORGOT_PASSWORD_URL,
     payload: actionPayload
   }).forgotPassword).to.equal(FORGOT_PWD);
   // test to be sure not *mutating* state object but rather returning new!
   let initialState = {};
   const tracked = mutationTracker.trackObj(initialState);
   let finalState = misc.blipUrls(initialState, {
     type: actionTypes.SET_FORGOT_PASSWORD_URL,
     payload: actionPayload
   });
   expect(mutationTracker.hasMutated(tracked)).to.be.false;
 });
    it('should set state to an array of pending invites', () => {
      let initialStateForTest = [];
      let tracked = mutationTracker.trackObj(initialStateForTest);

      let pendingSentInvites = [
        { inviteid: 'xyz123zyx' },
        { inviteid: 'abc987cba' }
      ];

      let action = actions.sync.fetchPendingSentInvitesSuccess(pendingSentInvites);

      let state = reducer(initialStateForTest, action);

      expect(state.length).to.equal(pendingSentInvites.length);
      expect(mutationTracker.hasMutated(tracked)).to.be.false;
    });
      it('should set the perms for the logged-in user on targetUserId/"self"', () => {
        const user = {
          userid: 'd4e5f6',
          permissions: {root: {}}
        };

        let initialStateForTest = {};
        let tracked = mutationTracker.trackObj(initialStateForTest);

        let action = actions.sync.loginSuccess(user);

        let state = reducer(initialStateForTest, action);

        expect(Object.keys(state).length).to.equal(1);
        expect(mutationTracker.hasMutated(tracked)).to.be.false;
      });
 it('should handle SET_SIGNUP_URL', () => {
   const SIGN_UP = 'http://www.acme.com/sign-up';
   const actionPayload = {url: SIGN_UP};
   expect(misc.blipUrls(undefined, {
     type: actionTypes.SET_SIGNUP_URL,
     payload: actionPayload
   }).signUp).to.equal(SIGN_UP);
   // test to be sure not *mutating* state object but rather returning new!
   let initialState = {};
   const tracked = mutationTracker.trackObj(initialState);
   let finalState = misc.blipUrls(initialState, {
     type: actionTypes.SET_SIGNUP_URL,
     payload: actionPayload
   });
   expect(mutationTracker.hasMutated(tracked)).to.be.false;
 });
 it('should handle SET_BLIP_VIEW_DATA_URL', () => {
   const VIEW_DATA_LINK = 'http://www.acme.com/patients/a1b2c3/data';
   const actionPayload = {url: VIEW_DATA_LINK};
   expect(misc.blipUrls(undefined, {
     type: actionTypes.SET_BLIP_VIEW_DATA_URL,
     payload: actionPayload
   }).viewDataLink).to.equal(VIEW_DATA_LINK);
   // test to be sure not *mutating* state object but rather returning new!
   let initialState = {};
   const tracked = mutationTracker.trackObj(initialState);
   let finalState = misc.blipUrls(initialState, {
     type: actionTypes.SET_BLIP_VIEW_DATA_URL,
     payload: actionPayload
   });
   expect(mutationTracker.hasMutated(tracked)).to.be.false;
 });
    it('should push new invitation to state', () => {
      let initialStateForTest = [
        { inviteid: 'xyz123zyx' },
        { inviteid: 'abc987cba' }
      ];
      let tracked = mutationTracker.trackObj(initialStateForTest);

      let invitation = { inviteid: 'def456fed' };

      let action = actions.sync.sendInviteSuccess(invitation);

      let state = reducer(initialStateForTest, action);

      expect(state.length).to.equal(initialStateForTest.length + 1);
      expect(mutationTracker.hasMutated(tracked)).to.be.false;
    });
Exemple #18
0
    it('should update the profile with patient info for the user', () => {
      let initialStateForTest = {
        a1b2c3:  { userid: 'a1b2c3' }
      };

      let tracked = mutationTracker.trackObj(initialStateForTest);

      let patient = { userid: 'a1b2c3', name: 'Xavier', profile: { foo: 'bar' } };

      let action = actions.sync.setupDataStorageSuccess('a1b2c3', patient)

      let state = reducer(initialStateForTest, action);

      expect(Object.keys(state).length).to.equal(1);
      expect(state[patient.userid].profile).to.equal(patient.profile);
      expect(mutationTracker.hasMutated(tracked)).to.be.false;
    });
Exemple #19
0
    it('should update the termsAccepted date for the user', () => {
      let initialStateForTest = {
        a1b2c3: { userid: 'a1b2c3', name: 'Xavier', termsAccepted: '' }
      };

      let tracked = mutationTracker.trackObj(initialStateForTest);

      let acceptedDate = new Date();

      let action = actions.sync.acceptTermsSuccess('a1b2c3', acceptedDate);

      let state = reducer(initialStateForTest, action);

      expect(Object.keys(state).length).to.equal(Object.keys(initialStateForTest).length);
      expect(state['a1b2c3'].termsAccepted).to.equal(acceptedDate);
      expect(mutationTracker.hasMutated(tracked)).to.be.false;
    });
Exemple #20
0
    it('should add fetched patients to state when they do not currently exist in state', () => {
      let initialStateForTest = {};
      let tracked = mutationTracker.trackObj(initialStateForTest);

      let patients = [
        {userid: 'a1b2c3'},
        {userid: 'd4e5f6'}
      ];

      let action = actions.sync.fetchPatientsSuccess(patients);
      let state = reducer(initialStateForTest, action);

      expect(Object.keys(state).length).to.equal(2);
      expect(state[patients[0].userid]).to.exist;
      expect(state[patients[1].userid]).to.exist;
      expect(mutationTracker.hasMutated(tracked)).to.be.false;
    });
    it('should remove member from hash map', () => {
      let patientId = 'a1b2c3';

      let initialStateForTest = {
        'a1b2c3': { foo: 'bar' },
        'd4e5f6': { a: 1 }
      };
      let tracked = mutationTracker.trackObj(initialStateForTest);
      
      let action = actions.sync.removeMemberFromTargetCareTeamSuccess(patientId);

      let state = reducer(initialStateForTest, action);

      expect(Object.keys(state).length).to.equal(1);
      expect(state['a1b2c3']).to.be.undefined;
      expect(mutationTracker.hasMutated(tracked)).to.be.false;
    });
Exemple #22
0
    it('should update the user', () => {
      let initialStateForTest = {
        a1b2c3:  { userid: 'a1b2c3' }
      };
      
      let tracked = mutationTracker.trackObj(initialStateForTest);

      let user = { userid: 'a1b2c3', name: 'Xavier', profile: { foo: 'bar' } };

      let action = actions.sync.updateUserSuccess('a1b2c3', user)

      let state = reducer(initialStateForTest, action);

      expect(Object.keys(state).length).to.equal(1);

      expect(state[user.userid].profile).to.equal(user.profile);
      expect(mutationTracker.hasMutated(tracked)).to.be.false;
    });
    it('should remove invitation from state array', () => {
      let initialStateForTest = [
        { inviteid: 'xyz123zyx', email: 'g@g.com' },
        { inviteid: 'abc987cba', email: 'a@a.com' }
      ];
      let tracked = mutationTracker.trackObj(initialStateForTest);

      let removedEmail = 'g@g.com';

      let action = actions.sync.cancelSentInviteSuccess(removedEmail);

      let state = reducer(initialStateForTest, action);

      expect(state.length).to.equal(initialStateForTest.length - 1);
      expect(_.find(state, {email: removedEmail})).to.be.undefined;
      expect(state[0].email).to.equal('a@a.com');
      expect(mutationTracker.hasMutated(tracked)).to.be.false;
    });
 it('should handle HIDE_UNAVAILABLE_DEVICES [win]', () => {
   let actualResult = misc.devices(undefined, {
     type: actionTypes.HIDE_UNAVAILABLE_DEVICES,
     payload: {os: 'win'}
   });
   let expectedResult = _.pick(devices, filterDevicesFn('win'));
   expect(actualResult).to.deep.equal(expectedResult);
   // because nothing currently is unavailable on Windows
   expect(Object.keys(actualResult).length).to.equal(Object.keys(devices).length);
   // test to be sure not *mutating* state object but rather returning new!
   let prevState = devices;
   const tracked = mutationTracker.trackObj(prevState);
   let resultState = misc.devices(prevState, {
     type: actionTypes.HIDE_UNAVAILABLE_DEVICES,
     payload: {os: 'win'}
   });
   expect(mutationTracker.hasMutated(tracked)).to.be.false;
 });
Exemple #25
0
    it('should add the invite creator when it does not currently exist in state', () => {
      let initialStateForTest = {};
      let tracked = mutationTracker.trackObj(initialStateForTest);

      let acceptedReceivedInvite = {
        key: 'xyz987zyx',
        creator: {
          userid: 'a1b2c3',
          profile: {fullName: 'Jenny'}
        }
      };

      let action = actions.sync.acceptReceivedInviteSuccess(acceptedReceivedInvite);
      let state = reducer(initialStateForTest, action);

      expect(Object.keys(state).length).to.equal(1);
      expect(state[acceptedReceivedInvite.creator.userid]).to.exist;
      expect(mutationTracker.hasMutated(tracked)).to.be.false;
    });
    it('should set state to a hash map of patientNotes', () => {
      let initialStateForTest = {};
      let tracked = mutationTracker.trackObj(initialStateForTest);

      let patientId = 'a1b2c3';
      let patientNotes = [
        { message: 'Hello there' },
        { message: 'This is fun!' }
      ];

      let action = actions.sync.fetchPatientDataSuccess(patientId, null, patientNotes);

      let state = reducer(initialStateForTest, action);

      expect(Object.keys(state).length).to.equal(1);
      expect(state[patientId].length).to.equal(patientNotes.length);
      expect(state[patientId]).to.deep.equal(patientNotes);
      expect(mutationTracker.hasMutated(tracked)).to.be.false;
    });
    it('should set state to empty hash map', () => {
      let initialStateForTest = {
        a1b2c3: [
          { value: 100 },
          { value: 20 }
        ],
        d4e5f6: [
          { value: 34 }
        ]
      };
      let tracked = mutationTracker.trackObj(initialStateForTest);

      let action = actions.sync.fetchPatientDataFailure();
      let state = reducer(initialStateForTest, action);

      expect(Object.keys(state).length).to.equal(0);
      expect(state).to.deep.equal({});
      expect(mutationTracker.hasMutated(tracked)).to.be.false;
    });
    it('should set state to a hash map of patientData', () => {
      let initialStateForTest = {};
      let tracked = mutationTracker.trackObj(initialStateForTest);

      let patientId = 'a1b2c3';
      let patientData = [
        { value: 100 },
        { value: 20 }
      ];

      let action = actions.sync.fetchPatientDataSuccess(patientId, patientData);

      let state = reducer(initialStateForTest, action);

      expect(Object.keys(state).length).to.equal(1);
      expect(state[patientId].length).to.equal(patientData.length);
      expect(state[patientId]).to.deep.equal(patientData);
      expect(mutationTracker.hasMutated(tracked)).to.be.false;
    });
    it('should set state to empty hash map', () => {
      let initialStateForTest = {
        a1b2c3: [
          { message: 'Hello there' },
          { message: 'This is fun!' }
        ],
        d4e5f6: [
          { message: 'Awesome sauce!' }
        ]
      };
      let tracked = mutationTracker.trackObj(initialStateForTest);

      let action = actions.sync.fetchPatientDataFailure();
      let state = reducer(initialStateForTest, action);

      expect(Object.keys(state).length).to.equal(0);
      expect(state).to.deep.equal({});
      expect(mutationTracker.hasMutated(tracked)).to.be.false;
    });
 it('should handle HIDE_UNAVAILABLE_DEVICES [win]', () => {
   let actualResult = misc.devices(undefined, {
     type: actionTypes.HIDE_UNAVAILABLE_DEVICES,
     payload: {os: 'win'}
   });
   let expectedResult = _.pickBy(devices, filterDevicesFn('win'));
   expect(actualResult).to.deep.equal(expectedResult);
   // at least one device may be unavailable on Windows, so available devices
   // could be less or equal to total number of devices
   expect(_.keys(actualResult).length).to.be.at.most(_.keys(devices).length);
   // test to be sure not *mutating* state object but rather returning new!
   let prevState = devices;
   const tracked = mutationTracker.trackObj(prevState);
   misc.devices(prevState, {
     type: actionTypes.HIDE_UNAVAILABLE_DEVICES,
     payload: {os: 'win'}
   });
   expect(mutationTracker.hasMutated(tracked)).to.be.false;
 });