|
| 1 | +import type { ComponentFixture } from '@angular/core/testing'; |
| 2 | +import { render } from '@testing-library/angular'; |
| 3 | +import type { People } from '../../../../shared/models/people.model'; |
| 4 | +import { PreviewList } from './preview-list'; |
| 5 | + |
| 6 | +const MOCK_PEOPLE: People[] = [ |
| 7 | + { |
| 8 | + id: '1', |
| 9 | + firstname: 'Alice', |
| 10 | + lastname: 'Smith', |
| 11 | + entity: 'Engineering', |
| 12 | + |
| 13 | + phone: '1234567890', |
| 14 | + manager: 'Bob Johnson', |
| 15 | + isManager: true, |
| 16 | + photo: 'https://randomuser.me/api/portraits/women/1.jpg', |
| 17 | + }, |
| 18 | + { |
| 19 | + id: '2', |
| 20 | + firstname: 'Bob', |
| 21 | + lastname: 'Johnson', |
| 22 | + entity: 'HR', |
| 23 | + |
| 24 | + phone: '0987654321', |
| 25 | + manager: 'Alice Smith', |
| 26 | + isManager: false, |
| 27 | + photo: 'https://randomuser.me/api/portraits/men/2.jpg', |
| 28 | + }, |
| 29 | +] as People[]; |
| 30 | + |
| 31 | +describe('PreviewList', () => { |
| 32 | + let fixture: ComponentFixture<PreviewList>; |
| 33 | + let component: PreviewList; |
| 34 | + |
| 35 | + beforeEach(async () => { |
| 36 | + const { fixture: componentFixture } = await render(PreviewList, { inputs: { people: MOCK_PEOPLE } }); |
| 37 | + fixture = componentFixture; |
| 38 | + component = fixture.componentInstance; |
| 39 | + }); |
| 40 | + |
| 41 | + describe('Basic rendering', () => { |
| 42 | + test('should create an instance of PreviewList', () => { |
| 43 | + expect(component).toBeTruthy(); |
| 44 | + expect(component).toBeInstanceOf(PreviewList); |
| 45 | + }); |
| 46 | + test('should display the list of people', () => { |
| 47 | + const peopleList = fixture.nativeElement.querySelector('mat-list'); |
| 48 | + expect(peopleList).toBeTruthy(); |
| 49 | + }); |
| 50 | + test('should display the correct number of people', () => { |
| 51 | + const peopleList = fixture.nativeElement.querySelectorAll('mat-list-item'); |
| 52 | + expect(peopleList.length).toEqual(MOCK_PEOPLE.length); |
| 53 | + }); |
| 54 | + }); |
| 55 | +}); |
0 commit comments