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

Adopt SkyUIConfigService #31

Merged
merged 6 commits into from
Jan 16, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@angular/common": ">=4.3.6",
"@angular/core": ">=4.3.6",
"@angular/forms": ">=4.3.6",
"@skyux/core": "^3.5.1",
"@skyux/i18n": "^3.5.0",
"@skyux/list-builder-common": "^3.0.0",
"@skyux/forms": "^3.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@
[heading]="asyncHeading | async"
[description]="asyncDescription | async">
</sky-grid-column>
<sky-grid-column
field="column2"
[heading]="asyncHeading | async"
[description]="asyncDescription | async">
</sky-grid-column>
</sky-grid>
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<sky-grid fit="scroll" [data]="data" [columns]="columns">
<sky-grid
fit="scroll"
[columns]="columns"
[data]="data"
[selectedColumnIds]="selectedColumnIds"
[settingsKey]="settingsKey"
>
</sky-grid>
<ng-template #defaultCellTemplate let-row="row" let-value="value">{{value}}</ng-template>
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export class GridEmptyTestComponent {
public template: TemplateRef<any>;

public columns: Array<SkyGridColumnModel>;
public selectedColumnIds: string[];
public settingsKey: string;

public data: any[] = [
{
Expand Down
18 changes: 16 additions & 2 deletions src/app/public/modules/grid/fixtures/grid-fixtures.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@ import {
} from '@angular/common';

import {
SkyUIConfigService,
SkyWindowRefService
} from '@skyux/core';

import {
Observable
} from 'rxjs/Observable';

import {
SkyGridModule
} from '../';
} from '../grid.module';

import {
GridTestComponent
Expand Down Expand Up @@ -47,7 +52,16 @@ import {
SkyGridModule
],
providers: [
SkyWindowRefService
SkyWindowRefService,
{
provide: SkyUIConfigService,
useValue: {
getConfig: () => Observable.of({
selectedColumnIds: []
}),
setConfig: () => Observable.of({})
}
}
],
exports: [
GridTestComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
[messageStream]="gridController"
[multiselectRowId]="multiselectRowId"
[rowHighlightedId]="rowHighlightedId"
[settingsKey]="settingsKey"
[sortField]="sortField"
(sortFieldChange)="onSort($event)"
(columnWidthChange)="onResize($event)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export class GridTestComponent {
public selectedRowsChange: SkyGridSelectedRowsModelChange;
public gridController = new Subject<SkyGridMessage>();
public rowHighlightedId: string;
public settingsKey: string;

public selectedColumnIds: string[] = [
'column1',
Expand Down
166 changes: 142 additions & 24 deletions src/app/public/modules/grid/grid.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,18 @@ import {
tick
} from '@angular/core/testing';

import {
SkyUIConfigService
} from '@skyux/core';

import {
DragulaService
} from 'ng2-dragula/ng2-dragula';

import {
Observable
} from 'rxjs/Observable';

const moment = require('moment');

import {
Expand Down Expand Up @@ -54,7 +62,6 @@ import {
} from './fixtures/mock-dragula.service';

import {
SkyGridModule,
SkyGridComponent,
SkyGridColumnModel
} from './';
Expand Down Expand Up @@ -207,8 +214,7 @@ describe('Grid Component', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
GridFixturesModule,
SkyGridModule
GridFixturesModule
]
});
}));
Expand Down Expand Up @@ -590,7 +596,7 @@ describe('Grid Component', () => {
});
});

describe('Resiazable columns', () => {
describe('Resizeable columns', () => {

it('should not resize if user does not use resize handle', fakeAsync(() => {
// Get initial baseline for comparison.
Expand Down Expand Up @@ -825,8 +831,7 @@ describe('Grid Component', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
GridFixturesModule,
SkyGridModule
GridFixturesModule
]
});
});
Expand Down Expand Up @@ -946,8 +951,7 @@ describe('Grid Component', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
GridFixturesModule,
SkyGridModule
GridFixturesModule
]
});
});
Expand Down Expand Up @@ -1266,8 +1270,7 @@ describe('Grid Component', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
GridFixturesModule,
SkyGridModule
GridFixturesModule
]
});
});
Expand Down Expand Up @@ -1323,8 +1326,7 @@ describe('Grid Component', () => {

TestBed.configureTestingModule({
imports: [
GridFixturesModule,
SkyGridModule
GridFixturesModule
]
});

Expand Down Expand Up @@ -1552,8 +1554,7 @@ describe('Grid Component', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
GridFixturesModule,
SkyGridModule
GridFixturesModule
]
});
}));
Expand Down Expand Up @@ -1639,8 +1640,7 @@ describe('Grid Component', () => {

TestBed.configureTestingModule({
imports: [
GridFixturesModule,
SkyGridModule
GridFixturesModule
]
});

Expand Down Expand Up @@ -1674,8 +1674,7 @@ describe('Grid Component', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
GridFixturesModule,
SkyGridModule
GridFixturesModule
]
}).compileComponents();
}));
Expand All @@ -1685,20 +1684,23 @@ describe('Grid Component', () => {
element = fixture.debugElement as DebugElement;
});

it('should handle async column headings', fakeAsync(() => {
fixture.detectChanges();

expect(getColumnHeader('column1', element).nativeElement.textContent.trim()).toBe('');
function verifyColumnHeaders(id: string) {
expect(getColumnHeader(id, element).nativeElement.textContent.trim()).toBe('');

tick(110); // wait for setTimeout
fixture.detectChanges();
tick();

expect(getColumnHeader('column1', element).nativeElement.textContent.trim()).toBe('Column1');
}));
expect(getColumnHeader(id, element).nativeElement.textContent.trim()).toBe('Column1');
}

it('should handle async column headings', fakeAsync(() => {
fixture.detectChanges();
verifyColumnHeaders('column1');
}));

it('should handle async column descriptions', fakeAsync(() => {
fixture.detectChanges();

let col1 = fixture.componentInstance.grid.columns.find(col => col.id === 'column1');
expect(col1.description).toBe('');
Expand All @@ -1709,5 +1711,121 @@ describe('Grid Component', () => {

expect(col1.description).toBe('Column1 Description');
}));

it('should support the item `field` property if `id` not provided', fakeAsync(() => {
fixture.detectChanges();

verifyColumnHeaders('column2');
}));
});

describe('UI config', () => {
let fixture: ComponentFixture<GridEmptyTestComponent>;
let component: GridEmptyTestComponent;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [
GridFixturesModule
]
});

fixture = TestBed.createComponent(GridEmptyTestComponent);
component = fixture.componentInstance;
});

it('should call the UI config service when selected columns change', () => {
component.columns = [
new SkyGridColumnModel(component.template, {
id: 'column1',
heading: 'Column 1'
}),
new SkyGridColumnModel(component.template, {
id: 'column2',
heading: 'Column 2'
})
];

fixture.detectChanges();

const uiConfigService = TestBed.get(SkyUIConfigService);
Blackbaud-SteveBrush marked this conversation as resolved.
Show resolved Hide resolved
const spy = spyOn(uiConfigService, 'setConfig').and.callThrough();

component.settingsKey = 'foobar';
component.selectedColumnIds = ['column1', 'column2'];
fixture.detectChanges();

expect(spy.calls.count()).toEqual(1);

spy.calls.reset();
component.selectedColumnIds = ['column2', 'column1'];
fixture.detectChanges();

expect(spy.calls.count()).toEqual(1);
});

it('should apply UI Config on init', () => {
Blackbaud-SteveBrush marked this conversation as resolved.
Show resolved Hide resolved
const uiConfigService = TestBed.get(SkyUIConfigService);
const spy = spyOn(uiConfigService, 'getConfig').and.callThrough();

component.settingsKey = 'foobar';
fixture.detectChanges();

expect(spy.calls.count()).toEqual(1);
});

it('should handle errors when setting config', () => {
const spy = spyOn(console, 'warn');

const uiConfigService = TestBed.get(SkyUIConfigService);

spyOn(uiConfigService, 'setConfig').and.callFake(() => {
return Observable.throw(new Error());
});

component.columns = [
new SkyGridColumnModel(component.template, {
id: 'column1',
heading: 'Column 1'
}),
new SkyGridColumnModel(component.template, {
id: 'column2',
heading: 'Column 2'
})
];

fixture.detectChanges();

component.settingsKey = 'foobar';
component.selectedColumnIds = ['column1', 'column2'];
fixture.detectChanges();

expect(spy).toHaveBeenCalledWith('Could not save grid settings.');
});

it('should suppress errors when getting config', () => {
const uiConfigService = TestBed.get(SkyUIConfigService);

spyOn(uiConfigService, 'getConfig').and.callFake(() => {
return Observable.throw(new Error());
});

const spy = spyOn(fixture.componentInstance.grid as any, 'initColumns').and.callThrough();

component.columns = [
new SkyGridColumnModel(component.template, {
id: 'column1',
heading: 'Column 1'
})
];

component.settingsKey = 'foobar';
fixture.detectChanges();

fixture.whenStable().then(() => {
fixture.detectChanges();
expect(spy).toHaveBeenCalled();
});
});
});
});
Loading