forum-options.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import assert from 'assert';
  2. import React from 'react'; // jshint ignore:line
  3. import ForumOptions from 'misago/components/options/forum-options'; // jshint ignore:line
  4. import snackbar from 'misago/services/snackbar';
  5. import store from 'misago/services/store';
  6. import * as testUtils from 'misago/utils/test-utils';
  7. let snackbarStore = null;
  8. let user = testUtils.mockUser();
  9. describe("Forum Options Form", function() {
  10. beforeEach(function() {
  11. snackbarStore = testUtils.snackbarStoreMock();
  12. snackbar.init(snackbarStore);
  13. testUtils.initEmptyStore(store);
  14. });
  15. afterEach(function() {
  16. testUtils.unmountComponents();
  17. testUtils.snackbarClear(snackbar);
  18. $.mockjax.clear();
  19. });
  20. it("renders", function(done) {
  21. /* jshint ignore:start */
  22. testUtils.render(<ForumOptions user={user} />);
  23. /* jshint ignore:end */
  24. testUtils.onElement('#test-mount .form-horizontal', function() {
  25. assert.ok(true, "component renders");
  26. done();
  27. });
  28. });
  29. it("handles backend rejection", function(done) {
  30. $.mockjax({
  31. url: user.api_url.options,
  32. status: 400,
  33. responseText: {
  34. detail: "Lol nope!"
  35. }
  36. });
  37. /* jshint ignore:start */
  38. testUtils.render(<ForumOptions user={user} />);
  39. /* jshint ignore:end */
  40. snackbarStore.callback(function(message) {
  41. assert.deepEqual(message, {
  42. message: "Please reload page and try again.",
  43. type: 'error'
  44. }, "error message was shown");
  45. done();
  46. });
  47. testUtils.onElement('#test-mount form', function() {
  48. testUtils.simulateSubmit('#test-mount form');
  49. });
  50. });
  51. it("handles backend error", function(done) {
  52. $.mockjax({
  53. url: user.api_url.options,
  54. status: 500
  55. });
  56. /* jshint ignore:start */
  57. testUtils.render(<ForumOptions user={user} />);
  58. /* jshint ignore:end */
  59. snackbarStore.callback(function(message) {
  60. assert.deepEqual(message, {
  61. message: "Unknown error has occured.",
  62. type: 'error'
  63. }, "error message was shown");
  64. done();
  65. });
  66. testUtils.onElement('#test-mount form', function() {
  67. testUtils.simulateSubmit('#test-mount form');
  68. });
  69. });
  70. it("submits successfully", function(done) {
  71. $.mockjax({
  72. url: user.api_url.options,
  73. status: 200,
  74. responseText: {
  75. detail: 'ok'
  76. }
  77. });
  78. /* jshint ignore:start */
  79. testUtils.render(<ForumOptions user={user} />);
  80. /* jshint ignore:end */
  81. snackbarStore.callback(function(message) {
  82. assert.deepEqual(message, {
  83. message: "Your forum options have been changed.",
  84. type: 'success'
  85. }, "success message was shown");
  86. done();
  87. });
  88. testUtils.onElement('#test-mount form', function() {
  89. testUtils.simulateSubmit('#test-mount form');
  90. });
  91. });
  92. });