emi-challenge-fe/tests/app/features/tasks/ui/task-card/task-card.spec.ts

91 lines
2.5 KiB
TypeScript
Raw Normal View History

import { describe, it, expect } from 'vitest';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { TaskCard } from '@app/features/tasks/ui/task-card/task-card';
import { TaskBuilder } from '@tests/builders/task.builder';
describe('TaskCard', () => {
let component: TaskCard;
let fixture: ComponentFixture<TaskCard>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [TaskCard],
}).compileComponents();
fixture = TestBed.createComponent(TaskCard);
component = fixture.componentInstance;
fixture.componentRef.setInput('task', new TaskBuilder().build());
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should render task title', () => {
fixture.componentRef.setInput('task', new TaskBuilder().withTitle('My Task').build());
fixture.detectChanges();
const title = fixture.nativeElement.querySelector('h3');
expect(title?.textContent).toContain('My Task');
});
it('should render task description', () => {
fixture.componentRef.setInput('task', new TaskBuilder().withDescription('My Description').build());
fixture.detectChanges();
const desc = fixture.nativeElement.querySelector('.task-card__description');
expect(desc?.textContent).toContain('My Description');
});
it('should render due date', () => {
fixture.componentRef.setInput('task', new TaskBuilder().withDueDate('2026-12-25').build());
fixture.detectChanges();
const date = fixture.nativeElement.querySelector('.task-card__date');
expect(date?.textContent).toContain('2026-12-25');
});
it('should return last state from stateHistory', () => {
fixture.componentRef.setInput('task', new TaskBuilder().withState('active').build());
expect(component.currentState).toBe('active');
});
it('should return new when stateHistory is empty', () => {
fixture.componentRef.setInput('task', new TaskBuilder().withStateHistory([]).build());
expect(component.currentState).toBe('new');
});
it('should emit view event', () => {
const spy = vi.fn();
component.view.subscribe(spy);
component.onView();
expect(spy).toHaveBeenCalledOnce();
});
it('should emit edit event', () => {
const spy = vi.fn();
component.edit.subscribe(spy);
component.onEdit();
expect(spy).toHaveBeenCalledOnce();
});
it('should emit delete event', () => {
const spy = vi.fn();
component.delete.subscribe(spy);
component.onDelete();
expect(spy).toHaveBeenCalledOnce();
});
});