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

97 lines
2.7 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { TaskNoteList } from '@app/features/tasks/ui/task-note-list/task-note-list';
describe('TaskNoteList', () => {
let component: TaskNoteList;
let fixture: ComponentFixture<TaskNoteList>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [TaskNoteList],
}).compileComponents();
fixture = TestBed.createComponent(TaskNoteList);
component = fixture.componentInstance;
fixture.componentRef.setInput('notes', []);
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should render empty state when no notes', () => {
const empty = fixture.nativeElement.querySelector('.note-list__empty');
expect(empty).toBeTruthy();
expect(empty.textContent).toContain('No notes yet');
});
it('should render notes list', () => {
fixture.componentRef.setInput('notes', ['Note 1', 'Note 2', 'Note 3']);
fixture.detectChanges();
const items = fixture.nativeElement.querySelectorAll('.note-list__item');
expect(items.length).toBe(3);
});
it('should render note content', () => {
fixture.componentRef.setInput('notes', ['My first note']);
fixture.detectChanges();
const content = fixture.nativeElement.querySelector('.note-list__content');
expect(content?.textContent).toContain('My first note');
});
it('should have list role for accessibility', () => {
const list = fixture.nativeElement.querySelector('.note-list');
expect(list.getAttribute('role')).toBe('list');
});
it('should have aria-label on list', () => {
const list = fixture.nativeElement.querySelector('.note-list');
expect(list.getAttribute('aria-label')).toBe('Task notes');
});
it('should emit addNote with content', () => {
const spy = vi.fn();
component.addNote.subscribe(spy);
component.onAddNote('New note');
expect(spy).toHaveBeenCalledWith('New note');
});
it('should not emit addNote when content is empty', () => {
const spy = vi.fn();
component.addNote.subscribe(spy);
component.onAddNote(' ');
expect(spy).not.toHaveBeenCalled();
});
it('should emit deleteNote with index', () => {
const spy = vi.fn();
component.deleteNote.subscribe(spy);
component.onDeleteNote(2);
expect(spy).toHaveBeenCalledWith(2);
});
it('should have delete button with aria-label', () => {
fixture.componentRef.setInput('notes', ['Test note']);
fixture.detectChanges();
const deleteBtn = fixture.nativeElement.querySelector('.note-list__delete');
expect(deleteBtn.getAttribute('aria-label')).toBe('Delete note: Test note');
});
});