Browse Source

test(core): add new test to table-directive.spec

pull/1897/head
thediaval 7 years ago
parent
commit
624e3b2311
  1. 4
      npm/ng-packs/packages/core/src/lib/directives/table-sort.directive.ts
  2. 27
      npm/ng-packs/packages/core/src/lib/tests/table-sort.directive.spec.ts

4
npm/ng-packs/packages/core/src/lib/directives/table-sort.directive.ts

@ -1,6 +1,8 @@
import { Directive, Input, Optional, Self, SimpleChanges, OnChanges } from '@angular/core';
import { Table } from 'primeng/table';
import { SortPipe, SortOrder } from '../pipes/sort.pipe';
import { timer } from 'rxjs';
import clone from 'just-clone';
export interface TableSortOptions {
key: string;
@ -23,7 +25,7 @@ export class TableSortDirective implements OnChanges {
ngOnChanges({ value, abpTableSort }: SimpleChanges) {
if (value || abpTableSort) {
this.abpTableSort = this.abpTableSort || ({} as TableSortOptions);
this.table.value = this.sortPipe.transform(this.value, this.abpTableSort.order, this.abpTableSort.key);
this.table.value = this.sortPipe.transform(clone(this.value), this.abpTableSort.order, this.abpTableSort.key);
}
}
}

27
npm/ng-packs/packages/core/src/lib/tests/table-sort.directive.spec.ts

@ -0,0 +1,27 @@
import { SpectatorDirective, createDirectiveFactory, SpyObject } from '@ngneat/spectator/jest';
import { TableSortDirective } from '../directives/table-sort.directive';
import { TableModule, Table } from 'primeng/table';
describe('TableSortDirective', () => {
let spectator: SpectatorDirective<TableSortDirective>;
let directive: TableSortDirective;
const createDirective = createDirectiveFactory({
directive: TableSortDirective,
imports: [TableModule],
});
beforeEach(() => {
spectator = createDirective(`<p-table [value]="[1,4,2]" [abpTableSort]="{ order: 'asc' }"></p-table>`);
directive = spectator.directive;
});
test('should be created', () => {
expect(directive).toBeTruthy();
});
test('should change table value', () => {
expect(directive.value).toEqual([1, 4, 2]);
const table = spectator.query(Table);
expect(table.value).toEqual([1, 2, 4]);
});
});
Loading…
Cancel
Save