ember_reopen_test.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. require('utils/ember_reopen');
  19. describe('Ember functionality extension', function () {
  20. describe('#Em.View', function () {
  21. var view,
  22. cases = [
  23. {
  24. result: {
  25. p0: 'v3',
  26. p1: 'v4',
  27. p2: 'v5'
  28. },
  29. title: 'active view'
  30. },
  31. {
  32. result: {
  33. p0: 'v0',
  34. p1: 'v1',
  35. p2: 'v2'
  36. },
  37. propertyToSet: 'isDestroyed',
  38. title: 'destroyed view'
  39. },
  40. {
  41. result: {
  42. p0: 'v0',
  43. p1: 'v1',
  44. p2: 'v2'
  45. },
  46. propertyToSet: 'isDestroying',
  47. title: 'view being destroyed'
  48. }
  49. ];
  50. beforeEach(function () {
  51. view = Em.View.create({
  52. isDestroyed: false,
  53. isDestroying: false,
  54. p0: 'v0',
  55. p1: 'v1',
  56. p2: 'v2'
  57. });
  58. });
  59. cases.forEach(function (item) {
  60. it(item.title, function () {
  61. if (item.propertyToSet) {
  62. view.set(item.propertyToSet, true);
  63. }
  64. view.set('p0', 'v3');
  65. view.setProperties({
  66. p1: 'v4',
  67. p2: 'v5'
  68. });
  69. expect(view.getProperties(['p0', 'p1', 'p2'])).to.eql(item.result);
  70. });
  71. });
  72. });
  73. describe('#Em.Route', function() {
  74. describe('#serializeQueryParams', function() {
  75. var route,
  76. cases = [
  77. {
  78. m: 'No query params',
  79. params: undefined,
  80. e: {
  81. result: {query: ''},
  82. serializedQuery: {}
  83. }
  84. },
  85. {
  86. m: 'Query params ?param1=value1&param2=value2',
  87. params: { query: '?param1=value1&param2=value2'},
  88. e: {
  89. result: {query: '?param1=value1&param2=value2'},
  90. serializedQuery: {param1: 'value1', param2: 'value2'}
  91. }
  92. },
  93. {
  94. m: 'Query params with encodedComponent ?param1=value1%30&param2=value2',
  95. params: { query: '?param1=value1%30&param2=value2'},
  96. e: {
  97. result: {query: '?param1=value1%30&param2=value2'},
  98. serializedQuery: {param1: 'value10', param2: 'value2'}
  99. }
  100. }
  101. ];
  102. beforeEach(function() {
  103. route = Ember.Route.create({
  104. route: 'demo:query',
  105. serialize: function(router, params) {
  106. return this.serializeQueryParams(router, params, 'testController');
  107. }
  108. });
  109. });
  110. afterEach(function() {
  111. route.destroy();
  112. route = null;
  113. });
  114. cases.forEach(function(test) {
  115. it(test.m, function() {
  116. var ctrl = Em.Object.create({});
  117. var router = Em.Object.create({
  118. testController: ctrl
  119. });
  120. var ret = route.serialize(router, test.params);
  121. expect(ret).to.be.eql(test.e.result);
  122. expect(ctrl.get('serializedQuery')).to.be.eql(test.e.serializedQuery);
  123. });
  124. });
  125. });
  126. });
  127. });