Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(module:descriptions): fix warning without logger #3663

Merged
merged 1 commit into from
Jun 27, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion components/descriptions/demo/border.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Component } from '@angular/core';
<nz-descriptions-item nzTitle="Order Time">
2018-04-24 18:00:00
</nz-descriptions-item>
<nz-descriptions-item nzTitle="Usage Time" [nzSpan]="3">
<nz-descriptions-item nzTitle="Usage Time" [nzSpan]="2">
2018-04-24 18:00:00 To 2019-04-24 18:00:00
</nz-descriptions-item>
<nz-descriptions-item nzTitle="Status" [nzSpan]="3">
Expand Down
4 changes: 2 additions & 2 deletions components/descriptions/nz-descriptions.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
import { fromEvent, merge, Subject } from 'rxjs';
import { auditTime, startWith, takeUntil } from 'rxjs/operators';

import { responsiveMap, Breakpoint, InputBoolean } from 'ng-zorro-antd/core';
import { responsiveMap, warn, Breakpoint, InputBoolean } from 'ng-zorro-antd/core';
import { NzDescriptionsItemRenderProps, NzDescriptionsSize } from './nz-descriptions-definitions';
import { NzDescriptionsItemComponent } from './nz-descriptions-item.component';

Expand Down Expand Up @@ -152,7 +152,7 @@ export class NzDescriptionsComponent implements OnChanges, OnDestroy, AfterConte
// Warn user about that.
if (width >= column) {
if (width > column && isDevMode()) {
console.warn(`"nzColumn" is ${column} but we have row length ${width}`);
warn(`"nzColumn" is ${column} but we have row length ${width}`);
}
flushRow();
}
Expand Down
44 changes: 22 additions & 22 deletions components/descriptions/nz-descriptions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ import { NzDescriptionsModule } from './nz-descriptions.module';
// tslint:disable-next-line no-any
declare const viewport: any;

@Component({
template: `
<nz-descriptions [nzTitle]="title" [nzBordered]="bordered" [nzColumn]="column">
<nz-descriptions-item *ngFor="let col of colspanArray; let i = index" [nzTitle]="'Title' + i" [nzSpan]="col">
</nz-descriptions-item>
</nz-descriptions>
`
})
export class NzTestDescriptionsComponent {
bordered = false;
colspanArray: number[] = [1, 1, 1];
column: number | { [key: string]: number } = 3;
title = 'Title';
}

describe('nz descriptions', () => {
let testComponent: NzTestDescriptionsComponent;
let componentElement: HTMLElement;
Expand Down Expand Up @@ -53,16 +68,16 @@ describe('nz descriptions', () => {
rows = componentElement.querySelectorAll('.ant-descriptions-row');
expect(rows.length).toBe(3);
expect(spyOnWarn).toHaveBeenCalledTimes(2);
expect(spyOnWarn).toHaveBeenCalledWith('"nzColumn" is 3 but we have row length 5');
expect(spyOnWarn).toHaveBeenCalledWith('"nzColumn" is 3 but we have row length 6');
expect(spyOnWarn).toHaveBeenCalledWith('[NG-ZORRO]:', '"nzColumn" is 3 but we have row length 5');
expect(spyOnWarn).toHaveBeenCalledWith('[NG-ZORRO]:', '"nzColumn" is 3 but we have row length 6');

testComponent.column = 5;
testComponent.colspanArray = [1, 2, 3];
fixture.detectChanges();
rows = componentElement.querySelectorAll('.ant-descriptions-row');
expect(rows.length).toBe(1);
expect(spyOnWarn).toHaveBeenCalledTimes(4);
expect(spyOnWarn).toHaveBeenCalledWith('"nzColumn" is 5 but we have row length 6');
expect(spyOnWarn).toHaveBeenCalledWith('[NG-ZORRO]:', '"nzColumn" is 5 but we have row length 6');

testComponent.colspanArray = [1, 2, 2];
fixture.detectChanges();
Expand All @@ -83,17 +98,17 @@ describe('nz descriptions', () => {

viewport.set(1024, 1024);
window.dispatchEvent(new Event('resize'));
fixture.autoDetectChanges();
fixture.detectChanges();
tick(1000);
fixture.autoDetectChanges();
fixture.detectChanges();
rows = componentElement.querySelectorAll('.ant-descriptions-row');
expect(rows.length).toBe(3);

viewport.set(320, 320);
window.dispatchEvent(new Event('resize'));
fixture.autoDetectChanges();
fixture.detectChanges();
tick(1000);
fixture.autoDetectChanges();
fixture.detectChanges();

rows = componentElement.querySelectorAll('.ant-descriptions-row');
expect(rows.length).toBe(7);
Expand All @@ -102,18 +117,3 @@ describe('nz descriptions', () => {
}));
});
});

@Component({
template: `
<nz-descriptions [nzTitle]="title" [nzBordered]="bordered" [nzColumn]="column">
<nz-descriptions-item *ngFor="let col of colspanArray; let i = index" [nzTitle]="'Title' + i" [nzSpan]="col">
</nz-descriptions-item>
</nz-descriptions>
`
})
export class NzTestDescriptionsComponent {
bordered = false;
colspanArray: number[] = [1, 1, 1];
column: number | { [key: string]: number } = 3;
title = 'Title';
}