Skip to content
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

Add tests for main menu service #2830

Merged
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
Original file line number Diff line number Diff line change
@@ -1,16 +1,54 @@
import { TestBed } from '@angular/core/testing';
import { firstValueFrom, skip } from 'rxjs';

import { MainMenuService } from './main-menu.service';
import { MainMenuEntry, MainMenuService } from './main-menu.service';

xdescribe(`MainMenuService`, () => {
const menuEntries: MainMenuEntry[] = [
{ route: `page1`, displayName: `A page`, icon: `add`, weight: 300 },
{ route: `start`, displayName: `Start page`, icon: `start`, weight: 100 },
{ route: `page2`, displayName: `Another page`, icon: `search`, weight: 200 }
];

function getNumberOfTogglesPromise(service: MainMenuService, requiredToggleNumber: number): Promise<void> {
return firstValueFrom(service.toggleMenuSubject.pipe(skip(requiredToggleNumber - 1)));
}

describe(`MainMenuService`, () => {
let service: MainMenuService;

beforeEach(() => {
TestBed.configureTestingModule({});
TestBed.configureTestingModule({
providers: [MainMenuService]
});

service = TestBed.inject(MainMenuService);
});

it(`should be created`, () => {
expect(service).toBeTruthy();
it(`test registerEntries method`, () => {
service.registerEntries([menuEntries[0]]);
expect(service.entries).toEqual([menuEntries[0]]);
});

it(`test registerEntries method with multiple entries at once`, () => {
service.registerEntries(menuEntries.slice(1));
expect(service.entries).toEqual(menuEntries.slice(1));
});

it(`test consecutive calls of registerEntries method`, () => {
service.registerEntries(menuEntries.slice(0, 2));
service.registerEntries([menuEntries[2]]);
expect(service.entries).toEqual(menuEntries.sort((a, b) => a.weight - b.weight));
});

for (let i = 1; i <= 5; i++) {
it(`test toggleSubject with ${i} call(s)`, async () => {
const promise1 = getNumberOfTogglesPromise(service, i);
const promise2 = getNumberOfTogglesPromise(service, i + 1);
for (let j = 0; j < i; j++) {
service.toggleMenu();
}
await expectAsync(promise1).toBeResolved();
await expectAsync(promise2).toBePending();
});
}
});