155 lines
4.5 KiB
TypeScript
155 lines
4.5 KiB
TypeScript
|
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||
|
|
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||
|
|
import { provideRouter } from '@angular/router';
|
||
|
|
import { TaskListPage } from '@app/features/tasks/feature/task-list-page/task-list-page';
|
||
|
|
import { TaskStore } from '@app/features/tasks/data-access/store/task-store';
|
||
|
|
import { TaskService } from '@app/features/tasks/data-access/services/task';
|
||
|
|
import { of } from 'rxjs';
|
||
|
|
import { TaskBuilder } from '@tests/builders/task.builder';
|
||
|
|
|
||
|
|
describe('TaskListPage', () => {
|
||
|
|
let component: TaskListPage;
|
||
|
|
let fixture: ComponentFixture<TaskListPage>;
|
||
|
|
let store: TaskStore;
|
||
|
|
let taskService: TaskService;
|
||
|
|
|
||
|
|
beforeEach(async () => {
|
||
|
|
taskService = {
|
||
|
|
getAll: vi.fn().mockReturnValue(of({ data: [], pagination: { page: 1, pageSize: 10, total: 0, totalPages: 0 } })),
|
||
|
|
delete: vi.fn().mockReturnValue(of(undefined)),
|
||
|
|
update: vi.fn(),
|
||
|
|
transition: vi.fn(),
|
||
|
|
addNote: vi.fn(),
|
||
|
|
deleteNote: vi.fn(),
|
||
|
|
} as unknown as TaskService;
|
||
|
|
|
||
|
|
await TestBed.configureTestingModule({
|
||
|
|
imports: [TaskListPage],
|
||
|
|
providers: [
|
||
|
|
provideRouter([]),
|
||
|
|
{ provide: TaskService, useValue: taskService },
|
||
|
|
],
|
||
|
|
}).compileComponents();
|
||
|
|
|
||
|
|
fixture = TestBed.createComponent(TaskListPage);
|
||
|
|
component = fixture.componentInstance;
|
||
|
|
store = TestBed.inject(TaskStore);
|
||
|
|
fixture.detectChanges();
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should create', () => {
|
||
|
|
expect(component).toBeTruthy();
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should have default view as table', () => {
|
||
|
|
expect(component.activeView()).toBe('table');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should have PAGE_SIZE of 5', () => {
|
||
|
|
expect(component.PAGE_SIZE).toBe(5);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should have default currentPage as 1', () => {
|
||
|
|
expect(component.currentPage()).toBe(1);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should change view mode', () => {
|
||
|
|
component.onViewChange('board');
|
||
|
|
|
||
|
|
expect(component.activeView()).toBe('board');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should change page', () => {
|
||
|
|
component.onPageChange(3);
|
||
|
|
|
||
|
|
expect(component.currentPage()).toBe(3);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should return current state from task history', () => {
|
||
|
|
const task = new TaskBuilder().withState('active').build();
|
||
|
|
|
||
|
|
expect(component.getState(task)).toBe('active');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should return new when history is empty', () => {
|
||
|
|
const task = new TaskBuilder().withStateHistory([]).build();
|
||
|
|
|
||
|
|
expect(component.getState(task)).toBe('new');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should return correct state label', () => {
|
||
|
|
const task = new TaskBuilder().withState('resolved').build();
|
||
|
|
|
||
|
|
expect(component.getStateLabel(task)).toBe('Resolved');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should return correct state progress', () => {
|
||
|
|
const task = new TaskBuilder().withState('active').build();
|
||
|
|
|
||
|
|
expect(component.getStateProgress(task)).toBe(50);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should return true for finalized tasks', () => {
|
||
|
|
const resolved = new TaskBuilder().withState('resolved').build();
|
||
|
|
const closed = new TaskBuilder().withState('closed').build();
|
||
|
|
|
||
|
|
expect(component.isFinalized(resolved)).toBe(true);
|
||
|
|
expect(component.isFinalized(closed)).toBe(true);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should return false for non-finalized tasks', () => {
|
||
|
|
const active = new TaskBuilder().withState('active').build();
|
||
|
|
const newTask = new TaskBuilder().withState('new').build();
|
||
|
|
|
||
|
|
expect(component.isFinalized(active)).toBe(false);
|
||
|
|
expect(component.isFinalized(newTask)).toBe(false);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should set selected task on view', () => {
|
||
|
|
const task = new TaskBuilder().build();
|
||
|
|
|
||
|
|
component.onViewTask(task);
|
||
|
|
|
||
|
|
expect(component.selectedTask()).toEqual(task);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should clear selected task on close', () => {
|
||
|
|
store.setSelectedTask(new TaskBuilder().build());
|
||
|
|
|
||
|
|
component.onCloseDetailSidebar();
|
||
|
|
|
||
|
|
expect(component.selectedTask()).toBeNull();
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should open create sidebar', () => {
|
||
|
|
component.onOpenCreateSidebar();
|
||
|
|
|
||
|
|
expect(component.showCreateSidebar()).toBe(true);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should close create sidebar', () => {
|
||
|
|
component.showCreateSidebar.set(true);
|
||
|
|
|
||
|
|
component.onCloseCreateSidebar();
|
||
|
|
|
||
|
|
expect(component.showCreateSidebar()).toBe(false);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should close create sidebar on task created', () => {
|
||
|
|
component.showCreateSidebar.set(true);
|
||
|
|
|
||
|
|
component.onTaskCreated();
|
||
|
|
|
||
|
|
expect(component.showCreateSidebar()).toBe(false);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should close create sidebar when viewing task', () => {
|
||
|
|
component.showCreateSidebar.set(true);
|
||
|
|
const task = new TaskBuilder().build();
|
||
|
|
|
||
|
|
component.onViewTask(task);
|
||
|
|
|
||
|
|
expect(component.showCreateSidebar()).toBe(false);
|
||
|
|
});
|
||
|
|
});
|