From 45c2b948675c7dccdbff1d31ab4fd9d2e2a1bbc9 Mon Sep 17 00:00:00 2001 From: smeligrana Date: Wed, 1 Nov 2023 19:35:55 +0100 Subject: [PATCH] test: add test for ItAlert --- .../core/alert/alert.component.spec.ts | 50 +++++++++++++++++-- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/projects/design-angular-kit/src/lib/components/core/alert/alert.component.spec.ts b/projects/design-angular-kit/src/lib/components/core/alert/alert.component.spec.ts index 2d5f0dee..f321f0dc 100644 --- a/projects/design-angular-kit/src/lib/components/core/alert/alert.component.spec.ts +++ b/projects/design-angular-kit/src/lib/components/core/alert/alert.component.spec.ts @@ -2,16 +2,41 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ItAlertComponent } from './alert.component'; import { tb_base } from '../../../../test'; +import { By } from '@angular/platform-browser'; +import { Component, Input } from '@angular/core'; +import { AlertColor } from '../../../interfaces/core'; +@Component( + { + selector: 'it-unit-test', + template: ` + + Questo รจ un alert di tipo "primary". + + ` + } +) +class UnitTestComponent { + @Input() set selectedColor(value: AlertColor | undefined) {this._selectedColor = value;} + get selectedColor(): AlertColor | undefined {return this._selectedColor;} + private _selectedColor: AlertColor | undefined = undefined; + + @Input() set isDismissible(value: boolean) {this._dismissible = value;} + get isDismissible(): boolean {return this._dismissible;} + private _dismissible: boolean = false; +} + +let component: UnitTestComponent; +let fixture: ComponentFixture; describe('ItAlertComponent', () => { - let component: ItAlertComponent; - let fixture: ComponentFixture; beforeEach(async () => { - await TestBed.configureTestingModule(tb_base) - .compileComponents(); + TestBed.configureTestingModule({ + declarations: [UnitTestComponent], + imports: [ItAlertComponent], + }).compileComponents(); - fixture = TestBed.createComponent(ItAlertComponent); + fixture = TestBed.createComponent(UnitTestComponent); component = fixture.componentInstance; fixture.detectChanges(); }); @@ -19,4 +44,19 @@ describe('ItAlertComponent', () => { it('should create', () => { expect(component).toBeTruthy(); }); + + it('Dovrebbe avere colore primary', () => { + component.selectedColor='primary'; + fixture.detectChanges(); + const spanElement = fixture.debugElement.query(By.css('div.alert.alert-primary')); + expect(spanElement).toBeTruthy(); + }); + + it('Dovrebbe avere colore success', () => { + component.selectedColor='success'; + fixture.detectChanges(); + const spanElement = fixture.debugElement.query(By.css('div.alert.alert-success')); + expect(spanElement).toBeTruthy(); + }); + });