Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // this tests everything I was pretty much trying to test without worrying about status codes in the axios request.
- describe('LoginForm', () => {
- it('should trigger attemptLogin on form submit.', ()=>{
- const spy = spyOn(cmp.vm, 'attemptLogin')
- cmp.update()
- cmp.vm.username = 'spencercooley'
- cmp.vm.password = 'top_secret'
- const theForm = cmp.find('form');
- theForm.trigger('submit');
- expect(cmp.vm.attemptLogin).toBeCalled()
- });
- it('should have invalid set to true on failed login and show the form with an error message.', () =>{
- let errorResponse = {
- 'response':{
- 'data':{
- 'error': 'invalid_grant',
- 'error_description': 'Invalid credentials given.'
- }
- }
- };
- //the method called when status code is 401
- cmp.vm.authFailure(errorResponse);
- cmp.update();
- expect(cmp.vm.invalid).toBe(true);
- expect(cmp.vm.loading).toBe(false);
- //correct elements are showing.
- expect(cmp.findAll('form').length).toBe(1);
- expect(cmp.findAll('.animated-loader').length).toBe(0);
- //check that an error is present in the dom and the data.
- expect(cmp.vm.submitErrors.length).toBe(1);
- expect(cmp.findAll('li.error').length).toBe(1);
- expect(cmp.vm.submitErrors[0]).toBe('Invalid credentials given.');
- });
- it('should have invalid set to false on successful login and remove the form.', () =>{
- let apiResponse = {
- 'data':{
- 'access_token': 'uYPlFOapaOaElDmW7V0Aq4mY2szJgo',
- 'scope': 'groups write read',
- 'token_type': 'Bearer',
- 'expires_in': 36000,
- 'refresh_token': 'EtQUYtximygPUPACAHKIY7nVmqKM49'
- }
- };
- //the method called when status code is 200
- cmp.vm.authSuccess(apiResponse);
- cmp.update();
- expect(cmp.vm.invalid).toBe(false);
- expect(cmp.vm.loading).toBe(true);
- //correct elements are showing.
- expect(cmp.findAll('form').length).toBe(0);
- expect(cmp.findAll('.animated-loader').length).toBe(1);
- //check that localStorage has been set
- expect(localStorage.getItem('authToken')).toBe('uYPlFOapaOaElDmW7V0Aq4mY2szJgo')
- });
- });
Add Comment
Please, Sign In to add comment