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);
148 }); 157 });
149 }); 158 });
150 159
151 describe('with a falsey value', function() { 160 describe('with a falsey value', function() {
152 it('unchecks the element', function() { 161 it('unchecks the radio input', function() {
153 rivets.binders.checked.routine(el, false); 162 rivets.binders.checked.routine(trueRadioInput, false);
154 expect(el.checked).toBe(false); 163 expect(trueRadioInput.checked).toBe(false);
164 });
165 });
166 });
167
168 describe('with a radio input with value="false"', function() {
169 describe('and a truthy value', function() {
170 it('checks the radio input', function() {
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 });
199 });
200 });
201
202 describe('with a radio input with value="false"', function() {
203 describe('and a truthy value', function() {
204 it('checks the radio input', function() {
205 rivets.binders.unchecked.routine(falseRadioInput, true);
206 expect(falseRadioInput.checked).toBe(true);
164 }); 207 });
165 }); 208 });
166 209
167 describe('with a falsey value', function() { 210 describe('with a falsey value', function() {
168 it('checks the element', function() { 211 it('unchecks the radio input', function() {
169 rivets.binders.unchecked.routine(el, false); 212 rivets.binders.unchecked.routine(falseRadioInput, false);
170 expect(el.checked).toBe(true); 213 expect(falseRadioInput.checked).toBe(false);
214 });
171 }); 215 });
172 }); 216 });
173 }); 217 });
......