Skip to content

Commit

Permalink
Added inout property to control the visibility of go-form-error.
Browse files Browse the repository at this point in the history
Implemented in all controls with go-form-error.
  • Loading branch information
CORP\Sudheep.Divakar committed Sep 20, 2023
1 parent 2bcf768 commit 1e8a818
Show file tree
Hide file tree
Showing 19 changed files with 723 additions and 494 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@
<legend
class="go-form__legend"
[ngClass]="{ 'go-form__legend--dark': theme === 'dark' }"
>{{ legend }}</legend>
>
{{ legend }}
</legend>

<ng-content></ng-content>

<go-hint *ngFor="let hint of hints" [message]="hint" [theme]="theme"></go-hint>

<go-form-errors [control]="control" [theme]="theme"></go-form-errors>
<go-hint
*ngFor="let hint of hints"
[message]="hint"
[theme]="theme"
></go-hint>
<div *ngIf="!hideFieldError">
<go-form-errors [control]="control" [theme]="theme"></go-form-errors>
</div>
</fieldset>
Original file line number Diff line number Diff line change
@@ -1,51 +1,68 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FormControl, FormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { async, ComponentFixture, TestBed } from "@angular/core/testing";
import {
FormControl,
FormGroup,
FormsModule,
ReactiveFormsModule,
} from "@angular/forms";

import { GoCheckboxGroupComponent } from './go-checkbox-group.component';
import { GoHintModule } from '../go-hint/go-hint.module';
import { GoCheckboxComponent } from './go-checkbox.component';
import { Component } from '@angular/core';
import { GoRequiredTextModule } from '../go-required-text/go-required-text.module';
import { GoFormErrorsModule } from '../go-form-errors/go-form-errors.module';
import { GoCheckboxGroupComponent } from "./go-checkbox-group.component";
import { GoHintModule } from "../go-hint/go-hint.module";
import { GoCheckboxComponent } from "./go-checkbox.component";
import { Component } from "@angular/core";
import { GoRequiredTextModule } from "../go-required-text/go-required-text.module";
import { GoFormErrorsModule } from "../go-form-errors/go-form-errors.module";
import { By } from "@angular/platform-browser";

@Component({
selector: 'go-test',
selector: "go-test",
template: `
<go-checkbox-group label="Options" [control]="checkboxForm">
<div>
<go-checkbox label="Option 1" [control]="checkboxForm.controls.option1"></go-checkbox>
<go-checkbox
label="Option 1"
[control]="checkboxForm.controls.option1"
[hideFieldError]="true"
></go-checkbox>
</div>
<div>
<go-checkbox label="Option 2" [control]="checkboxForm.controls.option2"></go-checkbox>
<go-checkbox
label="Option 2"
[control]="checkboxForm.controls.option2"
[hideFieldError]="true"
></go-checkbox>
</div>
</go-checkbox-group>
`
`,
})
class GoTestCheckboxGroupComponent {
checkboxForm: FormGroup = new FormGroup({
option1: new FormControl(''),
option2: new FormControl('')
option1: new FormControl(""),
option2: new FormControl(""),
});
}

describe('GoCheckboxGroupComponent', () => {
describe("GoCheckboxGroupComponent", () => {
let checkboxOne: GoCheckboxComponent;
let checkboxTwo: GoCheckboxComponent;
let component: GoCheckboxGroupComponent;
let fixture: ComponentFixture<GoTestCheckboxGroupComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [GoCheckboxGroupComponent, GoCheckboxComponent, GoTestCheckboxGroupComponent],
declarations: [
GoCheckboxGroupComponent,
GoCheckboxComponent,
GoTestCheckboxGroupComponent,
],
imports: [
GoFormErrorsModule,
GoHintModule,
GoRequiredTextModule,
FormsModule,
ReactiveFormsModule
]
})
.compileComponents();
ReactiveFormsModule,
],
}).compileComponents();
}));

beforeEach(() => {
Expand All @@ -59,22 +76,36 @@ describe('GoCheckboxGroupComponent', () => {
checkboxTwo = checkboxArray[1];
});

it('should create', () => {
it("should create", () => {
expect(component).toBeTruthy();
});

describe('ngAfterContentInit', () => {
describe("ngAfterContentInit", () => {
beforeEach(() => {
checkboxOne.theme = null;
checkboxTwo.theme = null;
});

it('should set a theme on each child component', () => {
component.theme = 'dark';
it("should set a theme on each child component", () => {
component.theme = "dark";
component.ngAfterContentInit();

expect(checkboxOne.theme).toBe('dark');
expect(checkboxTwo.theme).toBe('dark');
expect(checkboxOne.theme).toBe("dark");
expect(checkboxTwo.theme).toBe("dark");
});
});
it("component should not render go-form-errors if hideFieldError property is true ", () => {
component.hideFieldError = true;
fixture.detectChanges();
expect(
fixture.debugElement.queryAll(By.css("go-form-errors"))?.length
).toBe(0);
});
it("component should render go-form-errors if hideFieldError property is false ", () => {
component.hideFieldError = false;
fixture.detectChanges();
expect(
fixture.debugElement.queryAll(By.css("go-form-errors"))?.length
).toBe(1);
});
});
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
<div>
<label [for]="_id"
class="go-form__label go-form__label--inline go-form__label--checkbox-container"
[ngClass]="{'go-form__label--dark': theme === 'dark'}">
<label
[for]="_id"
class="go-form__label go-form__label--inline go-form__label--checkbox-container"
[ngClass]="{ 'go-form__label--dark': theme === 'dark' }"
>
{{ label }}
<go-required-text [control]="control"></go-required-text>
<input [id]="_id"
class="go-form__checkbox go-form__checkbox--hidden"
[ngClass]="inputClasses"
type="checkbox"
[formControl]="control"
#hiddenInputRef>
<input
[id]="_id"
class="go-form__checkbox go-form__checkbox--hidden"
[ngClass]="inputClasses"
type="checkbox"
[formControl]="control"
#hiddenInputRef
/>
<span class="go-form__custom-checkbox"></span>
</label>

<go-hint *ngFor="let hint of hints" [message]="hint" [theme]="theme"></go-hint>

<go-form-errors [control]="control"></go-form-errors>
<go-hint
*ngFor="let hint of hints"
[message]="hint"
[theme]="theme"
></go-hint>
<div *ngIf="!hideFieldError">
<go-form-errors [control]="control"></go-form-errors>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FormControl, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { GoFormErrorsModule } from '../go-form-errors/go-form-errors.module';
import { GoHintModule } from '../go-hint/go-hint.module';
import { GoRequiredTextModule } from '../go-required-text/go-required-text.module';
import { GoCheckboxComponent } from './go-checkbox.component';

describe('GoCheckboxComponent', () => {
import { async, ComponentFixture, TestBed } from "@angular/core/testing";
import { FormControl, FormsModule, ReactiveFormsModule } from "@angular/forms";
import { GoFormErrorsModule } from "../go-form-errors/go-form-errors.module";
import { GoHintModule } from "../go-hint/go-hint.module";
import { GoRequiredTextModule } from "../go-required-text/go-required-text.module";
import { GoCheckboxComponent } from "./go-checkbox.component";
import { By } from "@angular/platform-browser";

describe("GoCheckboxComponent", () => {
let component: GoCheckboxComponent;
let fixture: ComponentFixture<GoCheckboxComponent>;

Expand All @@ -17,10 +18,9 @@ describe('GoCheckboxComponent', () => {
ReactiveFormsModule,
GoFormErrorsModule,
GoHintModule,
GoRequiredTextModule
]
})
.compileComponents();
GoRequiredTextModule,
],
}).compileComponents();
}));

beforeEach(() => {
Expand All @@ -30,12 +30,12 @@ describe('GoCheckboxComponent', () => {
fixture.detectChanges();
});

it('should create', () => {
it("should create", () => {
expect(component).toBeTruthy();
});

describe('ngAfterViewInit', () => {
it('sets the hidden input to indeterminate if indeterminate input is true', () => {
describe("ngAfterViewInit", () => {
it("sets the hidden input to indeterminate if indeterminate input is true", () => {
expect(component.hiddenInputRef.nativeElement.indeterminate).toBe(false);

component.indeterminate = true;
Expand All @@ -45,4 +45,18 @@ describe('GoCheckboxComponent', () => {
expect(component.hiddenInputRef.nativeElement.indeterminate).toBe(true);
});
});
it("component should not render go-form-errors if hideFieldError property is true ", () => {
component.hideFieldError = true;
fixture.detectChanges();
expect(
fixture.debugElement.queryAll(By.css("go-form-errors"))?.length
).toBe(0);
});
it("component should render go-form-errors if hideFieldError property is false ", () => {
component.hideFieldError = false;
fixture.detectChanges();
expect(
fixture.debugElement.queryAll(By.css("go-form-errors"))?.length
).toBe(1);
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<label
<label
[attr.for]="_id"
class="go-form__label"
[ngClass]="{'go-form__label--dark': theme == 'dark'}">
[ngClass]="{ 'go-form__label--dark': theme == 'dark' }"
>
{{ label }}
<go-required-text [control]="control"></go-required-text>
</label>
Expand Down Expand Up @@ -39,5 +40,6 @@
</div>

<go-hint *ngFor="let hint of hints" [message]="hint" [theme]="theme"></go-hint>

<go-form-errors [control]="control" [theme]="theme"></go-form-errors>
<div *ngIf="!hideFieldError">
<go-form-errors [control]="control" [theme]="theme"></go-form-errors>
</div>
Loading

0 comments on commit 1e8a818

Please sign in to comment.