register.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. (function (root, factory) {
  2. define([
  3. "jquery",
  4. "mock",
  5. "test_utils"
  6. ], function ($, mock, test_utils) {
  7. return factory($, mock, test_utils);
  8. }
  9. );
  10. } (this, function ($, mock, test_utils) {
  11. describe("The Registration Panel", $.proxy(function (mock, test_utils) {
  12. beforeEach(function () {
  13. test_utils.openControlBox();
  14. });
  15. afterEach(function () {
  16. test_utils.closeControlBox();
  17. });
  18. it("is not available unless allow_registration=true", $.proxy(function () {
  19. test_utils.closeControlBox();
  20. var connection = mock.mock_connection;
  21. connection.connected = false;
  22. converse._tearDown();
  23. converse.initialize({
  24. animate: false,
  25. auto_subscribe: false,
  26. bosh_service_url: 'localhost',
  27. connection: connection,
  28. no_trimming: true,
  29. allow_registration: false,
  30. debug: true
  31. });
  32. test_utils.openControlBox();
  33. var cbview = this.chatboxviews.get('controlbox');
  34. expect(cbview.$('#controlbox-tabs li').length).toBe(1);
  35. expect(cbview.$('#controlbox-tabs li').text().trim()).toBe("Sign in");
  36. connection = mock.mock_connection;
  37. connection.connected = false;
  38. converse._tearDown();
  39. converse.initialize({
  40. bosh_service_url: 'localhost',
  41. allow_registration: true,
  42. auto_subscribe: false,
  43. animate: false,
  44. connection: connection,
  45. no_trimming: true,
  46. debug: true
  47. });
  48. test_utils.openControlBox();
  49. cbview = this.chatboxviews.get('controlbox');
  50. expect(cbview.$el.find('#controlbox-tabs li').length).toBe(2);
  51. expect(cbview.$('#controlbox-tabs li').first().text().trim()).toBe("Sign in");
  52. expect(cbview.$('#controlbox-tabs li').last().text().trim()).toBe("Register");
  53. }, converse));
  54. it("can be opened by clicking on the registration tab", $.proxy(function () {
  55. var cbview = this.chatboxviews.get('controlbox');
  56. var $tabs = cbview.$('#controlbox-tabs');
  57. var $panels = cbview.$('.controlbox-panes');
  58. var $login = $panels.children().first();
  59. var $registration = $panels.children().last();
  60. spyOn(cbview, 'switchTab').andCallThrough();
  61. cbview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
  62. $tabs.find('li').last().find('a').click(); // Click the Register tab
  63. expect($login.is(':visible')).toBe(false);
  64. expect($registration.is(':visible')).toBe(true);
  65. expect(cbview.switchTab).toHaveBeenCalled();
  66. }, converse));
  67. it("allows the user to choose an XMPP provider's domain", $.proxy(function () {
  68. var cbview = this.chatboxviews.get('controlbox');
  69. var registerview = cbview.registerpanel;
  70. spyOn(registerview, 'onProviderChosen').andCallThrough();
  71. registerview.delegateEvents(); // We need to rebind all events otherwise our spy won't be called
  72. spyOn(this.connection, 'connect');
  73. var $tabs = cbview.$('#controlbox-tabs');
  74. $tabs.find('li').last().find('a').click(); // Click the Register tab
  75. // Check the form layout
  76. var $form = cbview.$('#converse-register');
  77. expect($form.find('input').length).toEqual(2);
  78. expect($form.find('input').first().attr('name')).toEqual('domain');
  79. expect($form.find('input').last().attr('type')).toEqual('submit');
  80. // Check that the input[type=domain] input is required
  81. $form.find('input[type=submit]').click();
  82. expect(registerview.onProviderChosen).toHaveBeenCalled();
  83. expect($form.find('input[name=domain]').hasClass('error')).toBeTruthy();
  84. // Check that the form is accepted if input[type=domain] has a value
  85. $form.find('input[name=domain]').val('conversejs.org');
  86. $form.find('input[type=submit]').click();
  87. expect(registerview.onProviderChosen).toHaveBeenCalled();
  88. expect(this.connection.connect).toHaveBeenCalled();
  89. }, converse));
  90. it("will render a registration form as received from the XMPP provider", $.proxy(function () {
  91. // TODO
  92. }, converse));
  93. }, converse, mock, test_utils));
  94. }));