-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #778 from HealthCatalyst/dev
dev -> master
- Loading branch information
Showing
13 changed files
with
459 additions
and
74 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
2 changes: 1 addition & 1 deletion
2
...examples/src/lib/typeform-survey-overview/typeform-survey-overview-example.component.html
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<hc-typeform-survey [surveyUri]="surveyUri" #survey></hc-typeform-survey> | ||
<hc-typeform-survey [surveyUri]="surveyUri" appVersion="1.0" #survey></hc-typeform-survey> | ||
<button hc-button buttonStyle="primary" (click)="survey.open()"> | ||
Open Survey | ||
</button> |
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
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
175 changes: 164 additions & 11 deletions
175
projects/cashmere/src/lib/radio-button/radio-button.component.spec.ts
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 |
---|---|---|
@@ -1,24 +1,177 @@ | ||
import {async, ComponentFixture, TestBed} from '@angular/core/testing'; | ||
import {RadioButtonComponent} from './radio'; | ||
import {RadioButtonComponent, RadioButtonChangeEvent} from './radio'; | ||
import {RadioButtonModule} from './radio-button.module'; | ||
import {Component, DebugElement} from '@angular/core'; | ||
import {By} from '@angular/platform-browser'; | ||
|
||
@Component({ | ||
template: ` | ||
<div (click)="parentElementClicked = true" (keyup)="parentElementKeyedUp = true"> | ||
<hc-radio-button | ||
[id]="radioId" | ||
[required]="isRequired" | ||
[checked]="isChecked" | ||
[disabled]="isDisabled" | ||
[value]="radioValue" | ||
(change)="onRadioChange($event)" | ||
> | ||
Simple radio button | ||
</hc-radio-button> | ||
</div> | ||
` | ||
}) | ||
export class SingleRadioComponent { | ||
isChecked: boolean = false; | ||
isRequired: boolean = false; | ||
isIndeterminate: boolean = false; | ||
isDisabled: boolean = false; | ||
parentElementClicked: boolean = false; | ||
parentElementKeyedUp: boolean = false; | ||
radioId: string | null = 'simple-radio'; | ||
radioValue: string = 'single_radio'; | ||
|
||
onRadioClick: (event?: Event) => void = () => {}; | ||
onRadioChange: (event?: RadioButtonChangeEvent) => void = () => {}; | ||
} | ||
|
||
describe('RadioButtonComponent', () => { | ||
let component: RadioButtonComponent; | ||
let fixture: ComponentFixture<RadioButtonComponent>; | ||
let fixture: ComponentFixture<any>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [RadioButtonModule] | ||
imports: [RadioButtonModule], | ||
declarations: [SingleRadioComponent] | ||
}).compileComponents(); | ||
fixture = TestBed.createComponent(RadioButtonComponent); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(RadioButtonComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
describe('basic behaviors', () => { | ||
let radioDebugElement: DebugElement; | ||
let radioNativeElement: HTMLElement; | ||
let radioInstance: RadioButtonComponent; | ||
let testComponent: SingleRadioComponent; | ||
|
||
let inputElement: HTMLInputElement; | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(SingleRadioComponent); | ||
fixture.detectChanges(); | ||
|
||
radioDebugElement = fixture.debugElement.query(By.directive(RadioButtonComponent)); | ||
radioNativeElement = radioDebugElement.nativeElement; | ||
radioInstance = radioDebugElement.componentInstance; | ||
testComponent = fixture.debugElement.componentInstance; | ||
|
||
inputElement = <HTMLInputElement>radioNativeElement.querySelector('input'); | ||
|
||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should add and remove checked state', () => { | ||
expect(radioInstance.checked).toBe(false); | ||
expect(inputElement.checked).toBe(false); | ||
|
||
testComponent.isChecked = true; | ||
fixture.detectChanges(); | ||
|
||
expect(radioInstance.checked).toBe(true); | ||
expect(inputElement.checked).toBe(true); | ||
|
||
testComponent.isChecked = false; | ||
fixture.detectChanges(); | ||
|
||
expect(radioInstance.checked).toBe(false); | ||
expect(inputElement.checked).toBe(false); | ||
}); | ||
|
||
it('should toggle checked state on click', () => { | ||
expect(radioInstance.checked).toBe(false); | ||
|
||
inputElement.click(); | ||
fixture.detectChanges(); | ||
|
||
expect(radioInstance.checked).toBe(true); | ||
}); | ||
|
||
it('should change native element checked when check programmatically', () => { | ||
expect(inputElement.checked).toBe(false); | ||
|
||
radioInstance.checked = true; | ||
fixture.detectChanges(); | ||
|
||
expect(inputElement.checked).toBe(true); | ||
}); | ||
|
||
it('should add and remove disabled state', () => { | ||
expect(radioInstance.disabled).toBe(false); | ||
expect(inputElement.tabIndex).toBe(0); | ||
expect(inputElement.disabled).toBe(false); | ||
|
||
testComponent.isDisabled = true; | ||
fixture.detectChanges(); | ||
|
||
expect(radioInstance.disabled).toBe(true); | ||
expect(inputElement.disabled).toBe(true); | ||
|
||
testComponent.isDisabled = false; | ||
fixture.detectChanges(); | ||
|
||
expect(radioInstance.disabled).toBe(false); | ||
expect(inputElement.tabIndex).toBe(0); | ||
expect(inputElement.disabled).toBe(false); | ||
}); | ||
|
||
it('should not toggle `checked` state upon interaction while disabled', () => { | ||
testComponent.isDisabled = true; | ||
fixture.detectChanges(); | ||
|
||
inputElement.click(); | ||
expect(radioInstance.checked).toBe(false); | ||
}); | ||
|
||
it('should preserve the user-provided id', () => { | ||
expect(radioNativeElement.id).toBe('simple-radio'); | ||
expect(inputElement.id).toBe('simple-radio-input'); | ||
}); | ||
|
||
it('should generate a unique id for the radio button input if no id is set', () => { | ||
testComponent.radioId = null; | ||
fixture.detectChanges(); | ||
|
||
expect(radioInstance._inputId).toMatch(/hc-radio-button-\d+/); | ||
expect(inputElement.id).toBe(radioInstance._inputId); | ||
}); | ||
|
||
it('should forward the required attribute', () => { | ||
testComponent.isRequired = true; | ||
fixture.detectChanges(); | ||
|
||
expect(inputElement.required).toBe(true); | ||
|
||
testComponent.isRequired = false; | ||
fixture.detectChanges(); | ||
|
||
expect(inputElement.required).toBe(false); | ||
}); | ||
|
||
it('should forward the value to input element', () => { | ||
testComponent.radioValue = 'basic_radio'; | ||
fixture.detectChanges(); | ||
|
||
expect(inputElement.value).toBe('basic_radio'); | ||
}); | ||
|
||
it('should emit a change event when clicked', () => { | ||
spyOn(testComponent, 'onRadioChange'); | ||
|
||
expect(inputElement.checked).toBe(false); | ||
|
||
inputElement.click(); | ||
fixture.detectChanges(); | ||
|
||
expect(inputElement.checked).toBe(true); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
expect(testComponent.onRadioChange).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.