From 372253f6d2e6657ba67ac31cbbb6390f3f13150f Mon Sep 17 00:00:00 2001 From: esuau Date: Tue, 23 Oct 2018 13:19:58 +0200 Subject: [PATCH 1/6] feat(switch): IBM/carbon-components-angular#68 Add small version of switch component --- src/switch/switch.component.spec.ts | 26 ++++++++++++++++++++++---- src/switch/switch.component.ts | 13 ++++++++++++- src/switch/switch.stories.ts | 5 ++++- 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/switch/switch.component.spec.ts b/src/switch/switch.component.spec.ts index 288c6f2765..49ec1f4d99 100644 --- a/src/switch/switch.component.spec.ts +++ b/src/switch/switch.component.spec.ts @@ -5,13 +5,14 @@ import { DebugElement } from "@angular/core"; import { StaticIconModule } from "../icon/static-icon.module"; import { SwitchComponent } from "./switch.component"; +import { CheckboxComponent } from "../checkbox/checkbox.module"; describe("SwitchComponent", () => { let component: SwitchComponent; let fixture: ComponentFixture; - let de: DebugElement; - let el: HTMLElement; + let labelElement: HTMLElement; let buttonElement: HTMLElement; + let svgElement: HTMLElement; beforeEach(() => { TestBed.configureTestingModule({ @@ -22,8 +23,8 @@ describe("SwitchComponent", () => { fixture = TestBed.createComponent(SwitchComponent); component = fixture.componentInstance; - de = fixture.debugElement.query(By.css("label")); - el = de.nativeElement; + fixture.detectChanges(); + labelElement = fixture.debugElement.query(By.css("label")).nativeElement; buttonElement = fixture.debugElement.query(By.css("input")).nativeElement; }); @@ -40,4 +41,21 @@ describe("SwitchComponent", () => { fixture.detectChanges(); expect(component.checked).toBe(false, "setting to off"); }); + + it("should display small version of switch when size equals sm", () => { + component.size = "sm"; + component.ngOnInit(); + fixture.detectChanges(); + expect(buttonElement.className.includes("bx--toggle--small")).toEqual(true); + }); + + it("should display SVG in small version of switch", () => { + component.size = "sm"; + component.ngOnInit(); + fixture.detectChanges(); + labelElement = fixture.debugElement.query(By.css("label")).nativeElement; + expect(fixture.debugElement.query(By.css("svg")).nativeElement).not.toBeNull(); + expect(labelElement.innerHTML).toContain("bx--toggle__check"); + }); + }); diff --git a/src/switch/switch.component.ts b/src/switch/switch.component.ts index cc0320b7d5..3ae87c4181 100644 --- a/src/switch/switch.component.ts +++ b/src/switch/switch.component.ts @@ -66,11 +66,18 @@ export class SwitchChange { (click)="onClick($event)" [disabled]="disabled" [attr.aria-checked]="checked"> -