user_test.js 3.2 KB

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