Skip to content

Commit

Permalink
feat: add disabled property on TestInput, TestTextarea and TestSelect
Browse files Browse the repository at this point in the history
fixes #100
  • Loading branch information
jnizet committed Nov 15, 2018
1 parent a025786 commit a1b6597
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 0 deletions.
10 changes: 10 additions & 0 deletions projects/ngx-speculoos/src/lib/test-input.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { TestInput } from './test-input';
<input type="checkbox" id="c2" value="b" checked (change)="onChange()"/>
<input type="radio" name="r" id="r1" value="x" (change)="onChange()"/>
<input type="radio" name="r" id="r2" value="y" checked (change)="onChange()"/>
<input id="t2" disabled />
</form>
`
})
Expand Down Expand Up @@ -43,6 +44,10 @@ class TestComponentTester extends ComponentTester<TestComponent> {
get checkedRadio() {
return this.input('#r2');
}

get disabledInput() {
return this.input('#t2');
}
}

describe('TestInput', () => {
Expand Down Expand Up @@ -123,4 +128,9 @@ describe('TestInput', () => {
expect(tester.componentInstance.onChange).toHaveBeenCalled();
expect(tester.detectChanges).toHaveBeenCalled();
});

it('should expose the disabled property', () => {
expect(tester.textInput.disabled).toBe(false);
expect(tester.disabledInput.disabled).toBe(true);
});
});
7 changes: 7 additions & 0 deletions projects/ngx-speculoos/src/lib/test-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ export class TestInput extends TestHtmlElement<HTMLInputElement> {
return this.nativeElement.checked;
}

/**
* the disabled property of the wrapped input
*/
get disabled() {
return this.nativeElement.disabled;
}

/**
* Checks the wrapped input, then dispatches an event of type change and triggers a change detection
*/
Expand Down
10 changes: 10 additions & 0 deletions projects/ngx-speculoos/src/lib/test-select.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { TestSelect } from './test-select';
<option value="a">A</option>
<option value="b" label="B"></option>
</select>
<select id="s2" disabled></select>
`
})
class TestComponent {
Expand All @@ -25,6 +26,10 @@ class TestComponentTester extends ComponentTester<TestComponent> {
get selectBox() {
return this.select('#s1');
}

get disabledSelectBox() {
return this.select('#s2');
}
}

describe('TestButton', () => {
Expand Down Expand Up @@ -112,4 +117,9 @@ describe('TestButton', () => {
it('should expose the size', () => {
expect(tester.selectBox.size).toBe(3);
});

it('should expose the disabled property', () => {
expect(tester.selectBox.disabled).toBe(false);
expect(tester.disabledSelectBox.disabled).toBe(true);
});
});
7 changes: 7 additions & 0 deletions projects/ngx-speculoos/src/lib/test-select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,11 @@ export class TestSelect extends TestHtmlElement<HTMLSelectElement> {
get size() {
return this.nativeElement.options.length;
}

/**
* the disabled property of the wrapped select
*/
get disabled() {
return this.nativeElement.disabled;
}
}
10 changes: 10 additions & 0 deletions projects/ngx-speculoos/src/lib/test-textarea.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { TestTextArea } from './test-textarea';
@Component({
template: `
<textarea id="t1" value="hello" (input)="onInput()">hello</textarea>
<textarea id="t2" disabled></textarea>
`
})
class TestComponent {
Expand All @@ -21,6 +22,10 @@ class TestComponentTester extends ComponentTester<TestComponent> {
get textBox() {
return this.textarea('#t1');
}

get disabledTextBox() {
return this.textarea('#t2');
}
}

describe('TestTextArea', () => {
Expand Down Expand Up @@ -54,4 +59,9 @@ describe('TestTextArea', () => {
expect(tester.componentInstance.onInput).toHaveBeenCalled();
expect(tester.detectChanges).toHaveBeenCalled();
});

it('should expose the disabled property', () => {
expect(tester.textBox.disabled).toBe(false);
expect(tester.disabledTextBox.disabled).toBe(true);
});
});
7 changes: 7 additions & 0 deletions projects/ngx-speculoos/src/lib/test-textarea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,11 @@ export class TestTextArea extends TestHtmlElement<HTMLTextAreaElement> {
get value() {
return this.nativeElement.value;
}

/**
* the disabled property of the wrapped select
*/
get disabled() {
return this.nativeElement.disabled;
}
}

0 comments on commit a1b6597

Please sign in to comment.