formatUnavailable.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 helpers = App.TestAliases.helpers;
  19. /**
  20. *
  21. * @param {Em.Object} context
  22. * @param {string} propertyName
  23. * @param {string} dependentKey
  24. */
  25. App.TestAliases.testAsComputedFormatNa = function (context, propertyName, dependentKey) {
  26. describe('#' + propertyName + ' as Em.computed.formatUnavailable', function () {
  27. afterEach(function () {
  28. helpers.smartRestoreGet(context);
  29. });
  30. it('has valid dependent keys', function () {
  31. expect(Em.meta(context).descs[propertyName]._dependentKeys).to.eql([dependentKey]);
  32. });
  33. it('should be `0` if ' + JSON.stringify(dependentKey) + ' is `0`', function () {
  34. helpers.smartStubGet(context, dependentKey, 0)
  35. .propertyDidChange(context, propertyName);
  36. var value = helpers.smartGet(context, propertyName);
  37. expect(value).to.be.equal(0);
  38. });
  39. it('should be `12` if ' + JSON.stringify(dependentKey) + ' is `12`', function () {
  40. helpers.smartStubGet(context, dependentKey, 12)
  41. .propertyDidChange(context, propertyName);
  42. var value = helpers.smartGet(context, propertyName);
  43. expect(value).to.be.equal(12);
  44. });
  45. it('should be `n/a` if ' + JSON.stringify(dependentKey) + ' is not number >= 0', function () {
  46. helpers.smartStubGet(context, dependentKey, null)
  47. .propertyDidChange(context, propertyName);
  48. var value = helpers.smartGet(context, propertyName);
  49. expect(value).to.be.equal(Em.I18n.t('services.service.summary.notAvailable'));
  50. });
  51. });
  52. };