blob: a710b006e529211942bfe29805146e1d42442717 [file] [log] [blame]
/**
* @license
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Init app context before any other imports
import {create, Registry, Finalizable} from '../services/registry';
import {assertIsDefined} from '../utils/common-util';
import {AppContext, injectAppContext} from '../services/app-context';
import {grReportingMock} from '../services/gr-reporting/gr-reporting_mock';
import {grRestApiMock} from './mocks/gr-rest-api_mock';
import {grStorageMock} from '../services/storage/gr-storage_mock';
import {GrAuthMock} from '../services/gr-auth/gr-auth_mock';
import {FlagsServiceImplementation} from '../services/flags/flags_impl';
import {EventEmitter} from '../services/gr-event-interface/gr-event-interface_impl';
import {ChangeService} from '../services/change/change-service';
import {ChecksService} from '../services/checks/checks-service';
import {GrJsApiInterface} from '../elements/shared/gr-js-api-interface/gr-js-api-interface-element';
import {ConfigService} from '../services/config/config-service';
import {UserModel} from '../services/user/user-model';
import {CommentsService} from '../services/comments/comments-service';
import {ShortcutsService} from '../services/shortcuts/shortcuts-service';
import {BrowserModel} from '../services/browser/browser-model';
let appContext: (AppContext & Finalizable) | undefined;
export function _testOnlyInitAppContext() {
const appRegistry: Registry<AppContext> = {
flagsService: (_ctx: Partial<AppContext>) =>
new FlagsServiceImplementation(),
reportingService: (_ctx: Partial<AppContext>) => grReportingMock,
eventEmitter: (_ctx: Partial<AppContext>) => new EventEmitter(),
authService: (ctx: Partial<AppContext>) => {
assertIsDefined(ctx.eventEmitter, 'eventEmitter');
return new GrAuthMock(ctx.eventEmitter);
},
restApiService: (_ctx: Partial<AppContext>) => grRestApiMock,
changeService: (ctx: Partial<AppContext>) => {
assertIsDefined(ctx.restApiService, 'restApiService');
return new ChangeService(ctx.restApiService!);
},
commentsService: (ctx: Partial<AppContext>) => {
assertIsDefined(ctx.restApiService, 'restApiService');
return new CommentsService(ctx.restApiService!);
},
checksService: (ctx: Partial<AppContext>) => {
assertIsDefined(ctx.reportingService, 'reportingService');
return new ChecksService(ctx.reportingService!);
},
jsApiService: (ctx: Partial<AppContext>) => {
assertIsDefined(ctx.reportingService, 'reportingService');
return new GrJsApiInterface(ctx.reportingService!);
},
storageService: (_ctx: Partial<AppContext>) => grStorageMock,
configService: (ctx: Partial<AppContext>) => {
assertIsDefined(ctx.restApiService, 'restApiService');
return new ConfigService(ctx.restApiService!);
},
userModel: (ctx: Partial<AppContext>) => {
assertIsDefined(ctx.restApiService, 'restApiService');
return new UserModel(ctx.restApiService!);
},
shortcutsService: (ctx: Partial<AppContext>) => {
assertIsDefined(ctx.userModel, 'userModel');
assertIsDefined(ctx.reportingService, 'reportingService');
return new ShortcutsService(ctx.userModel!, ctx.reportingService!);
},
browserModel: (ctx: Partial<AppContext>) => {
assertIsDefined(ctx.userModel, 'userModel');
return new BrowserModel(ctx.userModel!);
},
};
appContext = create<AppContext>(appRegistry);
injectAppContext(appContext);
}
export function _testOnlyFinalizeAppContext() {
appContext?.finalize();
appContext = undefined;
}