register-button.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import assert from 'assert';
  2. import React from 'react'; // jshint ignore:line
  3. import RegisterButton from 'misago/components/register-button'; // jshint ignore:line
  4. import misago from 'misago/index';
  5. import captcha from 'misago/services/captcha';
  6. import modal from 'misago/services/modal';
  7. import snackbar from 'misago/services/snackbar';
  8. import zxcvbn from 'misago/services/zxcvbn';
  9. import * as testUtils from 'misago/utils/test-utils';
  10. let snackbarStore = null;
  11. describe("RegisterButton", function() {
  12. beforeEach(function() {
  13. snackbarStore = testUtils.snackbarStoreMock();
  14. snackbar.init(snackbarStore);
  15. testUtils.initModal(modal);
  16. testUtils.contextClear(misago);
  17. /* jshint ignore:start */
  18. testUtils.render(<RegisterButton />);
  19. /* jshint ignore:end */
  20. });
  21. afterEach(function() {
  22. delete window.zxcvbn;
  23. testUtils.unmountComponents();
  24. });
  25. it("renders", function() {
  26. let element = $('#test-mount button');
  27. assert.ok(element.length, "component rendered");
  28. });
  29. it("alerts about closed registration", function(done) {
  30. misago._context = {
  31. SETTINGS: {
  32. account_activation: 'closed'
  33. }
  34. };
  35. snackbarStore.callback(function(message) {
  36. assert.deepEqual(message, {
  37. message: "New registrations are currently disabled.",
  38. type: 'info'
  39. }, "valid alert is raised");
  40. done();
  41. });
  42. testUtils.simulateClick('#test-mount button');
  43. });
  44. it("opens registration modal", function(done) {
  45. misago._context = {
  46. SETTINGS: {
  47. captcha_type: 'no',
  48. account_activation: 'none'
  49. }
  50. };
  51. captcha.init(misago, {}, {}, {});
  52. zxcvbn.init({
  53. include: function(file) {
  54. assert.equal(file, 'misago/js/zxcvbn.js', "zxcvbn.js is requested");
  55. window.setTimeout(function() {
  56. window.zxcvbn = function() {
  57. return 0;
  58. };
  59. }, 200);
  60. }
  61. });
  62. testUtils.simulateClick('#test-mount button');
  63. testUtils.onElement('#modal-mount .modal-register', function() {
  64. let element = $('#modal-mount .modal-register');
  65. assert.ok(element.length, "registration modal was opened");
  66. done();
  67. });
  68. });
  69. });