2016-05-27 15:36:24 -04:00
|
|
|
import {MockLocationStrategy} from '@angular/common/testing';
|
2016-06-08 19:38:52 -04:00
|
|
|
import {COMPILER_PROVIDERS, DirectiveResolver, ViewResolver, XHR} from '@angular/compiler';
|
|
|
|
import {MockDirectiveResolver, MockViewResolver, TestComponentBuilder, TestComponentRenderer} from '@angular/compiler/testing';
|
|
|
|
import {APPLICATION_COMMON_PROVIDERS, APP_ID, NgZone, PLATFORM_COMMON_PROVIDERS, PLATFORM_INITIALIZER, RootRenderer} from '@angular/core';
|
2016-05-17 18:52:35 -04:00
|
|
|
import {BrowserDetection, DOMTestComponentRenderer} from '@angular/platform-browser/testing';
|
2016-06-08 19:38:52 -04:00
|
|
|
|
2016-05-25 15:46:22 -04:00
|
|
|
import {AnimationDriver, NoOpAnimationDriver} from '../core_private';
|
2016-06-08 19:38:52 -04:00
|
|
|
import {Parse5DomAdapter} from '../index';
|
|
|
|
|
|
|
|
import {DOCUMENT, BROWSER_SANITIZATION_PROVIDERS, EventManager, EVENT_MANAGER_PLUGINS, ELEMENT_PROBE_PROVIDERS, DomEventsPlugin,} from '@angular/platform-browser';
|
2016-05-27 15:36:24 -04:00
|
|
|
import {getDOM, DomRootRenderer, DomRootRenderer_, DomSharedStylesHost, SharedStylesHost} from '../platform_browser_private';
|
2016-05-17 18:52:35 -04:00
|
|
|
import {LocationStrategy} from '@angular/common';
|
|
|
|
import {Log} from '@angular/core/testing';
|
2015-12-15 19:38:27 -05:00
|
|
|
|
|
|
|
function initServerTests() {
|
|
|
|
Parse5DomAdapter.makeCurrent();
|
|
|
|
BrowserDetection.setup();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-04-14 23:59:44 -04:00
|
|
|
* Default platform providers for testing.
|
2015-12-15 19:38:27 -05:00
|
|
|
*/
|
2016-04-26 00:47:33 -04:00
|
|
|
export const TEST_SERVER_PLATFORM_PROVIDERS: Array<any /*Type | Provider | any[]*/> =
|
2016-04-26 01:25:21 -04:00
|
|
|
/*@ts2dart_const*/[
|
2016-04-26 00:47:33 -04:00
|
|
|
PLATFORM_COMMON_PROVIDERS,
|
2016-06-08 19:38:52 -04:00
|
|
|
/*@ts2dart_Provider*/ {
|
|
|
|
provide: PLATFORM_INITIALIZER,
|
|
|
|
useValue: initServerTests,
|
|
|
|
multi: true
|
|
|
|
}
|
2016-04-26 00:58:48 -04:00
|
|
|
];
|
2015-12-15 19:38:27 -05:00
|
|
|
|
|
|
|
function appDoc() {
|
|
|
|
try {
|
2016-04-28 20:50:03 -04:00
|
|
|
return getDOM().defaultDoc();
|
2015-12-15 19:38:27 -05:00
|
|
|
} catch (e) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-28 20:50:03 -04:00
|
|
|
|
|
|
|
function createNgZone(): NgZone {
|
|
|
|
return new NgZone({enableLongStackTrace: true});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-15 19:38:27 -05:00
|
|
|
/**
|
|
|
|
* Default application providers for testing.
|
|
|
|
*/
|
|
|
|
export const TEST_SERVER_APPLICATION_PROVIDERS: Array<any /*Type | Provider | any[]*/> =
|
2016-04-26 01:25:21 -04:00
|
|
|
/*@ts2dart_const*/[
|
2016-04-26 00:47:33 -04:00
|
|
|
// TODO(julie: when angular2/platform/server is available, use that instead of making our own
|
2015-12-15 19:38:27 -05:00
|
|
|
// list here.
|
2016-06-08 19:38:52 -04:00
|
|
|
APPLICATION_COMMON_PROVIDERS, COMPILER_PROVIDERS, BROWSER_SANITIZATION_PROVIDERS,
|
2016-04-26 01:25:21 -04:00
|
|
|
/* @ts2dart_Provider */ {provide: DOCUMENT, useFactory: appDoc},
|
|
|
|
/* @ts2dart_Provider */ {provide: DomRootRenderer, useClass: DomRootRenderer_},
|
|
|
|
/* @ts2dart_Provider */ {provide: RootRenderer, useExisting: DomRootRenderer},
|
2016-05-25 15:46:22 -04:00
|
|
|
/* @ts2dart_Provider */ {provide: AnimationDriver, useClass: NoOpAnimationDriver},
|
2015-12-15 19:38:27 -05:00
|
|
|
EventManager,
|
2016-06-08 19:38:52 -04:00
|
|
|
/* @ts2dart_Provider */ {
|
|
|
|
provide: EVENT_MANAGER_PLUGINS,
|
|
|
|
useClass: DomEventsPlugin,
|
|
|
|
multi: true
|
|
|
|
},
|
2016-04-26 01:25:21 -04:00
|
|
|
/* @ts2dart_Provider */ {provide: XHR, useClass: XHR},
|
|
|
|
/* @ts2dart_Provider */ {provide: APP_ID, useValue: 'a'},
|
|
|
|
/* @ts2dart_Provider */ {provide: SharedStylesHost, useExisting: DomSharedStylesHost},
|
2016-06-08 19:38:52 -04:00
|
|
|
DomSharedStylesHost, ELEMENT_PROBE_PROVIDERS,
|
2016-04-26 01:25:21 -04:00
|
|
|
/* @ts2dart_Provider */ {provide: DirectiveResolver, useClass: MockDirectiveResolver},
|
2016-06-08 19:38:52 -04:00
|
|
|
/* @ts2dart_Provider */ {provide: ViewResolver, useClass: MockViewResolver}, Log,
|
2016-04-28 20:50:03 -04:00
|
|
|
/* @ts2dart_Provider */ {provide: TestComponentRenderer, useClass: DOMTestComponentRenderer},
|
2015-12-15 19:38:27 -05:00
|
|
|
TestComponentBuilder,
|
2016-04-26 01:25:21 -04:00
|
|
|
/* @ts2dart_Provider */ {provide: NgZone, useFactory: createNgZone},
|
2016-05-25 15:46:22 -04:00
|
|
|
/* @ts2dart_Provider */ {provide: LocationStrategy, useClass: MockLocationStrategy}
|
2016-04-26 00:58:48 -04:00
|
|
|
];
|