Skip to content

test: reproduce #254 #255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions apps/example-app/src/app/issues/issue-254.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { Component, Inject, OnInit } from '@angular/core';
import { render, screen } from '@testing-library/angular';
import { createMock } from '@testing-library/angular/jest-utils';

interface Division {
JobType: string;
JobBullets: string[];
Description: string;
}

@Inject({
providedIn: 'root',
})
class JobsService {
divisions(): Promise<Division[]> {
throw new Error('Method not implemented.');
}
}

@Component({
selector: 'app-home-career-oportunities',
template: ` <ul class="popu-category-bullets">
<li class="text-dark" *ngFor="let bullet of dedicated.JobBullets">
{{ bullet }}
</li>
</ul>`,
})
class CareerOportunitiesComponent implements OnInit {
dedicated = {} as Division;
intermodal = {} as Division;
noCdl = {} as Division;
otr = {} as Division;

constructor(private jobsService: JobsService) {}

ngOnInit(): void {
this.jobsService.divisions().then((apiDivisions) => {
this.dedicated = apiDivisions.find((c) => c.JobType === 'DEDICATED');
this.intermodal = apiDivisions.find((c) => c.JobType === 'INTERMODAL');
this.noCdl = apiDivisions.find((c) => c.JobType === 'NO_CDL');
this.otr = apiDivisions.find((c) => c.JobType === 'OVER_THE_ROAD');
});
}
}

test('Render Component', async () => {
const divisions2: Division[] = [
{
JobType: 'INTERMODAL',
JobBullets: ['Local Routes', 'Flexible Schedules', 'Competitive Pay'],
Description: '',
},
{ JobType: 'NO_CDL', JobBullets: ['We Train', 'We Hire', 'We Pay'], Description: '' },
{
JobType: 'OVER_THE_ROAD',
JobBullets: ['Great Miles', 'Competitive Pay', 'Explore the Country'],
Description: '',
},
{
JobType: 'DEDICATED',
JobBullets: ['Regular Routes', 'Consistent Miles', 'Great Pay'],
Description: '',
},
];
const jobService = createMock(JobsService);
jobService.divisions = jest.fn(() => Promise.resolve(divisions2));

await render(CareerOportunitiesComponent, {
componentProviders: [
{
provide: JobsService,
useValue: jobService,
},
],
});
await screen.findAllByRole('listitem');
});