Skip to content

Commit 5e9afad

Browse files
authored
feat(components/tiles): add inline help support for tile dashboard (#563)
* feat(components/tiles): add inline help support for tile dashboard * Add providers to tests * Add coverage
1 parent d0db9a9 commit 5e9afad

16 files changed

+159
-23
lines changed

apps/e2e/tiles-storybook/project.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"executor": "@angular-devkit/build-angular:browser",
88
"outputs": ["{options.outputPath}"],
99
"options": {
10+
"allowedCommonJsDependencies": ["dragula", "ng2-dragula"],
1011
"outputPath": "dist/apps/e2e/tiles-storybook",
1112
"index": "apps/e2e/tiles-storybook/src/index.html",
1213
"main": "apps/e2e/tiles-storybook/src/main.ts",

apps/e2e/tiles-storybook/src/app/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { NgModule } from '@angular/core';
22
import { BrowserModule } from '@angular/platform-browser';
3+
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
34
import { Route, RouterModule } from '@angular/router';
45

56
import { AppComponent } from './app.component';
@@ -21,6 +22,7 @@ if (routes.length > 0 && routes.findIndex((r) => r.path === '') === -1) {
2122
declarations: [AppComponent],
2223
imports: [
2324
BrowserModule,
25+
NoopAnimationsModule,
2426
RouterModule.forRoot(routes, { initialNavigation: 'enabledBlocking' }),
2527
],
2628
bootstrap: [AppComponent],

apps/e2e/tiles-storybook/src/app/tile-dashboard/tile-dashboard.component.spec.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { ComponentFixture, TestBed, fakeAsync } from '@angular/core/testing';
1+
import {
2+
ComponentFixture,
3+
TestBed,
4+
fakeAsync,
5+
tick,
6+
} from '@angular/core/testing';
27
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
38

49
import { TileDashboardComponent } from './tile-dashboard.component';
@@ -33,9 +38,8 @@ describe('TileDashboardComponent', () => {
3338

3439
it('should create', fakeAsync(() => {
3540
expect(component).toBeTruthy();
36-
fixture.detectChanges();
37-
fixture.whenStable().then(() => {
38-
expect(component.ready$.getValue()).toBeTruthy();
39-
});
41+
component.ngAfterViewInit();
42+
tick();
43+
expect(component.ready$.getValue()).toBeTruthy();
4044
}));
4145
});

apps/e2e/tiles-storybook/src/app/tile-dashboard/tile-dashboard.component.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { BehaviorSubject } from 'rxjs';
55

66
import { Tile1Component } from './tile1/tile1.component';
77
import { Tile2Component } from './tile2/tile2.component';
8+
import { TileParameters } from './tile-parameters.token';
89

910
@Component({
1011
selector: 'app-tile-dashboard',
@@ -17,10 +18,54 @@ export class TileDashboardComponent implements AfterViewInit {
1718
{
1819
id: 'tile1',
1920
componentType: Tile1Component,
21+
providers: [
22+
{
23+
provide: TileParameters,
24+
useValue: {
25+
tileName: 'Tile 1',
26+
showInlineHelp: false,
27+
},
28+
},
29+
],
2030
},
2131
{
2232
id: 'tile2',
2333
componentType: Tile2Component,
34+
providers: [
35+
{
36+
provide: TileParameters,
37+
useValue: {
38+
tileName: 'Tile 2',
39+
showInlineHelp: false,
40+
},
41+
},
42+
],
43+
},
44+
{
45+
id: 'tile3',
46+
componentType: Tile1Component,
47+
providers: [
48+
{
49+
provide: TileParameters,
50+
useValue: {
51+
tileName: 'Tile 3',
52+
showInlineHelp: true,
53+
},
54+
},
55+
],
56+
},
57+
{
58+
id: 'tile4',
59+
componentType: Tile2Component,
60+
providers: [
61+
{
62+
provide: TileParameters,
63+
useValue: {
64+
tileName: 'Tile 4',
65+
showInlineHelp: true,
66+
},
67+
},
68+
],
2469
},
2570
],
2671
layout: {
@@ -34,6 +79,14 @@ export class TileDashboardComponent implements AfterViewInit {
3479
id: 'tile1',
3580
isCollapsed: true,
3681
},
82+
{
83+
id: 'tile3',
84+
isCollapsed: true,
85+
},
86+
{
87+
id: 'tile4',
88+
isCollapsed: true,
89+
},
3790
],
3891
},
3992
multiColumn: [
@@ -43,6 +96,14 @@ export class TileDashboardComponent implements AfterViewInit {
4396
id: 'tile1',
4497
isCollapsed: true,
4598
},
99+
{
100+
id: 'tile3',
101+
isCollapsed: true,
102+
},
103+
{
104+
id: 'tile4',
105+
isCollapsed: true,
106+
},
46107
],
47108
},
48109
{

apps/e2e/tiles-storybook/src/app/tile-dashboard/tile-dashboard.module.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { CommonModule } from '@angular/common';
22
import { NgModule } from '@angular/core';
33
import { RouterModule, Routes } from '@angular/router';
4+
import { SkyHelpInlineModule } from '@skyux/indicators';
45
import { SkyTilesModule } from '@skyux/tiles';
56

67
import { Tile1Component } from './tile1/tile1.component';
@@ -10,7 +11,12 @@ import { TileDashboardComponent } from './tile-dashboard.component';
1011
const routes: Routes = [{ path: '', component: TileDashboardComponent }];
1112
@NgModule({
1213
declarations: [TileDashboardComponent, Tile1Component, Tile2Component],
13-
imports: [CommonModule, RouterModule.forChild(routes), SkyTilesModule],
14+
imports: [
15+
CommonModule,
16+
RouterModule.forChild(routes),
17+
SkyTilesModule,
18+
SkyHelpInlineModule,
19+
],
1420
exports: [TileDashboardComponent],
1521
})
1622
export class TileDashboardModule {}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { InjectionToken } from '@angular/core';
2+
3+
import { TileParametersType } from './tile-parameters.type';
4+
5+
export const TileParameters = new InjectionToken<TileParametersType>(
6+
'TileParameters'
7+
);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export type TileParametersType = {
2+
tileName: string;
3+
showInlineHelp: boolean;
4+
};

apps/e2e/tiles-storybook/src/app/tile-dashboard/tile1/tile1.component.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<sky-tile (settingsClick)="tileSettingsClick()">
2-
<sky-tile-title> Tile 1 </sky-tile-title>
2+
<sky-tile-title>
3+
{{ tileParameters.tileName }}
4+
<sky-help-inline
5+
*ngIf="tileParameters.showInlineHelp"
6+
class="sky-control-help"
7+
></sky-help-inline>
8+
</sky-tile-title>
39
<sky-tile-summary> $123.4m </sky-tile-summary>
410
<sky-tile-content>
511
<sky-tile-content-section> Section 1 </sky-tile-content-section>

apps/e2e/tiles-storybook/src/app/tile-dashboard/tile1/tile1.component.spec.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
22
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
33

44
import { TileDashboardModule } from '../tile-dashboard.module';
5+
import { TileParameters } from '../tile-parameters.token';
56

67
import { Tile1Component } from './tile1.component';
78

89
describe('Tile1Component', () => {
910
let component: Tile1Component;
1011
let fixture: ComponentFixture<Tile1Component>;
1112

12-
beforeEach(async () => {
13+
beforeEach(() => {
1314
Object.defineProperty(window, 'matchMedia', {
1415
writable: true,
1516
value: jest.fn().mockImplementation((query) => ({
@@ -24,12 +25,19 @@ describe('Tile1Component', () => {
2425
})),
2526
});
2627

27-
await TestBed.configureTestingModule({
28+
TestBed.configureTestingModule({
2829
imports: [NoopAnimationsModule, TileDashboardModule],
29-
}).compileComponents();
30-
});
30+
providers: [
31+
{
32+
provide: TileParameters,
33+
useValue: {
34+
tileName: 'Test Tile',
35+
showInlineHelp: false,
36+
},
37+
},
38+
],
39+
});
3140

32-
beforeEach(() => {
3341
fixture = TestBed.createComponent(Tile1Component);
3442
component = fixture.componentInstance;
3543
fixture.detectChanges();

apps/e2e/tiles-storybook/src/app/tile-dashboard/tile1/tile1.component.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
import { ChangeDetectionStrategy, Component } from '@angular/core';
1+
import { ChangeDetectionStrategy, Component, Inject } from '@angular/core';
2+
3+
import { TileParameters } from '../tile-parameters.token';
4+
import { TileParametersType } from '../tile-parameters.type';
25

36
@Component({
47
selector: 'app-tile1',
58
templateUrl: './tile1.component.html',
69
changeDetection: ChangeDetectionStrategy.OnPush,
710
})
811
export class Tile1Component {
12+
constructor(
13+
@Inject(TileParameters) public tileParameters: TileParametersType
14+
) {}
15+
916
public tileSettingsClick() {
1017
console.log('Tile settings clicked!');
1118
}

0 commit comments

Comments
 (0)