user_test.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. var modelSetup = require('test/init_model_test');
  20. require('models/user');
  21. var user,
  22. form,
  23. userNameField,
  24. userData = {
  25. id: 'user'
  26. };
  27. describe('App.User', function () {
  28. beforeEach(function () {
  29. user = App.User.createRecord(userData);
  30. });
  31. afterEach(function () {
  32. modelSetup.deleteRecord(user);
  33. });
  34. describe('#id', function () {
  35. it('should take value from userName', function () {
  36. user.set('userName', 'name');
  37. expect(user.get('id')).to.equal('name');
  38. });
  39. });
  40. describe('#isLdap', function() {
  41. it('User userType value is "LDAP" should return "true"', function() {
  42. user.set('userType', 'LDAP');
  43. expect(user.get('isLdap')).to.be.true;
  44. });
  45. it('User userType value is "LOCAL" should return "false"', function() {
  46. user.set('userType', 'LOCAL');
  47. expect(user.get('isLdap')).to.be.false;
  48. });
  49. });
  50. });
  51. describe('App.CreateUserForm', function () {
  52. beforeEach(function () {
  53. form = App.CreateUserForm.create();
  54. });
  55. describe('#object', function () {
  56. before(function () {
  57. sinon.stub(App, 'get').withArgs('router.mainAdminUserCreateController.content').returns(userData);
  58. });
  59. after(function () {
  60. App.get.restore();
  61. });
  62. it('should take data from controller', function () {
  63. expect(form.get('object')).to.eql(userData);
  64. });
  65. });
  66. describe('#field.userName.toLowerCase', function () {
  67. it('should convert userName into lower case', function () {
  68. userNameField = form.getField('userName');
  69. userNameField.set('value', 'NAME');
  70. expect(userNameField.get('value')).to.equal('name');
  71. });
  72. });
  73. describe('#isValid', function () {
  74. it('should be false as default', function () {
  75. expect(form.isValid()).to.be.false;
  76. });
  77. it('should be true', function () {
  78. form.get('fields').forEach(function (item) {
  79. if (item.get('isRequired')) {
  80. item.set('value', 'value');
  81. }
  82. });
  83. expect(form.isValid()).to.be.true;
  84. });
  85. });
  86. describe('#isWarn', function () {
  87. it('should be false as default', function () {
  88. expect(form.isWarn()).to.be.false;
  89. });
  90. it('should be true', function () {
  91. form.getField('userName').set('value', '1');
  92. expect(form.isWarn()).to.be.true;
  93. });
  94. it('should be false', function () {
  95. form.getField('userName').set('value', 'name');
  96. expect(form.isWarn()).to.be.false;
  97. });
  98. });
  99. });