Guest User

Untitled

a guest
Jan 31st, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. // this tests everything I was pretty much trying to test without worrying about status codes in the axios request.
  2. describe('LoginForm', () => {
  3. it('should trigger attemptLogin on form submit.', ()=>{
  4. const spy = spyOn(cmp.vm, 'attemptLogin')
  5. cmp.update()
  6. cmp.vm.username = 'spencercooley'
  7. cmp.vm.password = 'top_secret'
  8. const theForm = cmp.find('form');
  9. theForm.trigger('submit');
  10. expect(cmp.vm.attemptLogin).toBeCalled()
  11. });
  12.  
  13. it('should have invalid set to true on failed login and show the form with an error message.', () =>{
  14. let errorResponse = {
  15. 'response':{
  16. 'data':{
  17. 'error': 'invalid_grant',
  18. 'error_description': 'Invalid credentials given.'
  19. }
  20. }
  21. };
  22. //the method called when status code is 401
  23. cmp.vm.authFailure(errorResponse);
  24. cmp.update();
  25. expect(cmp.vm.invalid).toBe(true);
  26. expect(cmp.vm.loading).toBe(false);
  27. //correct elements are showing.
  28. expect(cmp.findAll('form').length).toBe(1);
  29. expect(cmp.findAll('.animated-loader').length).toBe(0);
  30. //check that an error is present in the dom and the data.
  31. expect(cmp.vm.submitErrors.length).toBe(1);
  32. expect(cmp.findAll('li.error').length).toBe(1);
  33. expect(cmp.vm.submitErrors[0]).toBe('Invalid credentials given.');
  34. });
  35.  
  36. it('should have invalid set to false on successful login and remove the form.', () =>{
  37. let apiResponse = {
  38. 'data':{
  39. 'access_token': 'uYPlFOapaOaElDmW7V0Aq4mY2szJgo',
  40. 'scope': 'groups write read',
  41. 'token_type': 'Bearer',
  42. 'expires_in': 36000,
  43. 'refresh_token': 'EtQUYtximygPUPACAHKIY7nVmqKM49'
  44. }
  45. };
  46. //the method called when status code is 200
  47. cmp.vm.authSuccess(apiResponse);
  48. cmp.update();
  49. expect(cmp.vm.invalid).toBe(false);
  50. expect(cmp.vm.loading).toBe(true);
  51. //correct elements are showing.
  52. expect(cmp.findAll('form').length).toBe(0);
  53. expect(cmp.findAll('.animated-loader').length).toBe(1);
  54. //check that localStorage has been set
  55. expect(localStorage.getItem('authToken')).toBe('uYPlFOapaOaElDmW7V0Aq4mY2szJgo')
  56. });
  57.  
  58. });
Add Comment
Please, Sign In to add comment