refactoring RouteBuilderFactory into service
This commit is contained in:
parent
edd7314624
commit
2a59014f0b
7 changed files with 56 additions and 6 deletions
|
@ -3,7 +3,7 @@ import { quayConfig } from './quay.config';
|
|||
import quayPages from './quay-pages.module';
|
||||
import quayRun from './quay.run';
|
||||
import { ViewArrayFactory } from './services/view-array/view-array.factory';
|
||||
import { routeBuilderFactory } from './route-builder/route-builder.service.impl';
|
||||
import RouteBuilderFactory from './services/route-builder/route-builder.factory';
|
||||
import NAME_PATTERNS from './constants/name-patterns.constant';
|
||||
import { routeConfig } from './quay.routes';
|
||||
import { CONFIG } from './constants/quay-config.constant';
|
||||
|
@ -51,7 +51,7 @@ export default angular
|
|||
.config(routeConfig)
|
||||
.constant('NAME_PATTERNS', NAME_PATTERNS)
|
||||
.constant('CONFIG', CONFIG)
|
||||
.factory('RouteBuilder', routeBuilderFactory)
|
||||
.service('RouteBuilderFactory', RouteBuilderFactory)
|
||||
.service('ViewArrayFactory', ViewArrayFactory)
|
||||
.run(quayRun)
|
||||
.name;
|
|
@ -1,17 +1,18 @@
|
|||
import { RouteBuilder } from './route-builder/route-builder.service';
|
||||
import RouteBuilderFactory from './services/route-builder/route-builder.factory';
|
||||
import { RouteBuilder } from './services/route-builder/route-builder.service';
|
||||
import pages from './constants/pages.constant';
|
||||
|
||||
|
||||
routeConfig.$inject = [
|
||||
'pages',
|
||||
'RouteBuilderProvider',
|
||||
'RouteBuilderFactoryProvider',
|
||||
'$routeProvider',
|
||||
'$locationProvider',
|
||||
];
|
||||
|
||||
export function routeConfig(
|
||||
pages: any,
|
||||
RouteBuilderProvider: any,
|
||||
RouteBuilderFactoryProvider: any,
|
||||
$routeProvider: ng.route.IRouteProvider,
|
||||
$locationProvider: ng.ILocationProvider) {
|
||||
$locationProvider.html5Mode(true);
|
||||
|
@ -23,7 +24,7 @@ export function routeConfig(
|
|||
|
||||
var layoutProfile: string = 'layout';
|
||||
|
||||
var routeBuilder: RouteBuilder = new RouteBuilderProvider.$get()($routeProvider, pages, [
|
||||
var routeBuilder: RouteBuilder = RouteBuilderFactoryProvider.$get().create($routeProvider, pages, [
|
||||
// Start with the old pages (if we asked for it).
|
||||
{id: 'old-layout', templatePath: '/static/partials/'},
|
||||
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
import RouteBuilderFactory from './route-builder.factory';
|
||||
import { RouteBuilder } from "static/js/services/route-builder/route-builder.service";
|
||||
|
||||
|
||||
describe("Factory: RouteBuilderFactory", () => {
|
||||
var routeBuilderFactory: RouteBuilderFactory;
|
||||
var routeProviderMock;
|
||||
var pagesMock;
|
||||
var profiles;
|
||||
var currentProfile;
|
||||
|
||||
beforeEach(() => {
|
||||
profiles = [
|
||||
{id: 'old-layout', templatePath: '/static/partials/'},
|
||||
{id: 'layout', templatePath: '/static/partials/'}
|
||||
];
|
||||
currentProfile = 'layout';
|
||||
routeProviderMock = jasmine.createSpyObj('routeProvider', ['otherwise', 'when']);
|
||||
pagesMock = jasmine.createSpyObj('pagesMock', ['get', 'create']);
|
||||
routeBuilderFactory = new RouteBuilderFactory();
|
||||
});
|
||||
|
||||
describe("constructor", () => {
|
||||
|
||||
});
|
||||
|
||||
describe("create", () => {
|
||||
|
||||
it("returns a RouteBuilder instance", () => {
|
||||
var routeBuilder: RouteBuilder = routeBuilderFactory.create(routeProviderMock, pagesMock, profiles, currentProfile);
|
||||
|
||||
expect(routeBuilder).toBeDefined();
|
||||
});
|
||||
});
|
||||
});
|
14
static/js/services/route-builder/route-builder.factory.ts
Normal file
14
static/js/services/route-builder/route-builder.factory.ts
Normal file
|
@ -0,0 +1,14 @@
|
|||
import { RouteBuilder } from './route-builder.service';
|
||||
import { RouteBuilderImpl } from './route-builder.service.impl';
|
||||
|
||||
|
||||
export default class RouteBuilderFactory {
|
||||
|
||||
constructor() {
|
||||
|
||||
}
|
||||
|
||||
public create(routeProvider, pages, profiles, currentProfile): RouteBuilder {
|
||||
return new RouteBuilderImpl(routeProvider, pages, profiles, currentProfile);
|
||||
}
|
||||
}
|
Reference in a new issue