Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Feature help library #270

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
4b8fd4f
upgrading to helpclient v 1.0.2
Blackbaud-BrandonJones Sep 6, 2017
5d9ebdf
package update
Blackbaud-BrandonJones Sep 6, 2017
f23c760
added tests and updates to adding the BBHelpModule to skyPages based …
Blackbaud-BrandonJones Sep 8, 2017
a8bbec3
updated interface
Blackbaud-BrandonJones Sep 8, 2017
154c57c
updated test to use variable for clarity
Blackbaud-BrandonJones Sep 8, 2017
bdafc06
re-wording test for clarity
Blackbaud-BrandonJones Sep 8, 2017
71346ae
rewording for line length
Blackbaud-BrandonJones Sep 8, 2017
951cd3b
added test for no BBHelpModule import.
Blackbaud-BrandonJones Sep 8, 2017
c79b48d
Merge branch 'master' of github.com:blackbaud/skyux-builder into feat…
Blackbaud-BrandonJones Sep 13, 2017
ad10771
added skyux lib help
Blackbaud-BrandonJones Sep 13, 2017
c681c53
merge from master
Blackbaud-BrandonJones Sep 13, 2017
933603f
updated test and generator code
Blackbaud-BrandonJones Sep 14, 2017
b961740
test updates
Blackbaud-BrandonJones Sep 14, 2017
ebcc059
merge with master
Blackbaud-BrandonJones Sep 14, 2017
e631fcc
moved node module imports to separate array
Blackbaud-BrandonJones Sep 14, 2017
421ee11
Merge branch 'master' into feature-help-library
Blackbaud-PaulCrowder Sep 15, 2017
64d547c
Merge branch 'master' of github.com:blackbaud/skyux-builder into feat…
Blackbaud-BrandonJones Sep 18, 2017
17accda
updated tests and linter issues
Blackbaud-BrandonJones Sep 18, 2017
5f62229
Merge branch 'feature-help-library' of https://github.com/Blackbaud-B…
Blackbaud-BrandonJones Sep 18, 2017
3cab0bc
linting adjustment
Blackbaud-BrandonJones Sep 18, 2017
1c05167
made the bbHelpModule optional, updated tests, removed interface for …
Blackbaud-BrandonJones Sep 19, 2017
6812035
grammar fix
Blackbaud-BrandonJones Sep 19, 2017
a45d6df
nodeModuleImports
Blackbaud-BrandonJones Sep 19, 2017
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
50 changes: 32 additions & 18 deletions lib/sky-pages-module-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function getSource(skyAppConfig) {
];

const routes = routeGenerator.getRoutes(skyAppConfig);
const names = `${componentNames.concat(routes.names, runtimeComponents).join(',\n ')}`;
const names = componentNames.concat(routes.names, runtimeComponents);

skyAppConfig.runtime.routes = routes.routesForConfig;
const skyAppConfigAsString = JSON.stringify(skyAppConfig);
Expand Down Expand Up @@ -74,6 +74,26 @@ function getSource(skyAppConfig) {
}`);
}

let nodeModuleImports = [
`import {
Component,
Inject,
NgModule,
OnInit,
OnDestroy,
OpaqueToken
} from '@angular/core';`,
`import { CommonModule } from '@angular/common';`,
`import { HttpModule, XHRBackend, RequestOptions } from '@angular/http';`,
`import { FormsModule, ReactiveFormsModule } from '@angular/forms';`,
`import { ActivatedRoute, RouterModule, Routes } from '@angular/router';`,
`import { Subscription } from 'rxjs/Subscription';`
];

let runtimeModuleExports = [
...names
];

let runtimeModuleImports = [
'CommonModule',
'HttpModule',
Expand All @@ -83,6 +103,12 @@ function getSource(skyAppConfig) {
'AppExtrasModule'
];

if (skyAppConfig.skyux.help) {
nodeModuleImports.push(`import { BBHelpModule } from '@blackbaud/skyux-lib-help';`);
runtimeModuleImports.push('BBHelpModule');
runtimeModuleExports.push('BBHelpModule');
}

if (skyAppConfig.runtime.includeRouteModule) {
runtimeModuleImports.push('routing');
runtimeProviders.push('appRoutingProviders');
Expand Down Expand Up @@ -115,22 +141,10 @@ BBAuth.mock = true;

let moduleSource =
`${useMockAuth}
import '${skyAppConfig.runtime.skyPagesOutAlias}/src/main';

import {
Component,
Inject,
NgModule,
OnInit,
OnDestroy,
OpaqueToken
} from '@angular/core';

import { CommonModule } from '@angular/common';
import { HttpModule, XHRBackend, RequestOptions } from '@angular/http';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { ActivatedRoute, RouterModule, Routes } from '@angular/router';
import { Subscription } from 'rxjs/Subscription';
${nodeModuleImports.join('\n')}

import '${skyAppConfig.runtime.skyPagesOutAlias}/src/main';
import { SkyModule } from '${skyAppConfig.runtime.skyuxPathAlias}/core';
import {
AppExtrasModule
Expand Down Expand Up @@ -175,13 +189,13 @@ ${enableProdMode}

@NgModule({
declarations: [
${names}
${names.join(',\n' + codegen.indent(2))}
],
imports: [
${runtimeModuleImports.join(',\n' + codegen.indent(2))}
],
exports: [
${names}
${runtimeModuleExports.join(',\n' + codegen.indent(2))}
],
providers: [
${runtimeProviders.join(',\n' + codegen.indent(2))}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@angular/platform-browser-dynamic": "4.3.6",
"@angular/router": "4.3.6",
"@blackbaud/auth-client": "1.15.0",
"@blackbaud/help-client": "1.0.1",
"@blackbaud/skyux-lib-help": "1.0.0",
"@ngtools/webpack": "1.6.2",
"@types/core-js": "0.9.43",
"@types/fontfaceobserver": "0.0.5",
Expand Down
43 changes: 36 additions & 7 deletions src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import {
SkyAppStyleLoader,
SkyAppWindowRef
} from '@blackbaud/skyux-builder/runtime';
import { BBHelp } from '@blackbaud/help-client';

import { HelpInitializationService } from '@blackbaud/skyux-lib-help';

import { BBOmnibar, BBOmnibarSearchArgs } from '@blackbaud/auth-client';

import { AppComponent } from './app.component';
Expand Down Expand Up @@ -42,6 +44,12 @@ describe('AppComponent', () => {
}
};

class MockHelpInitService {
public load() { }
}

const mockHelpInitService = new MockHelpInitService();

function setup(
config: any,
includeSearchProvider?: boolean,
Expand Down Expand Up @@ -80,6 +88,10 @@ describe('AppComponent', () => {
useValue: {
loadStyles: () => Promise.resolve(styleLoadError)
}
},
{
provide: HelpInitializationService,
useValue: mockHelpInitService
}
];

Expand Down Expand Up @@ -229,7 +241,7 @@ describe('AppComponent', () => {
});
}));

it('should not markt he first service as select if another one is already marked', async(() => {
it('should not mark the first service as select if another one is already marked', async(() => {
let spyOmnibar = spyOn(BBOmnibar, 'load');
skyAppConfig.skyux.omnibar = {
nav: {
Expand Down Expand Up @@ -364,23 +376,40 @@ describe('AppComponent', () => {
});
}));

it('should not call BBHelp.load if config.skyux.help does not exist', async(() => {
let spyHelp = spyOn(BBHelp, 'load');
it('should not call HelpInitializationService.load if help config does not exist', async(() => {
let spyHelp = spyOn(mockHelpInitService, 'load');
setup(skyAppConfig).then(() => {
fixture.detectChanges();
expect(spyHelp).not.toHaveBeenCalled();
});
}));

it('should pass help config to BBHelp.load', async(() => {
let spyHelp = spyOn(BBHelp, 'load');
skyAppConfig.skyux.help = 'help-config';
it('should pass help config to HelpInitializationService.load', async(() => {
let spyHelp = spyOn(mockHelpInitService, 'load');
skyAppConfig.skyux.help = { productId: 'test-config' };
skyAppConfig.runtime.params.has = (key: any) => false;
setup(skyAppConfig).then(() => {
fixture.detectChanges();
expect(spyHelp).toHaveBeenCalledWith(skyAppConfig.skyux.help);
});
}));

it('should assign help config extends key to the svcid if one exists', async(() => {
let spyHelp = spyOn(mockHelpInitService, 'load');
const expectedCall = { productId: 'test-config', extends: 'help-extend' };
skyAppConfig.skyux.help = { productId: 'test-config' };

skyAppConfig.skyux.params = ['svcid'];
skyAppConfig.runtime.params.has = (key: any) => key === 'svcid';
skyAppConfig.runtime.params.get = (key: any) => key === 'svcid' ? 'help-extend' : false;

setup(skyAppConfig).then(() => {
fixture.detectChanges();
expect(spyHelp).not.toHaveBeenCalledWith(skyAppConfig.skyux.help);
expect(spyHelp).toHaveBeenCalledWith(expectedCall);
});
}));

it('should set isReady after SkyAppStyleLoader.loadStyles is resolved', async(() => {
setup(skyAppConfig).then(() => {
expect(comp.isReady).toEqual(true);
Expand Down
12 changes: 9 additions & 3 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
BBOmnibarSearchArgs
} from '@blackbaud/auth-client';

import { BBHelp } from '@blackbaud/help-client';
import { HelpInitializationService } from '@blackbaud/skyux-lib-help';

import {
SkyAppConfig,
Expand Down Expand Up @@ -74,6 +74,7 @@ export class AppComponent implements OnInit {
private windowRef: SkyAppWindowRef,
private config: SkyAppConfig,
private styleLoader: SkyAppStyleLoader,
@Optional() private helpInitService?: HelpInitializationService,
@Optional() private searchProvider?: SkyAppSearchResultsProvider
) {
this.styleLoader.loadStyles()
Expand Down Expand Up @@ -193,8 +194,13 @@ export class AppComponent implements OnInit {
BBOmnibar.load(omnibarConfig);
}

if (helpConfig) {
BBHelp.load(helpConfig);
if (helpConfig && this.helpInitService) {

if (this.config.runtime.params.has('svcid')) {
helpConfig.extends = this.config.runtime.params.get('svcid');
}

this.helpInitService.load(helpConfig);
}
}
}
1 change: 0 additions & 1 deletion test/sky-pages-component-generator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,4 @@ describe('SKY UX Builder component generator', () => {
});
expect(components.names.length).toEqual(0);
});

});
91 changes: 87 additions & 4 deletions test/sky-pages-module-generator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@

const codegen = require('../utils/codegen-utils');

const getModuleList = (listName, content) => {
const listRegExp = new RegExp(`${listName}:\\s\\[([\\s\\S]*?).*?\\]`, 'g');
const list = content.match(listRegExp);
return list ? list[0] : [];
}

describe('SKY UX Builder module generator', () => {

const runtimeUtils = require('../utils/runtime-test-utils.js');
Expand All @@ -20,6 +26,43 @@ describe('SKY UX Builder module generator', () => {
expect(source).toBeDefined();
});

it('should import modules from the nodeModuleImports', () => {
const expectedImport = `import { CommonModule } from '@angular/common';`;

let source = generator.getSource({
runtime: runtimeUtils.getDefaultRuntime(),
skyux: {}
});

expect(source).toContain(expectedImport);
});

it('should export modules from the runtimeModuleExports', () => {
const expectedExport = 'AppComponent';

let source = generator.getSource({
runtime: runtimeUtils.getDefaultRuntime(),
skyux: {}
});

let moduleExports = getModuleList('exports', source);

expect(moduleExports).toContain(expectedExport);
});

it('should import modules from the runtimeModuleImports', () => {
const expectedImport = 'CommonModule';

let source = generator.getSource({
runtime: runtimeUtils.getDefaultRuntime(),
skyux: {}
});

let moduleImports = getModuleList('imports', source);

expect(moduleImports).toContain(expectedImport);
});

it('should add the NotFoundComponent if it does not exist', () => {
const source = generator.getSource({
runtime: runtimeUtils.getDefaultRuntime(),
Expand Down Expand Up @@ -102,15 +145,53 @@ describe('SKY UX Builder module generator', () => {
expect(source).toContain(expectedProvider);
});

it('should not include routing in the module if includeRouteModule is false', () => {
it('should not add BBHelpModule if the help config does not exists.', () => {
const expectedModule = 'BBHelpModule';
const expectedNodeModule = `import { BBHelpModule } from '@blackbaud/skyux-lib-help';`;

let source = generator.getSource({
runtime: runtimeUtils.getDefaultRuntime(),
skyux: {}
});

let moduleImports = getModuleList('imports', source);
let moduleExports = getModuleList('exports', source);

expect(source).not.toContain(expectedNodeModule);
expect(moduleImports).not.toContain(expectedModule);
expect(moduleExports).not.toContain(expectedModule);
});

it('should add BBHelpModule if the help config exists.', () => {
const expectedModule = 'BBHelpModule';
const expectedNodeModule = `import { BBHelpModule } from '@blackbaud/skyux-lib-help';`;

let expectedRouting = `AppExtrasModule,\n${codegen.indent(2)}routing`;
let source = generator.getSource({
runtime: runtimeUtils.getDefaultRuntime(),
skyux: {
help: {}
}
});

let moduleImports = getModuleList('imports', source);
let moduleExports = getModuleList('exports', source);

expect(source).toContain(expectedNodeModule);
expect(moduleImports).toContain(expectedModule);
expect(moduleExports).toContain(expectedModule);
});

it('should not include routing in the module imports if includeRouteModule is false', () => {

const expectedImport = `routing`;
let sourceWithRouting = generator.getSource({
runtime: runtimeUtils.getDefaultRuntime(),
skyux: {}
});

expect(sourceWithRouting).toContain(expectedRouting);
let moduleImports = getModuleList('imports', sourceWithRouting);

expect(moduleImports).toContain(expectedImport);

let sourceWithoutRouting = generator.getSource(
{
Expand All @@ -120,7 +201,9 @@ describe('SKY UX Builder module generator', () => {
skyux: {}
});

expect(sourceWithoutRouting).not.toContain(expectedRouting);
moduleImports = getModuleList('imports', sourceWithoutRouting);

expect(moduleImports).not.toContain(expectedImport);
});

it('should call `enableProdMode` if the command is build', () => {
Expand Down