-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for main menu service (#2830)
- Loading branch information
1 parent
c063560
commit 7a71c20
Showing
1 changed file
with
43 additions
and
5 deletions.
There are no files selected for viewing
48 changes: 43 additions & 5 deletions
48
client/src/app/site/pages/meetings/services/main-menu.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
} | ||
}); |