Skip to content

Commit

Permalink
fix(abc:st): fix invalid default value of date type (ng-alain#765)
Browse files Browse the repository at this point in the history
  • Loading branch information
cipchk authored and goten002 committed May 20, 2020
1 parent 30774cd commit 6abc0d9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
8 changes: 3 additions & 5 deletions packages/abc/table/table-data-source.ts
Expand Up @@ -66,7 +66,7 @@ export class STDataSource {
@Host() private ynPipe: YNPipe,
@Host() private numberPipe: DecimalPipe,
private dom: DomSanitizer,
) { }
) {}

process(options: STDataSourceOptions): Observable<STDataSourceResult> {
let data$: Observable<STData[]>;
Expand Down Expand Up @@ -159,9 +159,7 @@ export class STDataSource {
data$ = data$.pipe(map(result => res.process!(result, rawData)));
}

data$ = data$.pipe(
map(result => this.optimizeData({ result, columns, rowClassName: options.rowClassName })),
);
data$ = data$.pipe(map(result => this.optimizeData({ result, columns, rowClassName: options.rowClassName })));

return data$.pipe(
map(result => {
Expand Down Expand Up @@ -208,7 +206,7 @@ export class STDataSource {
text = this.currentyPipe.transform(value);
break;
case 'date':
text = this.datePipe.transform(value, col.dateFormat);
text = value === col.default ? col.default : this.datePipe.transform(value, col.dateFormat);
break;
case 'yn':
text = this.ynPipe.transform(value === col.yn!.truth, col.yn!.yes!, col.yn!.no!, col.yn!.mode!);
Expand Down
22 changes: 16 additions & 6 deletions packages/abc/table/test/table-data-source.spec.ts
Expand Up @@ -721,12 +721,22 @@ describe('abc: table: data-souce', () => {
done();
});
});
it('via date', done => {
options.columns[0].type = 'date';
spyOn(datePipe, 'transform');
srv.process(options).subscribe(() => {
expect(datePipe.transform).toHaveBeenCalled();
done();
describe('via date', () => {
it('should be working', done => {
options.columns[0].type = 'date';
spyOn(datePipe, 'transform');
srv.process(options).subscribe(() => {
expect(datePipe.transform).toHaveBeenCalled();
done();
});
});
it('should be return default value', done => {
options.columns[0] = { index: 'date', type: 'date', default: '-' };
options.data = [{}, { date: new Date() }];
srv.process(options).subscribe(res => {
expect(res.list[0]._values[0].text).toBe('-');
done();
});
});
});
it('via yn', done => {
Expand Down

0 comments on commit 6abc0d9

Please sign in to comment.