trc-client-core
Version:
The core of the TRC Client
316 lines (264 loc) • 12.6 kB
JavaScript
// import proxyquire from 'proxyquire';
// import tape from 'tape';
// var RegistrationStore = proxyquire('trc/course/RegistrationStore', {
// 'history/lib/createHashHistory': () => {
// console.log('proxy')
// }
// });
// // console.log(RegistrationStore);
// // import RegistrationActions from 'trc-client-core/src/course/RegistrationActions';
// // import LoadingActions from 'trc-client-core/src/global/LoadingActions';
// // import RouterContainer from 'trc-client-core/src/global/RouterContainer';
// // import NavigationStore from 'trc-client-core/src/global/NavigationStore';
// tape('RegistrationStore.onFetchRegistrationDataFailed', (test) => {
// test.plan(1);
// test.true(true);
// RegistrationStore.init();
// // RegistrationStore.onFetchRegistrationDataFailed();
// // test.equal(RegistrationStore.get('error'), 'undefined cannot enrol staff.', 'adds and an error to state');
// });
// describe('Registration Store', function () {
// sinon.stub(RouterContainer, 'get', function () {
// return {
// transitionTo: function(){}
// };
// });
// sinon.stub(NavigationStore, 'get', function () {
// return {
// toJS: function(){}
// };
// });
// beforeEach(() => {
// RegistrationStore.init();
// });
// describe('onFetchRegistrationDataCompleted', function() {
// it('parses and restructures the payload', function () {
// var payload = [{
// soData: {
// soId: 'foo',
// soNoParticipants: 1
// },
// participantsData: [{
// participantId: 'bar',
// status: 'ENROLL',
// regId: 'baz'
// }]
// }];
// RegistrationStore.onFetchRegistrationDataCompleted(payload);
// expect(RegistrationStore.get('registrations').toJS()).toEqual({
// foo: [{
// participantId: 'bar',
// soId: 'foo',
// regId: 'baz',
// status: 'ENROLL'
// }]
// });
// expect(RegistrationStore.get('soData').toJS()).toEqual({
// foo: {
// soId: 'foo',
// soNoParticipants: 1,
// otherEnrolledParticipants: 0
// }
// });
// });
// });
// describe('onFetchCandidatesCompleted', function() {
// it('parses and restructures the payload', function () {
// RegistrationStore.onFetchCandidatesCompleted([
// {participantId: 'foo'},
// {participantId: 'bar'}
// ]);
// expect(RegistrationStore.get('candidates').toJS()).toEqual({
// foo: {participantId: 'foo'},
// bar: {participantId: 'bar'}
// });
// });
// });
// describe('getFlatListOfEnrollments', function() {
// it('gets a flat array of registrations and cancellations', function () {
// RegistrationStore.setState({
// registrations: {foo: 'bar'},
// cancellations: {baz: 'qux'}
// });
// expect(RegistrationStore.getFlatListOfEnrollments().toJS()).toEqual(['bar', 'qux']);
// });
// });
// describe('onEnrol', function() {
// it('filters out items that already have a status of ENROLL or WAITLIST', () => {
// spyOn(RegistrationActions, 'sendRegistrationData');
// RegistrationStore.setState({
// registrations: {
// foo: [{status: 'ENROLL'}],
// bar: [{status: 'WAITLIST'}]
// }
// });
// RegistrationStore.onEnrol();
// expect(RegistrationActions.sendRegistrationData).toHaveBeenCalledWith([]);
// });
// it('sets each operation to ENROLL', function () {
// spyOn(RegistrationActions, 'sendRegistrationData');
// RegistrationStore.setState({
// registrations: {
// foo: [{}]
// }
// });
// RegistrationStore.onEnrol();
// expect(RegistrationActions.sendRegistrationData).toHaveBeenCalledWith([{operation: 'ENROLL'}]);
// });
// it('changes the operation of UNENROLL and UNWAITLIST to CANCEL and adds the reason message', function () {
// spyOn(RegistrationActions, 'sendRegistrationData');
// RegistrationStore.setState({
// registrations: {
// foo: [{status: 'UNENROLL'}, {status: 'UNWAITLIST'}]
// }
// });
// RegistrationStore.onEnrol({reason: 'lorem ipsum'});
// expect(RegistrationActions.sendRegistrationData).toHaveBeenCalledWith([
// {status: 'UNENROLL', operation:'CANCEL', message: 'lorem ipsum'},
// {status: 'UNWAITLIST', operation:'CANCEL', message: 'lorem ipsum'}
// ]);
// });
// });
// describe('onRequestTraining', function() {
// it('calls RegistrationActions.sendRegistrationData correctly', function () {
// spyOn(RegistrationActions, 'sendRegistrationData');
// RegistrationStore.onRequestTraining('foo', 'bar');
// expect(RegistrationActions.sendRegistrationData).toHaveBeenCalledWith([{
// operation: 'REQUEST',
// participantId: 'foo',
// soId: 'bar'
// }]);
// });
// });
// describe('onSendRegistrationData', function () {
// it('calls the global loading action', function () {
// spyOn(LoadingActions, 'startLoading');
// RegistrationStore.onSendRegistrationData();
// expect(LoadingActions.startLoading).toHaveBeenCalled();
// });
// });
// describe('onSendRegistrationDataFailed', function () {
// it('calls the global loading action', function () {
// spyOn(LoadingActions, 'stopLoading');
// spyOn(LoadingActions, 'flashMessage');
// RegistrationStore.onSendRegistrationDataFailed();
// expect(LoadingActions.stopLoading).toHaveBeenCalled();
// expect(LoadingActions.flashMessage).toHaveBeenCalled();
// });
// });
// describe('onSendRegistrationDataCompleted', function () {
// it('stops the global loading', function () {
// spyOn(LoadingActions, 'stopLoading');
// RegistrationStore.onSendRegistrationDataCompleted();
// expect(LoadingActions.stopLoading).toHaveBeenCalled();
// });
// it('saves successfulRegistrations to state', function () {
// RegistrationStore.onSendRegistrationDataCompleted('foo');
// expect(RegistrationStore.get('successfulRegistrations')).toBe('foo');
// });
// it('clears registrations and cancellations', function () {
// RegistrationStore.onSendRegistrationDataCompleted();
// expect(RegistrationStore.get('registrations')).toBe(null);
// expect(RegistrationStore.get('cancellations').toJS()).toEqual({});
// });
// });
// describe('onAddRegistration', () => {
// it('adds a new registrationShape to a registration list', () => {
// RegistrationStore.setState({
// candidates: {
// participantId_123: {participantId: 'participantId_123'}
// },
// registrations: {}
// });
// RegistrationStore.onAddRegistration('participantId_123', 'soId_456');
// expect(RegistrationStore.get('registrations').get('soId_456').toJS()).toEqual([
// {participantId: 'participantId_123', soId: 'soId_456', regId: undefined, status: undefined}
// ]);
// });
// });
// describe('onUpdateRegistration', () => {
// it('updates an ENROLL status to UNENROLL', () => {
// RegistrationStore.setState({
// candidates: {
// participantId_123: {participantId: 'participantId_123'}
// },
// cancellations: {
// soId_456: []
// },
// registrations: {
// soId_456: [{status: 'ENROLL', participantId: 'participantId_123'}]
// }
// });
// RegistrationStore.onUpdateRegistration('participantId_123', 'soId_456');
// expect(RegistrationStore.get('registrations').get('soId_456').size).toEqual(0);
// expect(RegistrationStore.get('cancellations').get('soId_456').size).toEqual(1);
// expect(RegistrationStore.get('cancellations').get('soId_456').get(0).get('status')).toEqual('UNENROLL');
// });
// it('updates an WAITLIST status to UNWAITLIST', () => {
// RegistrationStore.setState({
// candidates: {
// participantId_123: {participantId: 'participantId_123'}
// },
// cancellations: {
// soId_456: []
// },
// registrations: {
// soId_456: [{status: 'WAITLIST', participantId: 'participantId_123'}]
// }
// });
// RegistrationStore.onUpdateRegistration('participantId_123', 'soId_456');
// expect(RegistrationStore.get('registrations').get('soId_456').size).toEqual(0);
// expect(RegistrationStore.get('cancellations').get('soId_456').size).toEqual(1);
// expect(RegistrationStore.get('cancellations').get('soId_456').get(0).get('status')).toEqual('UNWAITLIST');
// });
// it('updates an UNWAITLIST status to WAITLIST', () => {
// RegistrationStore.setState({
// candidates: {
// participantId_123: {participantId: 'participantId_123'}
// },
// cancellations: {
// soId_456: [{status: 'UNWAITLIST', participantId: 'participantId_123'}]
// },
// registrations: {
// soId_456: []
// }
// });
// RegistrationStore.onUpdateRegistration('participantId_123', 'soId_456');
// expect(RegistrationStore.get('registrations').get('soId_456').size).toEqual(1);
// expect(RegistrationStore.get('cancellations').get('soId_456').size).toEqual(0);
// expect(RegistrationStore.get('registrations').get('soId_456').get(0).get('status')).toEqual('WAITLIST');
// });
// it('updates an UNENROLL status to ENROLL', () => {
// RegistrationStore.setState({
// candidates: {
// participantId_123: {participantId: 'participantId_123'}
// },
// cancellations: {
// soId_456: [{status: 'UNENROLL', participantId: 'participantId_123'}]
// },
// registrations: {
// soId_456: []
// }
// });
// RegistrationStore.onUpdateRegistration('participantId_123', 'soId_456');
// expect(RegistrationStore.get('registrations').get('soId_456').size).toEqual(1);
// expect(RegistrationStore.get('cancellations').get('soId_456').size).toEqual(0);
// expect(RegistrationStore.get('registrations').get('soId_456').get(0).get('status')).toEqual('ENROLL');
// });
// it('deletes something with no status', () => {
// RegistrationStore.setState({
// candidates: {
// participantId_123: {participantId: 'participantId_123'}
// },
// cancellations: {
// soId_456: []
// },
// registrations: {
// soId_456: [{status: undefined, participantId: 'participantId_123'}]
// }
// });
// RegistrationStore.onUpdateRegistration('participantId_123', 'soId_456');
// expect(RegistrationStore.get('registrations').get('soId_456').size).toEqual(0);
// });
// });
// });