forgotten-password-test.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. import Ember from 'ember';
  2. import { module, test } from 'qunit';
  3. import startApp from '../helpers/start-app';
  4. var application;
  5. module('Acceptance: ForgottenPassword', {
  6. beforeEach: function() {
  7. application = startApp();
  8. },
  9. afterEach: function() {
  10. Ember.run(application, 'destroy');
  11. Ember.$.mockjax.clear();
  12. }
  13. });
  14. test('visiting /forgotten-password', function(assert) {
  15. visit('/forgotten-password');
  16. andThen(function() {
  17. assert.equal(currentPath(), 'forgotten-password.index');
  18. });
  19. });
  20. test('request password change link without entering e-mail', function(assert) {
  21. visit('/forgotten-password');
  22. click('.forgotten-password-page form .btn-primary');
  23. andThen(function() {
  24. assert.equal(currentPath(), 'forgotten-password.index');
  25. var error = Ember.$.trim(find('.flash-message p').text());
  26. assert.equal(error, 'Enter e-mail address.');
  27. });
  28. });
  29. test('request password change link with invalid e-mail', function(assert) {
  30. var message = 'Entered e-mail is invalid.';
  31. Ember.$.mockjax({
  32. url: "/api/change-password/send-link/",
  33. status: 400,
  34. responseText: {
  35. 'detail': message,
  36. 'code': 'invalid_email'
  37. }
  38. });
  39. visit('/forgotten-password');
  40. fillIn('.forgotten-password-page form input', 'not-valid-email');
  41. click('.forgotten-password-page form .btn-primary');
  42. andThen(function() {
  43. assert.equal(currentPath(), 'forgotten-password.index');
  44. var error = Ember.$.trim(find('.flash-message p').text());
  45. assert.equal(error, message);
  46. });
  47. });
  48. test('request password change link with non-existing e-mail', function(assert) {
  49. var message = 'No user with this e-mail exists.';
  50. Ember.$.mockjax({
  51. url: "/api/change-password/send-link/",
  52. status: 400,
  53. responseText: {
  54. 'detail': message,
  55. 'code': 'not_found'
  56. }
  57. });
  58. visit('/forgotten-password');
  59. fillIn('.forgotten-password-page form input', 'not-valid-email');
  60. click('.forgotten-password-page form .btn-primary');
  61. andThen(function() {
  62. assert.equal(currentPath(), 'forgotten-password.index');
  63. var error = Ember.$.trim(find('.flash-message p').text());
  64. assert.equal(error, message);
  65. });
  66. });
  67. test('request password change link with user-activated account', function(assert) {
  68. var message = 'You have to activate your account before you will be able to sign in.';
  69. Ember.$.mockjax({
  70. url: "/api/change-password/send-link/",
  71. status: 400,
  72. responseText: {
  73. 'detail': message,
  74. 'code': 'inactive_user'
  75. }
  76. });
  77. visit('/forgotten-password');
  78. fillIn('.forgotten-password-page form input', 'valid@mail.com');
  79. click('.forgotten-password-page form .btn-primary');
  80. andThen(function() {
  81. assert.equal(currentPath(), 'forgotten-password.index');
  82. var error = Ember.$.trim(find('.flash-message p').text());
  83. assert.equal(error, message);
  84. });
  85. });
  86. test('request password change link with admin-activated account', function(assert) {
  87. var message = 'Your account has to be activated by Administrator before you will be able to sign in.';
  88. Ember.$.mockjax({
  89. url: "/api/change-password/send-link/",
  90. status: 400,
  91. responseText: {
  92. 'detail': message,
  93. 'code': 'inactive_admin'
  94. }
  95. });
  96. visit('/forgotten-password');
  97. fillIn('.forgotten-password-page form input', 'valid@mail.com');
  98. click('.forgotten-password-page form .btn-primary');
  99. andThen(function() {
  100. assert.equal(currentPath(), 'forgotten-password.index');
  101. var error = Ember.$.trim(find('.flash-message p').text());
  102. assert.equal(error, message);
  103. });
  104. });
  105. test('request password change link with banned account', function(assert) {
  106. var done = assert.async();
  107. Ember.$.mockjax({
  108. url: "/api/change-password/send-link/",
  109. status: 400,
  110. responseText: {
  111. 'detail': {
  112. 'expires_on': null,
  113. 'message': {
  114. 'plain': 'You are banned for trolling.',
  115. 'html': '<p>You are banned for trolling.</p>',
  116. }
  117. },
  118. 'code': 'banned'
  119. }
  120. });
  121. visit('/forgotten-password');
  122. fillIn('.forgotten-password-page form input', 'valid@mail.com');
  123. click('.forgotten-password-page form .btn-primary');
  124. andThen(function() {
  125. var errorMessage = find('.lead p').text();
  126. assert.equal(errorMessage, 'You are banned for trolling.');
  127. var expirationMessage = find('.error-message>p').text();
  128. assert.equal(expirationMessage, 'This ban is permanent.');
  129. done();
  130. });
  131. });
  132. test('request password change link', function(assert) {
  133. var done = assert.async();
  134. Ember.$.mockjax({
  135. url: "/api/change-password/send-link/",
  136. status: 200,
  137. responseText: {
  138. 'username': 'BobBoberson',
  139. 'email': 'valid@mail.com'
  140. }
  141. });
  142. visit('/forgotten-password');
  143. fillIn('.forgotten-password-page form input', 'valid@mail.com');
  144. click('.forgotten-password-page form .btn-primary');
  145. andThen(function() {
  146. var pageHeader = Ember.$.trim(find('.page-header h1').text());
  147. assert.equal(pageHeader, 'Change password form link sent');
  148. done();
  149. });
  150. });