request-activation.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. (function () {
  2. 'use strict';
  3. var app = null;
  4. QUnit.acceptance("Request Activation Link", {
  5. beforeEach: function() {
  6. app = initTestMisago();
  7. },
  8. afterEach: function() {
  9. app.destroy();
  10. }
  11. });
  12. QUnit.test('with empty input', function(assert) {
  13. app.router.route('/activation/');
  14. var done = assert.async();
  15. click('.well-form .btn-primary');
  16. onElement('.alerts .alert-danger', function() {
  17. assert.equal(getAlertMessage(), "Enter a valid email address.",
  18. "request form raised alert about empty input.");
  19. done();
  20. });
  21. });
  22. QUnit.test('with invalid email', function(assert) {
  23. app.router.route('/activation/');
  24. var done = assert.async();
  25. fillIn('.well-form input', 'not-email');
  26. click('.well-form .btn-primary');
  27. onElement('.alerts .alert-danger', function() {
  28. assert.equal(getAlertMessage(), "Enter a valid email address.",
  29. "request form raised alert about empty input.");
  30. done();
  31. });
  32. });
  33. QUnit.test('with backend banned', function(assert) {
  34. $.mockjax({
  35. url: '/test-api/auth/send-activation/',
  36. status: 403,
  37. responseText: {
  38. 'detail': 'You are banned!',
  39. 'ban': {
  40. 'expires_on': null,
  41. 'message': {
  42. 'plain': 'This is test ban.',
  43. 'html': '<p>This is test ban.</p>'
  44. }
  45. }
  46. }
  47. });
  48. app.router.route('/activation/');
  49. var done = assert.async();
  50. fillIn('.well-form input', 'valid@email.com');
  51. click('.well-form .btn-primary');
  52. onElement('.page-error.page-error-banned .message-body', function() {
  53. assert.ok(true, "Permission denied error page was displayed.");
  54. assert.equal(
  55. getElementText('.page .message-body .lead'),
  56. "This is test ban.",
  57. "Banned page displayed ban message.");
  58. done();
  59. });
  60. });
  61. QUnit.test('with backend error', function(assert) {
  62. var message = "No user found for email!";
  63. $.mockjax({
  64. url: '/test-api/auth/send-activation/',
  65. status: 400,
  66. responseText: {
  67. 'detail': message
  68. }
  69. });
  70. app.router.route('/activation/');
  71. var done = assert.async();
  72. fillIn('.well-form input', 'valid@email.com');
  73. click('.well-form .btn-primary');
  74. onElement('.alerts .alert-danger', function() {
  75. assert.equal(getAlertMessage(), message,
  76. "request form raised alert returned by backend.");
  77. done();
  78. });
  79. });
  80. QUnit.test('with success', function(assert) {
  81. $.mockjax({
  82. url: '/test-api/auth/send-activation/',
  83. status: 200,
  84. responseText: {
  85. 'username': 'Bob',
  86. 'email': 'bob@boberson.com'
  87. }
  88. });
  89. app.router.route('/activation/');
  90. var done = assert.async();
  91. fillIn('.well-form input', 'valid@email.com');
  92. click('.well-form .btn-primary');
  93. onElement('.message-body p', function() {
  94. assert.equal(
  95. getElementText('.message-body p:nth-child(2)'),
  96. "Bob, we have sent your activation link to bob@boberson.com.",
  97. "request form displayed success message.");
  98. done();
  99. });
  100. });
  101. QUnit.test('reset', function(assert) {
  102. $.mockjax({
  103. url: '/test-api/auth/send-activation/',
  104. status: 200,
  105. responseText: {
  106. 'username': 'Bob',
  107. 'email': 'bob@boberson.com'
  108. }
  109. });
  110. app.router.route('/activation/');
  111. var done = assert.async();
  112. fillIn('.well-form input', 'valid@email.com');
  113. click('.well-form .btn-primary');
  114. waitForElement('.message-body .btn-default');
  115. click('.message-body .btn-default');
  116. onElement('.well-form', function() {
  117. assert.ok(true, 'reset button took client back to previous screen.');
  118. done();
  119. });
  120. });
  121. }());