registration-test.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. import Ember from 'ember';
  2. import { module, test } from 'qunit';
  3. import startApp from '../helpers/start-app';
  4. import PreloadStore from 'misago/services/preload-store';
  5. import destroyModal from '../helpers/destroy-modal';
  6. import getToastMessage from '../helpers/toast-message';
  7. var application;
  8. module('Acceptance: Register', {
  9. beforeEach: function() {
  10. application = startApp();
  11. },
  12. afterEach: function() {
  13. window.MisagoData['misagoSettings']['account_activation'] = 'none';
  14. destroyModal();
  15. Ember.run(application, 'destroy');
  16. Ember.$.mockjax.clear();
  17. }
  18. });
  19. test('registration is closed', function(assert) {
  20. window.MisagoData['misagoSettings']['account_activation'] = 'closed';
  21. assert.expect(1);
  22. visit('/');
  23. click('.navbar-guest-nav button.btn-success');
  24. andThen(function() {
  25. assert.equal(Ember.$.trim(find('.modal-register-closed .lead').text()), 'New registrations are currently not being accepted.');
  26. });
  27. });
  28. test('register with empty credentials', function(assert) {
  29. assert.expect(1);
  30. visit('/');
  31. click('.navbar-guest-nav button.btn-success');
  32. click('#appModal .btn-primary');
  33. andThen(function() {
  34. assert.equal(getToastMessage(), 'Fill out all fields.');
  35. });
  36. });
  37. test('register with invalid credentials', function(assert) {
  38. assert.expect(1);
  39. visit('/');
  40. click('.navbar-guest-nav button.btn-success');
  41. fillIn('#appModal #id_username', 'a');
  42. fillIn('#appModal #id_password', 'b');
  43. fillIn('#appModal #id_email', 'c');
  44. click('#appModal .btn-primary');
  45. andThen(function() {
  46. assert.equal(getToastMessage(), 'Form contains errors.');
  47. });
  48. });
  49. test('register with rejected credentials', function(assert) {
  50. assert.expect(1);
  51. Ember.$.mockjax({
  52. url: "/api/users/",
  53. status: 400
  54. });
  55. visit('/');
  56. click('.navbar-guest-nav button.btn-success');
  57. fillIn('#appModal #id_username', 'Lorem');
  58. fillIn('#appModal #id_password', 'ipsum123');
  59. fillIn('#appModal #id_email', 'lorem@ipsum.com');
  60. click('#appModal .btn-primary');
  61. andThen(function() {
  62. assert.equal(getToastMessage(), 'Form contains errors.');
  63. });
  64. });
  65. test('register banned', function(assert) {
  66. assert.expect(3);
  67. Ember.$.mockjax({
  68. url: "/api/users/",
  69. status: 403,
  70. responseText: {
  71. 'detail': 'Thy are banned!',
  72. 'ban': {
  73. 'expires_on': null,
  74. 'message': {
  75. 'plain': 'You are banned for trolling.',
  76. 'html': '<p>You are banned for trolling.</p>',
  77. }
  78. }
  79. }
  80. });
  81. visit('/');
  82. click('.navbar-guest-nav button.btn-success');
  83. fillIn('#appModal #id_username', 'Lorem');
  84. fillIn('#appModal #id_password', 'ipsum123');
  85. fillIn('#appModal #id_email', 'lorem@ipsum.com');
  86. click('#appModal .btn-primary');
  87. andThen(function() {
  88. assert.equal(currentPath(), 'error-banned');
  89. var banMessage = find('.lead p').text();
  90. assert.equal(banMessage, 'You are banned for trolling.');
  91. var expirationMessage = Ember.$.trim(find('.error-message>p').text());
  92. assert.equal(expirationMessage, 'This ban is permanent.');
  93. });
  94. });
  95. test('register active user', function(assert) {
  96. assert.expect(1);
  97. Ember.$.mockjax({
  98. url: "/api/users/",
  99. status: 200,
  100. responseText: {
  101. 'activation': 'active',
  102. 'username': 'BobBoberson',
  103. 'email': 'bob@weebl.com'
  104. }
  105. });
  106. visit('/');
  107. click('.navbar-guest-nav button.btn-success');
  108. fillIn('#appModal #id_username', 'Lorem');
  109. fillIn('#appModal #id_password', 'ipsum123');
  110. fillIn('#appModal #id_email', 'lorem@ipsum.com');
  111. click('#appModal .btn-primary');
  112. andThen(function() {
  113. var expectedMessage = 'BobBoberson, your account has been registered successfully.';
  114. assert.equal(Ember.$.trim(find('.modal-register-done .lead').text()), expectedMessage);
  115. });
  116. });
  117. test('register admin-activated user', function(assert) {
  118. assert.expect(1);
  119. Ember.$.mockjax({
  120. url: "/api/users/",
  121. status: 200,
  122. responseText: {
  123. 'activation': 'activation_by_admin',
  124. 'username': 'BobBoberson',
  125. 'email': 'bob@weebl.com'
  126. }
  127. });
  128. visit('/');
  129. click('.navbar-guest-nav button.btn-success');
  130. fillIn('#appModal #id_username', 'Lorem');
  131. fillIn('#appModal #id_password', 'ipsum123');
  132. fillIn('#appModal #id_email', 'lorem@ipsum.com');
  133. click('#appModal .btn-primary');
  134. andThen(function() {
  135. var expectedMessage = 'BobBoberson, your account has been registered successfully, but site administrator has to activate it before you will be able to sing in.';
  136. assert.equal(Ember.$.trim(find('.modal-register-done .lead').text()), expectedMessage);
  137. });
  138. });
  139. test('register self-activated user', function(assert) {
  140. assert.expect(1);
  141. Ember.$.mockjax({
  142. url: "/api/users/",
  143. status: 200,
  144. responseText: {
  145. 'activation': 'activation_by_user',
  146. 'username': 'BobBoberson',
  147. 'email': 'bob@weebl.com'
  148. }
  149. });
  150. visit('/');
  151. click('.navbar-guest-nav button.btn-success');
  152. fillIn('#appModal #id_username', 'Lorem');
  153. fillIn('#appModal #id_password', 'ipsum123');
  154. fillIn('#appModal #id_email', 'lorem@ipsum.com');
  155. click('#appModal .btn-primary');
  156. andThen(function() {
  157. var expectedMessage = 'BobBoberson, your account has been registered successfully, but you have to activate it before you will be able to sign in.';
  158. assert.equal(Ember.$.trim(find('.modal-register-done .lead').text()), expectedMessage);
  159. });
  160. });