-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(radio): improve group/button value comparisons
- Loading branch information
1 parent
8b1783b
commit 5d9b169
Showing
5 changed files
with
374 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import {RadioGroup, RadioButton, Form} from '../../../../ionic'; | ||
|
||
export function run() { | ||
describe('RadioGroup', () => { | ||
|
||
describe('_update', () => { | ||
|
||
it('should set checked via string values', () => { | ||
let rb1 = createRadioButton(); | ||
rb1.value = 'string1'; | ||
let rb2 = createRadioButton(); | ||
rb2.value = 'string2'; | ||
let rb3 = createRadioButton(); | ||
rb3.value = 'string3'; | ||
|
||
rg.value = 'string1'; | ||
rg._update(); | ||
|
||
expect(rb1.checked).toEqual(true); | ||
expect(rb2.checked).toEqual(false); | ||
expect(rb3.checked).toEqual(false); | ||
}); | ||
|
||
it('should set checked via string group value, and number button values', () => { | ||
let rb1 = createRadioButton(); | ||
rb1.value = 1; | ||
let rb2 = createRadioButton(); | ||
rb2.value = 2; | ||
let rb3 = createRadioButton(); | ||
rb3.value = 3; | ||
|
||
rg.value = '1'; | ||
rg._update(); | ||
|
||
expect(rb1.checked).toEqual(true); | ||
expect(rb2.checked).toEqual(false); | ||
expect(rb3.checked).toEqual(false); | ||
}); | ||
|
||
it('should set checked via number group value, and string button values', () => { | ||
let rb1 = createRadioButton(); | ||
rb1.value = '1'; | ||
let rb2 = createRadioButton(); | ||
rb2.value = '2'; | ||
let rb3 = createRadioButton(); | ||
rb3.value = '3'; | ||
|
||
rg.value = 1; | ||
rg._update(); | ||
|
||
expect(rb1.checked).toEqual(true); | ||
expect(rb2.checked).toEqual(false); | ||
expect(rb3.checked).toEqual(false); | ||
}); | ||
|
||
it('should set checked via empty string group value, and one empty string button value', () => { | ||
let rb1 = createRadioButton(); | ||
rb1.value = ''; | ||
let rb2 = createRadioButton(); | ||
rb2.value = 'value2'; | ||
let rb3 = createRadioButton(); | ||
rb3.value = 'value3'; | ||
|
||
rg.value = ''; | ||
rg._update(); | ||
|
||
expect(rb1.checked).toEqual(true); | ||
expect(rb2.checked).toEqual(false); | ||
expect(rb3.checked).toEqual(false); | ||
}); | ||
|
||
it('should only check at most one value', () => { | ||
let rb1 = createRadioButton(); | ||
rb1.value = 'string1'; | ||
let rb2 = createRadioButton(); | ||
rb2.value = 'string1'; | ||
let rb3 = createRadioButton(); | ||
rb3.value = 'string1'; | ||
|
||
rg.value = 'string1'; | ||
rg._update(); | ||
|
||
expect(rb1.checked).toEqual(true); | ||
expect(rb2.checked).toEqual(false); | ||
expect(rb3.checked).toEqual(false); | ||
}); | ||
|
||
}); | ||
|
||
let rg: RadioGroup; | ||
let form: Form; | ||
|
||
function createRadioButton() { | ||
return new RadioButton(form, null, rg); | ||
} | ||
|
||
function mockRenderer(): any { | ||
return { | ||
setElementAttribute: function(){} | ||
} | ||
} | ||
|
||
function mockElementRef(): any { | ||
return { | ||
nativeElement: document.createElement('div') | ||
} | ||
} | ||
|
||
beforeEach(() => { | ||
rg = new RadioGroup(mockRenderer(), mockElementRef()); | ||
form = new Form(); | ||
}); | ||
|
||
}); | ||
} |
Oops, something went wrong.