emi-challenge-fe/tests/app/shared/ui/spinner/spinner.spec.ts

66 lines
1.9 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { Spinner } from '@app/shared/ui/spinner/spinner';
describe('Spinner', () => {
let component: Spinner;
let fixture: ComponentFixture<Spinner>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [Spinner],
}).compileComponents();
fixture = TestBed.createComponent(Spinner);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should render a span with spinner class', () => {
const span = fixture.nativeElement.querySelector('.spinner');
expect(span).toBeTruthy();
});
it('should have role status for accessibility', () => {
const span = fixture.nativeElement.querySelector('.spinner');
expect(span.getAttribute('role')).toBe('status');
});
it('should have aria-label for accessibility', () => {
const span = fixture.nativeElement.querySelector('.spinner');
expect(span.getAttribute('aria-label')).toBe('Loading');
});
it('should apply md class by default', () => {
const span = fixture.nativeElement.querySelector('.spinner');
expect(span.classList.contains('spinner--md')).toBe(true);
});
it('should apply sm class when size is sm', () => {
fixture.componentRef.setInput('size', 'sm');
fixture.detectChanges();
const span = fixture.nativeElement.querySelector('.spinner');
expect(span.classList.contains('spinner--sm')).toBe(true);
expect(span.classList.contains('spinner--md')).toBe(false);
});
it('should apply lg class when size is lg', () => {
fixture.componentRef.setInput('size', 'lg');
fixture.detectChanges();
const span = fixture.nativeElement.querySelector('.spinner');
expect(span.classList.contains('spinner--lg')).toBe(true);
});
});