login-test.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import Ember from 'ember';
  2. import { module, test } from 'qunit';
  3. import startApp from '../helpers/start-app';
  4. var application;
  5. module('Acceptance: Login', {
  6. beforeEach: function() {
  7. application = startApp();
  8. },
  9. afterEach: function() {
  10. Ember.$('#loginModal').off();
  11. Ember.$('body').removeClass('modal-open');
  12. Ember.run(application, 'destroy');
  13. Ember.$.mockjax.clear();
  14. }
  15. });
  16. test('login with empty credentials', function(assert) {
  17. visit('/');
  18. click('.guest-nav button.btn-login');
  19. click('#loginModal .btn-primary');
  20. andThen(function() {
  21. var error = Ember.$.trim(find('.flash-message p').text());
  22. assert.equal(error, 'Fill out both fields.');
  23. });
  24. });
  25. test('login with invalid credentials', function(assert) {
  26. var message = 'Login or password is incorrect.';
  27. Ember.$.mockjax({
  28. url: "/api/auth/login/",
  29. status: 400,
  30. responseText: {
  31. 'detail': message,
  32. 'code': 'invalid_login'
  33. }
  34. });
  35. visit('/');
  36. click('.guest-nav .btn-login');
  37. fillIn('#loginModal .form-group:first-child input', 'SomeFake');
  38. fillIn('#loginModal .form-group:last-child input', 'pass1234');
  39. click('#loginModal .btn-primary');
  40. andThen(function() {
  41. var error = Ember.$.trim(find('.flash-message p').text());
  42. assert.equal(error, message);
  43. });
  44. });
  45. test('login to user-activated account', function(assert) {
  46. var message = 'You have to activate your account before you will be able to sign in.';
  47. Ember.$.mockjax({
  48. url: "/api/auth/login/",
  49. status: 400,
  50. responseText: {
  51. 'detail': message,
  52. 'code': 'inactive_user'
  53. }
  54. });
  55. visit('/');
  56. click('.guest-nav .btn-login');
  57. fillIn('#loginModal .form-group:first-child input', 'SomeFake');
  58. fillIn('#loginModal .form-group:last-child input', 'pass1234');
  59. click('#loginModal .btn-primary');
  60. andThen(function() {
  61. var error = Ember.$.trim(find('.flash-message p').text());
  62. assert.equal(error, message);
  63. });
  64. });
  65. test('login to admin-activated account', function(assert) {
  66. var message = 'Your account has to be activated by Administrator before you will be able to sign in.';
  67. Ember.$.mockjax({
  68. url: "/api/auth/login/",
  69. status: 400,
  70. responseText: {
  71. 'detail': message,
  72. 'code': 'inactive_admin'
  73. }
  74. });
  75. visit('/');
  76. click('.guest-nav .btn-login');
  77. fillIn('#loginModal .form-group:first-child input', 'SomeFake');
  78. fillIn('#loginModal .form-group:last-child input', 'pass1234');
  79. click('#loginModal .btn-primary');
  80. andThen(function() {
  81. var error = Ember.$.trim(find('.flash-message p').text());
  82. assert.equal(error, message);
  83. });
  84. });
  85. test('login to banned account', function(assert) {
  86. var done = assert.async();
  87. Ember.$.mockjax({
  88. url: "/api/auth/login/",
  89. status: 400,
  90. responseText: {
  91. 'detail': {
  92. 'expires_on': null,
  93. 'message': {
  94. 'plain': 'You are banned for trolling.',
  95. 'html': '<p>You are banned for trolling.</p>',
  96. }
  97. },
  98. 'code': 'banned'
  99. }
  100. });
  101. visit('/');
  102. click('.guest-nav .btn-login');
  103. fillIn('#loginModal .form-group:first-child input', 'SomeFake');
  104. fillIn('#loginModal .form-group:last-child input', 'pass1234');
  105. click('#loginModal .btn-primary');
  106. andThen(function() {
  107. var errorMessage = find('.lead p').text();
  108. assert.equal(errorMessage, 'You are banned for trolling.');
  109. var expirationMessage = find('.error-message>p').text();
  110. assert.equal(expirationMessage, 'This ban is permanent.');
  111. done();
  112. });
  113. });