Skip to content

Commit

Permalink
fix(module:upload): fix only allow type is picture or picture-card ge…
Browse files Browse the repository at this point in the history
…nerate thumbnail (#2219)

close #2216
  • Loading branch information
cipchk authored and vthinkxie committed Oct 10, 2018
1 parent 8861beb commit 8306111
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
9 changes: 6 additions & 3 deletions components/upload/nz-upload.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,14 @@ export class NzUploadComponent implements OnInit, OnChanges, OnDestroy {
}

private genThumb(file: UploadFile): void {
if (typeof document === 'undefined' ||
if (
(this.nzListType !== 'picture' && this.nzListType !== 'picture-card') ||
typeof document === 'undefined' ||
typeof window === 'undefined' ||
!(window as any).FileReader || !(window as any).File ||
!(window as any).FileReader ||
!(window as any).File ||
!(file.originFileObj instanceof File) ||
file.thumbUrl !== undefined
file.thumbUrl != null
) {
return;
}
Expand Down
19 changes: 19 additions & 0 deletions components/upload/upload.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,25 @@ describe('upload', () => {
expect(dl.queryAll(By.css('.anticon-close')).length).toBe(INITCOUNT - 1);
});
});

describe('[nzListType]', () => {
describe(`should be only allow type is picture or picture-card generate thumbnail`, () => {
it('with text', () => {
instance.nzListType = 'text';
fixture.detectChanges();
pageObject.postSmall();
fixture.detectChanges();
expect(instance.comp.nzFileList[0].thumbUrl).toBeUndefined();
});
it('with picture', () => {
instance.nzListType = 'picture';
fixture.detectChanges();
pageObject.postSmall();
fixture.detectChanges();
expect(instance.comp.nzFileList[0].thumbUrl).not.toBeUndefined();
});
});
});
});

describe('CORS', () => {
Expand Down

0 comments on commit 8306111

Please sign in to comment.