-
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 RepositoryServiceCollectorServices
- Loading branch information
1 parent
412525f
commit 7d5a687
Showing
2 changed files
with
101 additions
and
20 deletions.
There are no files selected for viewing
104 changes: 100 additions & 4 deletions
104
client/src/app/gateways/repositories/repository-meeting-service-collector.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,112 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { TranslateService } from '@ngx-translate/core'; | ||
import { firstValueFrom, skip } from 'rxjs'; | ||
import { ActiveMeetingService } from 'src/app/site/pages/meetings/services/active-meeting.service'; | ||
import { ActiveMeetingIdService } from 'src/app/site/pages/meetings/services/active-meeting-id.service'; | ||
import { MeetingSettingsService } from 'src/app/site/pages/meetings/services/meeting-settings.service'; | ||
import { CollectionMapperService } from 'src/app/site/services/collection-mapper.service'; | ||
import { DataStoreService } from 'src/app/site/services/data-store.service'; | ||
import { RelationManagerService } from 'src/app/site/services/relation-manager.service'; | ||
import { ViewModelStoreService } from 'src/app/site/services/view-model-store.service'; | ||
|
||
import { ActionService } from '../actions'; | ||
import { RepositoryMeetingServiceCollectorService } from './repository-meeting-service-collector.service'; | ||
import { RepositoryServiceCollectorService } from './repository-service-collector.service'; | ||
|
||
xdescribe(`RepositoryMeetingServiceCollectorService`, () => { | ||
abstract class MockService { | ||
public abstract readonly name: keyof RepositoryMeetingServiceCollectorService; | ||
} | ||
class MockDataStore extends MockService { | ||
public readonly name = `DS`; | ||
} | ||
class MockAction extends MockService { | ||
public readonly name = `actionService`; | ||
} | ||
class MockCollectionMapper extends MockService { | ||
public readonly name = `collectionMapperService`; | ||
} | ||
class MockViewModelStore extends MockService { | ||
public readonly name = `viewModelStoreService`; | ||
} | ||
class MockTranslate extends MockService { | ||
public readonly name = `translate`; | ||
} | ||
class MockRelationManager extends MockService { | ||
public readonly name = `relationManager`; | ||
} | ||
class MockActiveMeetingId extends MockService { | ||
public readonly name = `activeMeetingIdService`; | ||
} | ||
class MockActiveMeeting extends MockService { | ||
public readonly name = `activeMeetingService`; | ||
} | ||
class MockMeetingSettings extends MockService { | ||
public readonly name = `meetingSettingsService`; | ||
} | ||
|
||
describe(`RepositoryMeetingServiceCollectorService and MeetingServiceCollectorService`, () => { | ||
let service: RepositoryMeetingServiceCollectorService; | ||
|
||
const serviceGetterTestCases: (keyof RepositoryMeetingServiceCollectorService)[] = [ | ||
`DS`, | ||
`actionService`, | ||
`collectionMapperService`, | ||
`viewModelStoreService`, | ||
`translate`, | ||
`relationManager`, | ||
`activeMeetingIdService`, | ||
`activeMeetingService`, | ||
`meetingSettingsService` | ||
]; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
TestBed.configureTestingModule({ | ||
providers: [ | ||
RepositoryMeetingServiceCollectorService, | ||
RepositoryServiceCollectorService, | ||
{ provide: ActiveMeetingIdService, useClass: MockActiveMeetingId }, | ||
{ provide: ActiveMeetingService, useClass: MockActiveMeeting }, | ||
{ provide: MeetingSettingsService, useClass: MockMeetingSettings }, | ||
{ provide: DataStoreService, useClass: MockDataStore }, | ||
{ provide: ActionService, useClass: MockAction }, | ||
{ provide: CollectionMapperService, useClass: MockCollectionMapper }, | ||
{ provide: ViewModelStoreService, useClass: MockViewModelStore }, | ||
{ provide: TranslateService, useClass: MockTranslate }, | ||
{ provide: RelationManagerService, useClass: MockRelationManager } | ||
] | ||
}); | ||
service = TestBed.inject(RepositoryMeetingServiceCollectorService); | ||
}); | ||
|
||
it(`should be created`, () => { | ||
expect(service).toBeTruthy(); | ||
for (const testCase of serviceGetterTestCases) { | ||
it(`test service getter '${testCase}'`, () => { | ||
expect(service[testCase][`name`]).toBe(testCase); | ||
}); | ||
} | ||
|
||
it(`test collectionToKeyUpdatesObservableMap`, async () => { | ||
service.registerNewKeyUpdates(`A collection`, [`key1`, `key2`, `abc`]); | ||
service.registerNewKeyUpdates(`B collection`, [`1`, `2`, `something`]); | ||
expect( | ||
Object.keys(service.collectionToKeyUpdatesObservableMap).flatMap(key => [ | ||
key, | ||
service.collectionToKeyUpdatesObservableMap[key].value | ||
]) | ||
).toEqual([`A collection`, [`key1`, `key2`, `abc`], `B collection`, [`1`, `2`, `something`]]); | ||
const promise = firstValueFrom(service.getNewKeyUpdatesObservable(`A collection`).pipe(skip(1))); | ||
service.registerNewKeyUpdates(`A collection`, [`a`, `b`, `c`]); | ||
await expectAsync(promise).toBeResolvedTo([`a`, `b`, `c`]); | ||
}); | ||
|
||
it(`test collectionToKeyUpdatesObservableMap for yet unknown collection`, async () => { | ||
const promise = firstValueFrom(service.getNewKeyUpdatesObservable(`C collection`).pipe(skip(1))); | ||
expect( | ||
Object.keys(service.collectionToKeyUpdatesObservableMap).flatMap(key => [ | ||
key, | ||
service.collectionToKeyUpdatesObservableMap[key].value | ||
]) | ||
).toEqual([`C collection`, []]); | ||
service.registerNewKeyUpdates(`C collection`, [`a`, `b`, `c`]); | ||
await expectAsync(promise).toBeResolvedTo([`a`, `b`, `c`]); | ||
}); | ||
}); |
17 changes: 1 addition & 16 deletions
17
client/src/app/gateways/repositories/repository-service-collector.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 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { RepositoryServiceCollectorService } from './repository-service-collector.service'; | ||
|
||
xdescribe(`RepositoryServiceCollectorService`, () => { | ||
let service: RepositoryServiceCollectorService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(RepositoryServiceCollectorService); | ||
}); | ||
|
||
it(`should be created`, () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); | ||
// See repository-meeting-service-collector.service.spec.ts |