Skip to content

Commit

Permalink
test: add tests for spinner
Browse files Browse the repository at this point in the history
Co-authored-by: smeligrana <[email protected]>
  • Loading branch information
smeligrana and smeligrana authored Nov 7, 2023
1 parent d27a725 commit 0e4cabb
Showing 1 changed file with 63 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,77 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { ItSpinnerComponent } from './spinner.component';
import { tb_base } from '../../../../test';
import { Component, Input } from '@angular/core';
import { BooleanInput } from '../../../utils/boolean-input';
import { By } from '@angular/platform-browser';
import { TranslateModule,} from '@ngx-translate/core';

describe('ItSpinnerComponent', () => {
let component: ItSpinnerComponent;
let fixture: ComponentFixture<ItSpinnerComponent>;
@Component(
{
selector: 'it-unit-test',
template: `
<it-spinner [active]="active" [small]="small"></it-spinner>
`
}
)
class UnitTestComponent {
@Input() set active(value: BooleanInput | undefined) {this._active = value;}
get active(): BooleanInput | undefined {return this._active;}
private _active: BooleanInput | undefined = undefined;

@Input() set small(value: BooleanInput | undefined) {this._small = value;}
get small(): BooleanInput | undefined {return this._small;}
private _small: BooleanInput | undefined = undefined;

}

let component: UnitTestComponent;
let fixture: ComponentFixture<UnitTestComponent>;

describe('ItSpinnerComponent', () => {

beforeEach(async () => {
await TestBed.configureTestingModule(tb_base)
.compileComponents();
TestBed.configureTestingModule({
declarations: [UnitTestComponent],
imports: [ItSpinnerComponent, TranslateModule.forRoot(),],
}).compileComponents();

fixture = TestBed.createComponent(ItSpinnerComponent);
fixture = TestBed.createComponent(UnitTestComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

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

it('Dovrebbe avere spinner active', () => {
component.active='true';
fixture.detectChanges();
const spanElement = fixture.debugElement.query(By.css('div.progress-spinner.progress-spinner-active'));
expect(spanElement).toBeTruthy();
});

it('Dovrebbe avere spinner non active', () => {
component.active='false';
fixture.detectChanges();
const spanElement = fixture.debugElement.query(By.css('div.progress-spinner'));
expect(spanElement).toBeTruthy();
});

it('Dovrebbe avere spinner small non active', () => {
component.active='false';
component.small='true';
fixture.detectChanges();
const spanElement = fixture.debugElement.query(By.css('div.progress-spinner.size-sm'));
expect(spanElement).toBeTruthy();
});

it('Dovrebbe avere spinner small active', () => {
component.active='true';
component.small='true';
fixture.detectChanges();
const spanElement = fixture.debugElement.query(By.css('div.progress-spinner.progress-spinner-active.size-sm'));
expect(spanElement).toBeTruthy();
});
});

1 comment on commit 0e4cabb

@vercel
Copy link

@vercel vercel bot commented on 0e4cabb Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.