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 bootstrap rest mocks for jasmine specs #987

Merged
merged 1 commit into from
May 13, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions eclipse-scout-core/src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export interface AppBootstrapOptions {
configUrl?: string | string[];
/**
* Custom functions that needs to be executed while bootstrapping.
* All custom and default bootrappers need to finish successfully before the app will proceed with the initialization.
* All custom and default bootstrappers need to finish successfully before the app will proceed with the initialization.
*/
bootstrappers?: (() => JQuery.Promise<void>)[];
}
Expand All @@ -90,11 +90,11 @@ export class App extends EventEmitter {
* Adds a function that needs to be executed while bootstrapping.
* @see AppModel.bootstrappers
*/
static addBootstrapper(bootrapper: () => JQuery.Promise<void>) {
if (bootstrappers.indexOf(bootrapper) > -1) {
static addBootstrapper(bootstrapper: () => JQuery.Promise<void>) {
if (bootstrappers.indexOf(bootstrapper) > -1) {
throw new Error('Bootstrapper is already registered.');
}
bootstrappers.push(bootrapper);
bootstrappers.push(bootstrapper);
}

static get(): App {
Expand Down
4 changes: 2 additions & 2 deletions eclipse-scout-core/src/RemoteApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class RemoteApp extends App {

protected override _defaultBootstrappers(options: AppBootstrapOptions): (() => JQuery.Promise<void>)[] {
return super._defaultBootstrappers(options).concat(
this._defaultValuesBootrapper(),
this._defaultValuesBootstrapper(),
this._configPropertiesBootstrapper(options)
);
}
Expand All @@ -32,7 +32,7 @@ export class RemoteApp extends App {
return config.bootstrapSystem.bind(config);
}

protected _defaultValuesBootrapper(): () => JQuery.Promise<void> {
protected _defaultValuesBootstrapper(): () => JQuery.Promise<void> {
return defaultValues.bootstrap.bind(defaultValues);
}

Expand Down
13 changes: 11 additions & 2 deletions eclipse-scout-core/src/testing/JasmineScout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
* SPDX-License-Identifier: EPL-2.0
*/
import {
AdapterData, App, arrays, Desktop, FullModelOf, HtmlEnvironment, InitModelOf, JsonErrorResponse, ModelAdapter, ModelOf, ObjectFactory, RemoteEvent, RemoteRequest, RemoteResponse, scout, Session, SessionStartupResponse, Widget, WidgetModel
AdapterData, App, arrays, Desktop, FullModelOf, HtmlEnvironment, InitModelOf, JsonErrorResponse, ModelAdapter, ModelOf, ObjectFactory, PermissionCollectionType, RemoteEvent, RemoteRequest, RemoteResponse, scout, Session,
SessionStartupResponse, Widget, WidgetModel
} from '../index';
import {jasmineScoutMatchers, LocaleSpecHelper, TestingApp} from './index';
import {jasmineScoutMatchers, JasmineScoutUtil, LocaleSpecHelper, TestingApp} from './index';
import 'jasmine-jquery';
import $ from 'jquery';

Expand Down Expand Up @@ -261,14 +262,22 @@ export const JasmineScout = {

context.keys().forEach(context);
},

startApp(App: new() => App) {
// App initialization uses promises which are executed asynchronously
// -> Use the clock to make sure all promise callbacks are executed before any test starts.
jasmine.clock().install();
jasmine.Ajax.install();

new App().init();

jasmine.clock().tick(1000);

jasmine.Ajax.uninstall();
jasmine.clock().uninstall();
}
};

JasmineScoutUtil.mockRestCall('api/permissions', {type: PermissionCollectionType.ALL});
JasmineScoutUtil.mockRestCall('api/codes', {});
JasmineScoutUtil.mockRestCall('api/parameters', []);
2 changes: 1 addition & 1 deletion eclipse-scout-core/src/testing/TestingApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {App, AppBootstrapOptions, Device, InitModelOf, RemoteApp, Session} from

export class TestingApp extends RemoteApp {

protected override _defaultValuesBootrapper(): () => JQuery.Promise<void> {
protected override _defaultValuesBootstrapper(): () => JQuery.Promise<void> {
// nop for testing
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion eclipse-scout-core/src/testing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {ObjectFactory} from '../index';
import * as self from './index';

export * from './TestingApp';
export * from './JasmineScout';
export * from './JasmineScoutUtil';
export * from './JasmineScout';
export * from './text/LocaleSpecHelper';
export * from './menu/MenuSpecHelper';
export * from './security/accessSpecHelper';
Expand Down