error-toast-test.js 2.9 KB

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