authentication_test.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. require('models/authentication');
  20. var form,
  21. methods = [
  22. {
  23. name: 'method',
  24. fields: ['primaryServer', 'searchBaseDn', 'usernameAttribute']
  25. },
  26. {
  27. name: 'bindMethod',
  28. fields: ['bindUser', 'password', 'passwordRetype']
  29. }
  30. ],
  31. classCases = [
  32. {
  33. result: 0,
  34. message: 'fail',
  35. className: 'error'
  36. },
  37. {
  38. result: 1,
  39. message: 'success',
  40. className: 'success'
  41. }
  42. ];
  43. describe('App.AuthenticationForm', function () {
  44. beforeEach(function() {
  45. form = App.AuthenticationForm.create();
  46. });
  47. methods.forEach(function (method) {
  48. method.fields.forEach(function (field) {
  49. describe('#' + field + '.isRequired', function () {
  50. for (var i = 2; i--; ) {
  51. it('should be ' + i + ' dependent on ' + method.name + ' value', function () {
  52. form.getField(method.name).set('value', i);
  53. expect(form.getField(field).get('isRequired')).to.equal(i);
  54. });
  55. }
  56. });
  57. });
  58. });
  59. describe('#testResult', function () {
  60. it('should be 0 or 1', function () {
  61. form.testConfiguration();
  62. expect([0, 1]).to.include(Number(form.get('testResult')));
  63. });
  64. });
  65. describe('#testConfigurationMessage', function () {
  66. classCases.forEach(function (item) {
  67. it('should indicate ' + item.message, function () {
  68. form.set('testResult', item.result);
  69. expect(form.get('testConfigurationMessage')).to.equal(Em.I18n.t('admin.authentication.form.test.' + item.message));
  70. });
  71. });
  72. });
  73. describe('#testConfigurationClass', function () {
  74. classCases.forEach(function (item) {
  75. it('should indicate ' + item.className, function () {
  76. form.set('testResult', item.result);
  77. expect(form.get('testConfigurationClass')).to.equal('text-' + item.className);
  78. });
  79. });
  80. });
  81. });