error-toast-test.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import Ember from 'ember';
  2. import { module, test } from 'qunit';
  3. import startApp from '../helpers/start-app';
  4. import getToastMessage from '../helpers/toast-message';
  5. var application;
  6. module('Acceptance: Application Error Handler', {
  7. beforeEach: function() {
  8. application = startApp();
  9. },
  10. afterEach: function() {
  11. Ember.run(application, 'destroy');
  12. Ember.$.mockjax.clear();
  13. }
  14. });
  15. test('some unhandled error occured', function(assert) {
  16. assert.expect(1);
  17. Ember.$.mockjax({
  18. url: '/api/auth/login/',
  19. status: 500
  20. });
  21. visit('/');
  22. click('.guest-nav .btn-login');
  23. fillIn('#loginModal .form-group:first-child input', 'SomeFake');
  24. fillIn('#loginModal .form-group:last-child input', 'pass1234');
  25. click('#loginModal .btn-primary');
  26. andThen(function() {
  27. assert.equal(getToastMessage(), 'Unknown error has occured.');
  28. });
  29. });
  30. test('app went away', function(assert) {
  31. assert.expect(1);
  32. Ember.$.mockjax({
  33. url: '/api/auth/login/',
  34. status: 0
  35. });
  36. visit('/');
  37. click('.guest-nav .btn-login');
  38. fillIn('#loginModal .form-group:first-child input', 'SomeFake');
  39. fillIn('#loginModal .form-group:last-child input', 'pass1234');
  40. click('#loginModal .btn-primary');
  41. andThen(function() {
  42. assert.equal(getToastMessage(), 'Lost connection with application.');
  43. });
  44. });
  45. test('not found', function(assert) {
  46. assert.expect(1);
  47. Ember.$.mockjax({
  48. url: '/api/auth/login/',
  49. status: 404,
  50. responseText: {
  51. 'detail': 'Not found'
  52. }
  53. });
  54. visit('/');
  55. click('.guest-nav .btn-login');
  56. fillIn('#loginModal .form-group:first-child input', 'SomeFake');
  57. fillIn('#loginModal .form-group:last-child input', 'pass1234');
  58. click('#loginModal .btn-primary');
  59. andThen(function() {
  60. assert.equal(getToastMessage(), 'Action link is invalid.');
  61. });
  62. });
  63. test('permission denied', function(assert) {
  64. assert.expect(1);
  65. Ember.$.mockjax({
  66. url: '/api/auth/login/',
  67. status: 403,
  68. responseText: {
  69. 'detail': 'Permission denied'
  70. }
  71. });
  72. visit('/');
  73. click('.guest-nav .btn-login');
  74. fillIn('#loginModal .form-group:first-child input', 'SomeFake');
  75. fillIn('#loginModal .form-group:last-child input', 'pass1234');
  76. click('#loginModal .btn-primary');
  77. andThen(function() {
  78. assert.equal(getToastMessage(), "You don't have permission to perform this action.");
  79. });
  80. });
  81. test('permission denied with reason', function(assert) {
  82. assert.expect(1);
  83. Ember.$.mockjax({
  84. url: '/api/auth/login/',
  85. status: 403,
  86. responseText: {
  87. 'detail': 'Lorem ipsum dolor met.'
  88. }
  89. });
  90. visit('/');
  91. click('.guest-nav .btn-login');
  92. fillIn('#loginModal .form-group:first-child input', 'SomeFake');
  93. fillIn('#loginModal .form-group:last-child input', 'pass1234');
  94. click('#loginModal .btn-primary');
  95. andThen(function() {
  96. assert.equal(getToastMessage(), 'Lorem ipsum dolor met.');
  97. });
  98. });