829fe3d2 by David Han Sze Chuen

- update jasmine test case to verify that the checked/unchecked routines work pr…

…operly when we assign a truthy/falsey model value
1 parent 8b6b1ebe
1 describe('Routines', function() { 1 describe('Routines', function() {
2 var el, input, radioBox; 2 var el, input, trueRadioInput, falseRadioInput;
3 3
4 beforeEach(function() { 4 beforeEach(function() {
5 rivets.configure({ 5 rivets.configure({
...@@ -18,17 +18,25 @@ describe('Routines', function() { ...@@ -18,17 +18,25 @@ describe('Routines', function() {
18 input.setAttribute('type', 'text'); 18 input.setAttribute('type', 'text');
19 document.body.appendChild(input); 19 document.body.appendChild(input);
20 20
21 // to test the radio box scenario 21 // to test the radio input scenario when its value is "true"
22 radioBox = document.createElement('input'); 22 trueRadioInput = document.createElement('input');
23 radioBox.setAttribute('type', 'radio'); 23 trueRadioInput.setAttribute('type', 'radio');
24 document.body.appendChild(radioBox); 24 trueRadioInput.value = 'true';
25 document.body.appendChild(trueRadioInput);
26
27 // to test the radio input scenario when its value is "false"
28 falseRadioInput = document.createElement('input');
29 falseRadioInput.setAttribute('type', 'radio');
30 falseRadioInput.value = 'false';
31 document.body.appendChild(falseRadioInput);
25 32
26 }); 33 });
27 34
28 afterEach(function(){ 35 afterEach(function(){
29 el.parentNode.removeChild(el); 36 el.parentNode.removeChild(el);
30 input.parentNode.removeChild(input); 37 input.parentNode.removeChild(input);
31 radioBox.parentNode.removeChild(radioBox); 38 trueRadioInput.parentNode.removeChild(trueRadioInput);
39 falseRadioInput.parentNode.removeChild(falseRadioInput);
32 }); 40 });
33 41
34 describe('text', function() { 42 describe('text', function() {
...@@ -141,33 +149,69 @@ describe('Routines', function() { ...@@ -141,33 +149,69 @@ describe('Routines', function() {
141 }); 149 });
142 150
143 describe('checked', function() { 151 describe('checked', function() {
144 describe('with a truthy value', function() { 152 describe('with a radio input with value="true"', function() {
145 it('checks the element', function() { 153 describe('and a truthy value', function() {
146 rivets.binders.checked.routine(el, true); 154 it('checks the radio input', function() {
147 expect(el.checked).toBe(true); 155 rivets.binders.checked.routine(trueRadioInput, true);
156 expect(trueRadioInput.checked).toBe(true);
157 });
158 });
159
160 describe('with a falsey value', function() {
161 it('unchecks the radio input', function() {
162 rivets.binders.checked.routine(trueRadioInput, false);
163 expect(trueRadioInput.checked).toBe(false);
164 });
148 }); 165 });
149 }); 166 });
150 167
151 describe('with a falsey value', function() { 168 describe('with a radio input with value="false"', function() {
152 it('unchecks the element', function() { 169 describe('and a truthy value', function() {
153 rivets.binders.checked.routine(el, false); 170 it('checks the radio input', function() {
154 expect(el.checked).toBe(false); 171 rivets.binders.checked.routine(falseRadioInput, true);
172 expect(falseRadioInput.checked).toBe(false);
173 });
174 });
175
176 describe('with a falsey value', function() {
177 it('unchecks the radio input', function() {
178 rivets.binders.checked.routine(falseRadioInput, false);
179 expect(falseRadioInput.checked).toBe(true);
180 });
155 }); 181 });
156 }); 182 });
157 }); 183 });
158 184
159 describe('unchecked', function() { 185 describe('unchecked', function() {
160 describe('with a truthy value', function() { 186 describe('with a radio input with value="true"', function() {
161 it('unchecks the element', function() { 187 describe('and a truthy value', function() {
162 rivets.binders.unchecked.routine(el, true); 188 it('checks the radio input', function() {
163 expect(el.checked).toBe(false); 189 rivets.binders.unchecked.routine(trueRadioInput, true);
190 expect(trueRadioInput.checked).toBe(false);
191 });
192 });
193
194 describe('with a falsey value', function() {
195 it('unchecks the radio input', function() {
196 rivets.binders.unchecked.routine(trueRadioInput, false);
197 expect(trueRadioInput.checked).toBe(true);
198 });
164 }); 199 });
165 }); 200 });
166 201
167 describe('with a falsey value', function() { 202 describe('with a radio input with value="false"', function() {
168 it('checks the element', function() { 203 describe('and a truthy value', function() {
169 rivets.binders.unchecked.routine(el, false); 204 it('checks the radio input', function() {
170 expect(el.checked).toBe(true); 205 rivets.binders.unchecked.routine(falseRadioInput, true);
206 expect(falseRadioInput.checked).toBe(true);
207 });
208 });
209
210 describe('with a falsey value', function() {
211 it('unchecks the radio input', function() {
212 rivets.binders.unchecked.routine(falseRadioInput, false);
213 expect(falseRadioInput.checked).toBe(false);
214 });
171 }); 215 });
172 }); 216 });
173 }); 217 });
......