Created
February 7, 2017 21:24
-
-
Save qetr1ck-op/d410d526c57cb8857b23c840eababd81 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import eventTermsCtrl from './terms-controller'; | |
describe('vv.manager.manager.event:EventTermsController', () => { | |
let sut, MimeType, eventService, enumService, FormValidationService, notificationService, eventResolve, isSuccess; | |
beforeEach(() => { | |
MimeType = { | |
pdf: {extensions: []} | |
}; | |
eventService = { | |
patch: jasmine.createSpy('eventService.patch').and.callFake(() => isSuccess ? Promise.resolve() : Promise.reject())) | |
}; | |
enumService = { | |
eventStatusTypes: {}, | |
termsTypes: {}, | |
bookingApprovalTypes: {}, | |
eventTypes: {} | |
}; | |
FormValidationService = {}; | |
notificationService = { | |
parseAndShowServerErrorMessage: jasmine.createSpy('parseAndShowServerErrorMessage') | |
}; | |
eventResolve = { | |
bookingApproval: {}, | |
ticketLimitation: { | |
min: null, | |
max: null | |
} | |
}; | |
sut = new eventTermsCtrl(MimeType, eventService, enumService, FormValidationService, notificationService, eventResolve); | |
}); | |
describe('instance should have correct props', () => { | |
it('rest of public props'); | |
it('ticketLimitation should has a correct structure', () => { | |
let sut; | |
eventResolve.ticketLimitation = {min: 5, max: 10}; | |
sut = new eventTermsCtrl(MimeType, eventService, enumService, FormValidationService, notificationService, eventResolve); | |
expect(sut.ticketLimitation.min).toEqual({checked: true, value: 5}); | |
expect(sut.ticketLimitation.max).toEqual({checked: true, value: 10}); | |
eventResolve.ticketLimitation = {min: 1, max: null}; | |
sut = new eventTermsCtrl(MimeType, eventService, enumService, FormValidationService, notificationService, eventResolve); | |
expect(sut.ticketLimitation.min).toEqual({checked: true, value: 1}); | |
expect(sut.ticketLimitation.max).toEqual({checked: false, value: null}); | |
}); | |
}); | |
describe('editTicketLimitation()', () => { | |
let ngForm = { | |
$invalid: true, | |
$setSubmitted: jasmine.createSpy('$setSubmitted') | |
}; | |
it('should not process data if invalid', () => { | |
sut.editTicketLimitation(ngForm); | |
expect(ngForm.$setSubmitted).toHaveBeenCalled(); | |
}); | |
it('should process and patched data if valid', done => { | |
ngForm.$invalid = false; | |
isSuccess = true; | |
sut.editTicketLimitation(ngForm) | |
.then(() => { | |
expect(sut._eventService.patch).toHaveBeenCalledWith(sut.event.id, { | |
ticketLimitation: { | |
min: sut.ticketLimitation.min.checked ? sut.ticketLimitation.min.value : null, | |
max: sut.ticketLimitation.max.checked ? sut.ticketLimitation.max.value : null | |
} | |
}); | |
expect(sut.loadingState).toBeFalsy(); | |
}) | |
.then(done); | |
}); | |
it('should handle error when patched data', done => { | |
ngForm.$invalid = false; | |
isSuccess = false; | |
sut.editTicketLimitation(ngForm) | |
.then(() => { | |
expect(sut.loadingState).toBeFalsy(); | |
expect(sut._notificationService.parseAndShowServerErrorMessage).toHaveBeenCalled(); | |
}) | |
.then(done); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment