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 20 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
49 changes: 30 additions & 19 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,13 +74,36 @@ function getSource(skyAppConfig) {
}`);
}

let nodeModulesImports = [
`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';`,
`import { BBHelpModule } from '@blackbaud/skyux-lib-help';`
];

let runtimeModuleExports = [
...names,
'BBHelpModule'
];

let runtimeModuleImports = [
'CommonModule',
'HttpModule',
'FormsModule',
'ReactiveFormsModule',
'SkyModule',
'AppExtrasModule'
'AppExtrasModule',
'BBHelpModule'
];

if (skyAppConfig.runtime.includeRouteModule) {
Expand Down Expand Up @@ -115,22 +138,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';
${nodeModulesImports.join('\n')}

import '${skyAppConfig.runtime.skyPagesOutAlias}/src/main';
import { SkyModule } from '${skyAppConfig.runtime.skyuxPathAlias}/core';
import {
AppExtrasModule
Expand Down Expand Up @@ -175,13 +186,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
21 changes: 20 additions & 1 deletion runtime/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,25 @@ export interface RuntimeConfig {
useTemplateUrl: boolean;
}

export interface HelpWidgetConfig {
extends?: string;
productId?: string;
defaultHelpKey?: string;
locale?: string;
helpBaseUrl?: string;
customLocales?: string[];
headerColor?: string;
headerTextColor?: string;
trainingCentralUrl?: string;
knowledgeBaseUrl?: string;
caseCentralUrl?: string;
helpCentralUrl?: string;
hideUndock?: boolean;
hideWidgetOnMobile?: boolean;
hideHelpChat?: boolean;
useFlareSearch?: boolean;
}

export interface SkyuxConfigA11y {
rules?: any;
}
Expand All @@ -47,7 +66,7 @@ export interface SkyuxConfig {
cssPath?: string;
command?: string;
compileMode?: string;
help?: any;
help?: HelpWidgetConfig;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious about the creation of this interface. We'd previous used interfaces for the auth and help clients. We decided against that; however, as somewhat painfully tied those libraries to builder, but without any benefit (consumers never use the interface).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. I added it because I was using it for the Help Library and thought builder may want to also make use of it. That being said, having to update it in multiple places should one change would be a pain, I am fine with removing it.

host?: SkyuxConfigHost;
importPath?: string;
mode?: string;
Expand Down
41 changes: 35 additions & 6 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 @@ -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
10 changes: 8 additions & 2 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,
private helpInitService: HelpInitializationService,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use a similar approach to the optional searchProvider below this line, and mark the service as optional + check for it's existence for using it? I believe this would allow us to conditionally inject it in lib/sky-pages-module-generator.js, thereby not including the library for SPAs that don't have help defined in skyuxconfig.json. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good thoughts! I'll see what I can do.

@Optional() private searchProvider?: SkyAppSearchResultsProvider
) {
this.styleLoader.loadStyles()
Expand Down Expand Up @@ -194,7 +195,12 @@ export class AppComponent implements OnInit {
}

if (helpConfig) {
BBHelp.load(helpConfig);

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);
});

});
46 changes: 42 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 Down Expand Up @@ -102,15 +108,45 @@ describe('SKY UX Builder module generator', () => {
expect(source).toContain(expectedProvider);
});

it('should not include routing in the module if includeRouteModule is false', () => {
it('should import modules from the nodeModuleImports', () => {
const expectedImport = `import { BBHelpModule } from '@blackbaud/skyux-lib-help'`;

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

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

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

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

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

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

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 +156,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