diff --git a/apps/testing-todos-list/src/app/list/list.component.spec.ts b/apps/testing-todos-list/src/app/list/list.component.spec.ts index 89a583e..91e90aa 100644 --- a/apps/testing-todos-list/src/app/list/list.component.spec.ts +++ b/apps/testing-todos-list/src/app/list/list.component.spec.ts @@ -1,21 +1,52 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ReactiveFormsModule } from '@angular/forms'; -import { By } from '@angular/platform-browser'; +import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { RouterTestingModule } from '@angular/router/testing'; +import { of } from 'rxjs'; import { BackendService } from '../backend.service'; import { ListComponent } from './list.component'; -import { AddComponent } from './ui/add.component'; -import { RowComponent } from './ui/row.component'; + +const USERS = [ + { id: 1, name: 'titi' }, + { id: 2, name: 'george' }, +]; +const TICKETS = [ + { + id: 0, + description: 'Install a monitor arm', + assigneeId: 1, + completed: false, + }, + { + id: 1, + description: 'Coucou', + assigneeId: 1, + completed: false, + }, +]; describe('ListComponent', () => { let component: ListComponent; let fixture: ComponentFixture; + //To change with a setup function beforeEach(async () => { await TestBed.configureTestingModule({ - declarations: [ListComponent, AddComponent, RowComponent], - imports: [ReactiveFormsModule, RouterTestingModule], - providers: [BackendService], + imports: [ + ListComponent, + ReactiveFormsModule, + RouterTestingModule, + NoopAnimationsModule, + ], + providers: [ + { + provide: BackendService, + useValue: { + users: () => of(USERS), + tickets: () => of(TICKETS), + }, + }, + ], }).compileComponents(); }); @@ -25,18 +56,51 @@ describe('ListComponent', () => { fixture.detectChanges(); }); - it('should search on table', async () => { - await fixture.whenStable(); - fixture.detectChanges(); + describe('Given Install inside the search input', () => { + it('Then one row is visible', async () => { + // + }); + }); - let rows = fixture.debugElement.queryAll(By.css('.rows')); - expect(rows.length).toEqual(2); + describe('When typing a description and clicking on add a new ticket', () => { + describe('Given a success answer from API', () => { + it('Then ticket with the description is added to the list with unassigned status', async () => { + // + }); + }); - component.search.setValue('Install'); - fixture.detectChanges(); - await fixture.whenStable(); + describe('Given a failure answer from API', () => { + it('Then an error is displayed at the bottom of the list', async () => { + // + }); + }); + }); - rows = fixture.debugElement.queryAll(By.css('.rows')); - expect(rows.length).toEqual(1); + describe('When assigning first ticket to george', () => { + describe('Given a success answer from API', () => { + it('Then first ticket is assigned to George', async () => { + // + }); + }); + + describe('Given a failure answer from API', () => { + it('Then an error is displayed at the bottom of the list', async () => { + // + }); + }); + }); + + describe('When finishing first ticket', () => { + describe('Given a success answer from API', () => { + it('Then first ticket is done', async () => { + // + }); + }); + + describe('Given a failure answer from API', () => { + it('Then an error is displayed at the bottom of the list', async () => { + // + }); + }); }); }); diff --git a/apps/testing-todos-list/src/app/list/list.component.ts b/apps/testing-todos-list/src/app/list/list.component.ts index dee2811..bc24485 100644 --- a/apps/testing-todos-list/src/app/list/list.component.ts +++ b/apps/testing-todos-list/src/app/list/list.component.ts @@ -36,15 +36,23 @@ import { RowComponent } from './ui/row.component'; placeholder="write an article" /> - - + +