-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(design): moved CVA implementation to a directive
- Loading branch information
1 parent
c2611c6
commit d19685b
Showing
9 changed files
with
272 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<daff-checkbox-set [formGroup]="checkboxes"> | ||
<daff-checkbox formControlName="option1" value="option1">Option 1 </daff-checkbox> | ||
<daff-checkbox formControlName="option2" value="option2">Option 2 </daff-checkbox> | ||
<daff-checkbox formControlName="option3" value="option3">Option 3 </daff-checkbox> | ||
<daff-checkbox formControlName="0" value="option1">Option 1 </daff-checkbox> | ||
<daff-checkbox formControlName="1" value="option2">Option 2 </daff-checkbox> | ||
<daff-checkbox formControlName="2" value="option3">Option 3 </daff-checkbox> | ||
</daff-checkbox-set> |
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,17 +1,19 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { FormGroup, FormControl } from '@angular/forms'; | ||
import { FormControl, FormArray } from '@angular/forms'; | ||
|
||
@Component({ | ||
selector: 'checkbox-component', | ||
templateUrl: './checkbox.component.html', | ||
styleUrls: ['./checkbox.component.scss'], | ||
|
||
}) | ||
export class CheckboxComponent { | ||
export class CheckboxComponent implements OnInit { | ||
|
||
checkboxes = new FormGroup({ | ||
option1: new FormControl('false'), | ||
option2: new FormControl('true'), | ||
option3: new FormControl() | ||
}) | ||
} | ||
option1 = new FormControl(); | ||
option2 = new FormControl(); | ||
option3 = new FormControl(); | ||
checkboxes = new FormArray([this.option1, this.option2, this.option3]); | ||
ngOnInit() { | ||
this.checkboxes.setValue(['option1', 'false', 'false']) | ||
} | ||
} |
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
93 changes: 93 additions & 0 deletions
93
libs/design/src/atoms/form/checkbox/cva/checkbox-cva.directive.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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { Component } from '@angular/core'; | ||
import { ComponentFixture, async, TestBed } from '@angular/core/testing'; | ||
import { ReactiveFormsModule, FormControl } from '@angular/forms'; | ||
import { By } from '@angular/platform-browser'; | ||
|
||
import { DaffCheckboxComponent } from '../checkbox.component'; | ||
import { DaffCheckboxModule } from '../checkbox.module'; | ||
|
||
|
||
|
||
@Component({ | ||
template: ` | ||
<daff-checkbox name='test' value='testValue' [formControl]='checkbox'></daff-checkbox> | ||
` | ||
}) | ||
class CheckboxWrapperComponent { | ||
checkbox = new FormControl() | ||
} | ||
|
||
describe('DaffCheckboxControlValueAccessorDirective', () => { | ||
|
||
describe('with the directive', () => { | ||
let CheckboxWrapper: CheckboxWrapperComponent; | ||
|
||
let component: DaffCheckboxComponent; | ||
|
||
let fixture: ComponentFixture<CheckboxWrapperComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ | ||
CheckboxWrapperComponent, | ||
], | ||
imports: [ | ||
ReactiveFormsModule, | ||
DaffCheckboxModule | ||
] | ||
}) | ||
.compileComponents(); | ||
})); | ||
describe('the DaffCheckboxComponent', () => { | ||
|
||
beforeEach(() => { | ||
|
||
fixture = TestBed.createComponent(CheckboxWrapperComponent); | ||
CheckboxWrapper = fixture.componentInstance; | ||
component = fixture.debugElement.query(By.css('daff-Checkbox')).componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
it('has the writeValue function for formControls', async () => { | ||
|
||
expect(component.checked).toEqual(false); | ||
|
||
CheckboxWrapper.checkbox.setValue('testValue'); | ||
|
||
expect(component.checked).toEqual(true); | ||
}); | ||
}); | ||
|
||
}); | ||
describe('without the directive', () => { | ||
let CheckboxWrapper: CheckboxWrapperComponent; | ||
|
||
let component: DaffCheckboxComponent; | ||
|
||
let fixture: ComponentFixture<CheckboxWrapperComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ | ||
CheckboxWrapperComponent, | ||
DaffCheckboxComponent | ||
], | ||
imports: [ | ||
ReactiveFormsModule, | ||
] | ||
}) | ||
.compileComponents(); | ||
})); | ||
describe('the DaffCheckboxComponent', () => { | ||
|
||
it('throws an error without the directive to give the itself the CVA interface', async () => { | ||
fixture = TestBed.createComponent(CheckboxWrapperComponent); | ||
CheckboxWrapper = fixture.componentInstance; | ||
expect(() => { | ||
component = fixture.debugElement.query(By.css('daff-checkbox')).componentInstance; | ||
fixture.detectChanges(); | ||
}).toThrowError() | ||
}); | ||
|
||
}); | ||
}); | ||
}); |
Oops, something went wrong.