Skip to content

Commit

Permalink
Test per componente itAlert
Browse files Browse the repository at this point in the history
  • Loading branch information
smeligrana committed Nov 1, 2023
1 parent c373d99 commit 5e15b9b
Showing 1 changed file with 45 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,61 @@ 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: `
<it-alert [color]="selectedColor" [dismissible]="isDismissible">
Questo è un alert di tipo "<b>primary</b>".
</it-alert>
`
}
)
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<UnitTestComponent>;
describe('ItAlertComponent', () => {
let component: ItAlertComponent;
let fixture: ComponentFixture<ItAlertComponent>;

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();
});

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();
});

});

0 comments on commit 5e15b9b

Please sign in to comment.