From 624e3b231179e4bb4b131d4de390c3a5143bd1af Mon Sep 17 00:00:00 2001 From: thediaval Date: Thu, 10 Oct 2019 14:46:35 +0300 Subject: [PATCH] test(core): add new test to table-directive.spec --- .../lib/directives/table-sort.directive.ts | 4 ++- .../lib/tests/table-sort.directive.spec.ts | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/npm/ng-packs/packages/core/src/lib/directives/table-sort.directive.ts b/npm/ng-packs/packages/core/src/lib/directives/table-sort.directive.ts index 707f2ab6ef..77e9bc10e8 100644 --- a/npm/ng-packs/packages/core/src/lib/directives/table-sort.directive.ts +++ b/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); } } } diff --git a/npm/ng-packs/packages/core/src/lib/tests/table-sort.directive.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/table-sort.directive.spec.ts index e69de29bb2..c705735f03 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/table-sort.directive.spec.ts +++ b/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; + let directive: TableSortDirective; + const createDirective = createDirectiveFactory({ + directive: TableSortDirective, + imports: [TableModule], + }); + + beforeEach(() => { + spectator = createDirective(``); + 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]); + }); +});