@zohodesk/dot 1.0.0-temp-230.3 → 1.0.0-temp-230.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -2
- package/es/AttachmentViewer/AttachmentViewer.js +51 -81
- package/es/AttachmentViewer/__tests__/AttachmentViewer.spec.js +104 -100
- package/es/AttachmentViewer/__tests__/__snapshots__/AttachmentViewer.spec.js.snap +778 -1
- package/es/AttachmentViewer/props/defaultProps.js +1 -1
- package/es/AttachmentViewer/props/propTypes.js +3 -2
- package/lib/AttachmentViewer/AttachmentViewer.js +82 -117
- package/lib/AttachmentViewer/__tests__/AttachmentViewer.spec.js +100 -100
- package/lib/AttachmentViewer/__tests__/__snapshots__/AttachmentViewer.spec.js.snap +778 -1
- package/lib/AttachmentViewer/props/defaultProps.js +1 -1
- package/lib/AttachmentViewer/props/propTypes.js +3 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -5,13 +5,16 @@ In this Library, we Provide Some Basic Components to Build Your Application
|
|
|
5
5
|
# 1.9.13
|
|
6
6
|
|
|
7
7
|
- **AttachmentViewer**
|
|
8
|
-
- Added support for
|
|
8
|
+
- Added support for `onSelectedAttachmentChange` and `renderCustomImagePreviewElement`.
|
|
9
9
|
- Increased header bar height.
|
|
10
|
-
- Added support for `
|
|
10
|
+
- Added support for `hasCount`, `renderCustomIcons`, annotation URL re-rendering, and `downloadName`.
|
|
11
11
|
|
|
12
12
|
- **Link**
|
|
13
13
|
- Added `downloadName` prop for custom file download names.
|
|
14
14
|
|
|
15
|
+
- **AttachmentImage**
|
|
16
|
+
- Added `imageRef` prop to pass a ref to the `Image` component.
|
|
17
|
+
|
|
15
18
|
# 1.9.12
|
|
16
19
|
|
|
17
20
|
- DUMMY_ARRAY import path issue fixed in DotProvider DefaultProps
|
|
@@ -14,6 +14,8 @@ import AttachmentImage from "./AttachmentImage";
|
|
|
14
14
|
import Link from "../Link/Link";
|
|
15
15
|
import IconButton from "../IconButton/IconButton";
|
|
16
16
|
import FreezeLayer from "../FreezeLayer/FreezeLayer";
|
|
17
|
+
import { renderNode } from '@zohodesk/utils';
|
|
18
|
+
import { DUMMY_OBJECT } from "../utils/General";
|
|
17
19
|
import { getExtensionFromFileName, getAttachmentIconDetails } from "./Attachment";
|
|
18
20
|
import { shallowDiff } from "../utils/General";
|
|
19
21
|
import { checkFileSourcesValidation, FILE_EXTENSIONS } from "./utils";
|
|
@@ -47,35 +49,10 @@ export default class AttachmentViewer extends Component {
|
|
|
47
49
|
this.zoomMaintain = this.zoomMaintain.bind(this);
|
|
48
50
|
this.handleMenuValidation = this.handleMenuValidation.bind(this);
|
|
49
51
|
this.getPreviewIconData = this.getPreviewIconData.bind(this);
|
|
50
|
-
this.renderIframe = this.renderIframe.bind(this);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
// }
|
|
55
|
-
// const { data } = this.state;
|
|
56
|
-
// const targetIdx = typeof idOrIndex === 'number'
|
|
57
|
-
// ? idOrIndex
|
|
58
|
-
// : data.findIndex((item) => item && item.id === idOrIndex);
|
|
59
|
-
// if (targetIdx < 0 || targetIdx >= data.length) {
|
|
60
|
-
// return false;
|
|
61
|
-
// }
|
|
62
|
-
// this.setState((prevState) => {
|
|
63
|
-
// const nextData = prevState.data.slice();
|
|
64
|
-
// nextData[targetIdx] = { ...nextData[targetIdx], ...changes };
|
|
65
|
-
// let nextDataList = prevState.dataList;
|
|
66
|
-
// if (targetIdx < prevState.dataList.length) {
|
|
67
|
-
// nextDataList = prevState.dataList.slice();
|
|
68
|
-
// nextDataList[targetIdx] = { ...nextDataList[targetIdx], ...changes };
|
|
69
|
-
// }
|
|
70
|
-
// return { data: nextData, dataList: nextDataList };
|
|
71
|
-
// }, () => {
|
|
72
|
-
// if (this.state.selectedIndex === targetIdx) {
|
|
73
|
-
// this.handleMenuValidation();
|
|
74
|
-
// }
|
|
75
|
-
// });
|
|
76
|
-
// return true;
|
|
77
|
-
// }
|
|
78
|
-
|
|
52
|
+
this.renderIframe = this.renderIframe.bind(this);
|
|
53
|
+
this.getRenderImageFrameCustomClass = this.getRenderImageFrameCustomClass.bind(this);
|
|
54
|
+
this.renderImageFrame = this.renderImageFrame.bind(this);
|
|
55
|
+
}
|
|
79
56
|
|
|
80
57
|
isImageFileType(fileName) {
|
|
81
58
|
const extension = (getExtensionFromFileName(fileName) || '').toLowerCase();
|
|
@@ -101,10 +78,12 @@ export default class AttachmentViewer extends Component {
|
|
|
101
78
|
|
|
102
79
|
componentDidUpdate(prevProps, prevState) {
|
|
103
80
|
let {
|
|
104
|
-
previewObj
|
|
81
|
+
previewObj,
|
|
82
|
+
onSelectedAttachmentChange
|
|
105
83
|
} = this.props;
|
|
106
84
|
const {
|
|
107
|
-
selectedIndex
|
|
85
|
+
selectedIndex,
|
|
86
|
+
data
|
|
108
87
|
} = this.state;
|
|
109
88
|
let indexChanged = previewObj.selectedIndex != prevProps.previewObj.selectedIndex;
|
|
110
89
|
const attachmentPreviewUrlChanged = previewObj.previewData.some((value, index) => value?.viewUrl !== prevState.data[index]?.viewUrl); // Triggers an update if any previewed attachment is edited by the Attachment Annotator.
|
|
@@ -129,6 +108,10 @@ export default class AttachmentViewer extends Component {
|
|
|
129
108
|
}
|
|
130
109
|
|
|
131
110
|
if (prevState.selectedIndex != selectedIndex || attachmentPreviewUrlChanged) {
|
|
111
|
+
onSelectedAttachmentChange && onSelectedAttachmentChange({
|
|
112
|
+
data: data[selectedIndex] || DUMMY_OBJECT,
|
|
113
|
+
selectedIndex
|
|
114
|
+
});
|
|
132
115
|
this.handleMenuValidation();
|
|
133
116
|
}
|
|
134
117
|
}
|
|
@@ -141,7 +124,7 @@ export default class AttachmentViewer extends Component {
|
|
|
141
124
|
const {
|
|
142
125
|
allowedPreviewExtensionsData
|
|
143
126
|
} = this.props;
|
|
144
|
-
const selectedAttachment = data[selectedIndex] ||
|
|
127
|
+
const selectedAttachment = data[selectedIndex] || DUMMY_OBJECT;
|
|
145
128
|
const selectedAttachmentViewUrl = selectedAttachment.viewUrl; // const selectedAttachmentDownloadUrl = selectedAttachment.downloadUrl;
|
|
146
129
|
|
|
147
130
|
const selectedAttachmentName = selectedAttachment.name;
|
|
@@ -336,73 +319,71 @@ export default class AttachmentViewer extends Component {
|
|
|
336
319
|
}, this.props.customProps.iframeProps));
|
|
337
320
|
}
|
|
338
321
|
|
|
339
|
-
getRenderImageFrameCustomClass(
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
retainZoom,
|
|
322
|
+
getRenderImageFrameCustomClass() {
|
|
323
|
+
const {
|
|
324
|
+
selectedIndex,
|
|
343
325
|
isZoomed,
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
} =
|
|
326
|
+
canZoom,
|
|
327
|
+
data
|
|
328
|
+
} = this.state;
|
|
329
|
+
const {
|
|
330
|
+
maintainZoom
|
|
331
|
+
} = this.props;
|
|
332
|
+
const selectedData = data[selectedIndex] || DUMMY_OBJECT;
|
|
333
|
+
const {
|
|
334
|
+
customClass = DUMMY_OBJECT
|
|
335
|
+
} = selectedData;
|
|
336
|
+
const {
|
|
337
|
+
customImageClass = '',
|
|
338
|
+
customChildrenClass = ''
|
|
339
|
+
} = customClass;
|
|
340
|
+
const retainZoom = canZoom && maintainZoom;
|
|
347
341
|
return {
|
|
348
342
|
customImageClass: `${style.img} ${style.altText} ${canZoom || retainZoom ? isZoomed ? `${style.zoomedImg} ${style.zoomOutCursor}` : `${style.normalImg} ${style.zoomInCursor}` : ''} ${customImageClass}`,
|
|
349
343
|
customChildrenClass
|
|
350
344
|
};
|
|
351
345
|
}
|
|
352
346
|
|
|
353
|
-
renderImageFrame(
|
|
347
|
+
renderImageFrame() {
|
|
354
348
|
const {
|
|
355
349
|
selectedIndex,
|
|
356
350
|
isZoomed,
|
|
357
|
-
canZoom,
|
|
358
351
|
isPreviewAttachmentValid
|
|
359
352
|
} = this.state;
|
|
360
353
|
const {
|
|
361
|
-
maintainZoom,
|
|
362
354
|
renderCustomImagePreviewElement
|
|
363
355
|
} = this.props;
|
|
356
|
+
const data = this.state.data[selectedIndex] || DUMMY_OBJECT;
|
|
364
357
|
const {
|
|
365
358
|
viewUrl,
|
|
366
359
|
name,
|
|
367
360
|
children,
|
|
368
361
|
dataId = 'attachViewer',
|
|
369
|
-
|
|
370
|
-
customProps = {},
|
|
362
|
+
customProps = DUMMY_OBJECT,
|
|
371
363
|
imageRef
|
|
372
364
|
} = data;
|
|
373
365
|
const {
|
|
374
|
-
imageProps =
|
|
366
|
+
imageProps = DUMMY_OBJECT
|
|
375
367
|
} = customProps;
|
|
376
|
-
const {
|
|
377
|
-
customImageClass = '',
|
|
378
|
-
customChildrenClass = ''
|
|
379
|
-
} = customClass;
|
|
380
368
|
const resolvedImageRef = imageRef;
|
|
381
|
-
const
|
|
382
|
-
const
|
|
383
|
-
const handleZoomIn = isPreviewAttachmentValid && !isZoomed ? e => this.zoomIn(e, i, true) : undefined;
|
|
369
|
+
const handleZoomOut = isPreviewAttachmentValid && isZoomed ? this.zoomOut.bind(this, selectedIndex) : undefined;
|
|
370
|
+
const handleZoomIn = isPreviewAttachmentValid && !isZoomed ? e => this.zoomIn(e, selectedIndex, true) : undefined;
|
|
384
371
|
const handleImageClick = isPreviewAttachmentValid ? isZoomed ? handleZoomOut : handleZoomIn : undefined;
|
|
385
|
-
const imageFrameCustomClass = this.getRenderImageFrameCustomClass(
|
|
386
|
-
|
|
387
|
-
retainZoom,
|
|
388
|
-
isZoomed,
|
|
389
|
-
customImageClass,
|
|
390
|
-
customChildrenClass
|
|
391
|
-
});
|
|
392
|
-
const img = /*#__PURE__*/React.createElement(AttachmentImage, _extends({}, imageProps, {
|
|
372
|
+
const imageFrameCustomClass = this.getRenderImageFrameCustomClass();
|
|
373
|
+
const img = /*#__PURE__*/React.createElement(AttachmentImage, _extends({
|
|
393
374
|
customClass: imageFrameCustomClass,
|
|
394
375
|
src: viewUrl,
|
|
395
376
|
onClick: handleImageClick,
|
|
396
377
|
alt: name,
|
|
397
378
|
dataId: dataId,
|
|
398
|
-
id: `img${
|
|
379
|
+
id: `img${selectedIndex}`,
|
|
399
380
|
isCover: false,
|
|
400
381
|
imageRef: resolvedImageRef
|
|
401
|
-
}), children);
|
|
382
|
+
}, imageProps), children);
|
|
402
383
|
return typeof renderCustomImagePreviewElement === 'function' ? renderCustomImagePreviewElement({
|
|
403
384
|
defaultView: img,
|
|
404
385
|
data,
|
|
405
|
-
index:
|
|
386
|
+
index: selectedIndex
|
|
406
387
|
}) : img;
|
|
407
388
|
}
|
|
408
389
|
|
|
@@ -411,13 +392,9 @@ export default class AttachmentViewer extends Component {
|
|
|
411
392
|
|
|
412
393
|
const {
|
|
413
394
|
dataList,
|
|
414
|
-
selectedIndex
|
|
415
|
-
isZoomed,
|
|
416
|
-
canZoom,
|
|
417
|
-
isPreviewAttachmentValid
|
|
395
|
+
selectedIndex
|
|
418
396
|
} = this.state;
|
|
419
397
|
const {
|
|
420
|
-
maintainZoom,
|
|
421
398
|
dataId,
|
|
422
399
|
i18nKeys,
|
|
423
400
|
renderUnSupportedElement
|
|
@@ -456,21 +433,14 @@ export default class AttachmentViewer extends Component {
|
|
|
456
433
|
name,
|
|
457
434
|
children,
|
|
458
435
|
dataId = 'attachViewer',
|
|
459
|
-
customClass = {},
|
|
460
436
|
customProps = {},
|
|
461
437
|
previewurl,
|
|
462
438
|
type
|
|
463
439
|
} = data;
|
|
464
440
|
const {
|
|
465
441
|
audioProps = {},
|
|
466
|
-
imageProps = {},
|
|
467
442
|
videoProps = {}
|
|
468
443
|
} = customProps;
|
|
469
|
-
const {
|
|
470
|
-
customImageClass = '',
|
|
471
|
-
customChildrenClass = ''
|
|
472
|
-
} = customClass;
|
|
473
|
-
const retainZoom = canZoom && selectedIndex == i && maintainZoom;
|
|
474
444
|
const extension = getExtensionFromFileName(name);
|
|
475
445
|
const {
|
|
476
446
|
previewUnsupportedText = "Preview not available for the selected file type.",
|
|
@@ -502,7 +472,7 @@ export default class AttachmentViewer extends Component {
|
|
|
502
472
|
}, videoProps), /*#__PURE__*/React.createElement("source", {
|
|
503
473
|
src: viewUrl,
|
|
504
474
|
type: `video/${extension}`
|
|
505
|
-
})) : _this.isImageFileType(name) || children ? _this.renderImageFrame(
|
|
475
|
+
})) : _this.isImageFileType(name) || children ? _this.renderImageFrame() : type === "document" && previewurl != null ? _this.renderIframe(previewurl) : typeof renderUnSupportedElement === 'function' ? renderUnSupportedElement(data) : /*#__PURE__*/React.createElement("div", {
|
|
506
476
|
className: style.previewNone
|
|
507
477
|
}, /*#__PURE__*/React.createElement("div", {
|
|
508
478
|
className: style.fileTypeImg
|
|
@@ -538,7 +508,7 @@ export default class AttachmentViewer extends Component {
|
|
|
538
508
|
isActive,
|
|
539
509
|
dataId,
|
|
540
510
|
customProps,
|
|
541
|
-
|
|
511
|
+
hasCount,
|
|
542
512
|
renderCustomIcons
|
|
543
513
|
} = this.props;
|
|
544
514
|
const {
|
|
@@ -567,10 +537,10 @@ export default class AttachmentViewer extends Component {
|
|
|
567
537
|
}, /*#__PURE__*/React.createElement(ResponsiveReceiver, {
|
|
568
538
|
responsiveId: responsiveId,
|
|
569
539
|
query: this.responsiveFunc
|
|
570
|
-
},
|
|
540
|
+
}, _ref3 => {
|
|
571
541
|
let {
|
|
572
542
|
uptoTablet
|
|
573
|
-
} =
|
|
543
|
+
} = _ref3;
|
|
574
544
|
return /*#__PURE__*/React.createElement(Container, {
|
|
575
545
|
scroll: "none",
|
|
576
546
|
"data-scroll-palette": "dark"
|
|
@@ -585,7 +555,7 @@ export default class AttachmentViewer extends Component {
|
|
|
585
555
|
"data-title": selectedAttachment.name,
|
|
586
556
|
dataId: "attachName",
|
|
587
557
|
id: ariaId
|
|
588
|
-
}, selectedAttachment.name),
|
|
558
|
+
}, selectedAttachment.name), hasCount && /*#__PURE__*/React.createElement(Box, {
|
|
589
559
|
flexible: true,
|
|
590
560
|
className: style.count,
|
|
591
561
|
dataId: "attachCountContainer"
|
|
@@ -597,7 +567,7 @@ export default class AttachmentViewer extends Component {
|
|
|
597
567
|
align: uptoTablet ? 'bottom' : 'center',
|
|
598
568
|
wrap: "wrap",
|
|
599
569
|
isCover: false
|
|
600
|
-
},
|
|
570
|
+
}, renderNode(renderCustomIcons, {
|
|
601
571
|
selectedAttachment,
|
|
602
572
|
selectedIndex,
|
|
603
573
|
totalLen
|
|
@@ -8,62 +8,63 @@ beforeEach(() => {
|
|
|
8
8
|
afterEach(() => {
|
|
9
9
|
cleanup();
|
|
10
10
|
});
|
|
11
|
+
const mockData = [{
|
|
12
|
+
id: '1',
|
|
13
|
+
name: 'slack0.jpg',
|
|
14
|
+
size: '100412',
|
|
15
|
+
href: 'https://2.bp.blogspot.com/_H-PCzW2K720/SlXXLLMOzsI/AAAAAAAAAFE/efv7GBth9cQ/s280/Elva+Hill+04.JPG',
|
|
16
|
+
viewUrl: 'https://2.bp.blogspot.com/_H-PCzW2K720/SlXXLLMOzsI/AAAAAAAAAFE/efv7GBth9cQ/s280/Elva+Hill+04.JPG',
|
|
17
|
+
downloadUrl: 'https://2.bp.blogspot.com/_H-PCzW2K720/SlXXLLMOzsI/AAAAAAAAAFE/efv7GBth9cQ/s280/Elva+Hill+04.JPG'
|
|
18
|
+
}, {
|
|
19
|
+
id: '2',
|
|
20
|
+
name: 'slack1.jpg',
|
|
21
|
+
size: '100412',
|
|
22
|
+
href: 'https://p.bigstockphoto.com/GeFvQkBbSLaMdpKXF1Zv_bigstock-Aerial-View-Of-Blue-Lakes-And--227291596.jpg',
|
|
23
|
+
viewUrl: 'https://p.bigstockphoto.com/GeFvQkBbSLaMdpKXF1Zv_bigstock-Aerial-View-Of-Blue-Lakes-And--227291596.jpg',
|
|
24
|
+
downloadUrl: 'https://p.bigstockphoto.com/GeFvQkBbSLaMdpKXF1Zv_bigstock-Aerial-View-Of-Blue-Lakes-And--227291596.jpg'
|
|
25
|
+
}, {
|
|
26
|
+
id: '3',
|
|
27
|
+
name: 'slack2.jpg',
|
|
28
|
+
size: '100412',
|
|
29
|
+
href: 'https://wallpapercave.com/wp/wp3913900.jpg',
|
|
30
|
+
viewUrl: 'https://wallpapercave.com/wp/wp3913900.jpg',
|
|
31
|
+
downloadUrl: 'https://wallpapercave.com/wp/wp3913900.jpg'
|
|
32
|
+
}, {
|
|
33
|
+
id: '4',
|
|
34
|
+
name: 'slack3.jpg',
|
|
35
|
+
size: '100412',
|
|
36
|
+
href: 'https://upload.wikimedia.org/wikipedia/commons/thumb/0/09/Giraffe_2019-07-28.jpg/682px-Giraffe_2019-07-28.jpg',
|
|
37
|
+
viewUrl: 'https://upload.wikimedia.org/wikipedia/commons/thumb/0/09/Giraffe_2019-07-28.jpg/682px-Giraffe_2019-07-28.jpg',
|
|
38
|
+
downloadUrl: 'https://upload.wikimedia.org/wikipedia/commons/thumb/0/09/Giraffe_2019-07-28.jpg/682px-Giraffe_2019-07-28.jpg'
|
|
39
|
+
}, {
|
|
40
|
+
id: '5',
|
|
41
|
+
name: 'slack4.jpg',
|
|
42
|
+
size: '100412',
|
|
43
|
+
href: 'https://wallpapercave.com/wp/wp3913900.jpg',
|
|
44
|
+
viewUrl: 'https://wallpapercave.com/wp/wp3913900.jpg',
|
|
45
|
+
downloadUrl: 'https://wallpapercave.com/wp/wp3913900.jpg'
|
|
46
|
+
}, {
|
|
47
|
+
id: '6',
|
|
48
|
+
name: 'slack5.jpg',
|
|
49
|
+
size: '100412',
|
|
50
|
+
href: 'https://upload.wikimedia.org/wikipedia/commons/thumb/0/09/Giraffe_2019-07-28.jpg/682px-Giraffe_2019-07-28.jpg',
|
|
51
|
+
viewUrl: 'https://upload.wikimedia.org/wikipedia/commons/thumb/0/09/Giraffe_2019-07-28.jpg/682px-Giraffe_2019-07-28.jpg',
|
|
52
|
+
downloadUrl: 'https://upload.wikimedia.org/wikipedia/commons/thumb/0/09/Giraffe_2019-07-28.jpg/682px-Giraffe_2019-07-28.jpg'
|
|
53
|
+
}, {
|
|
54
|
+
id: '6',
|
|
55
|
+
name: 'slack5.mp3',
|
|
56
|
+
size: '100412',
|
|
57
|
+
href: 'https://www.w3schools.com/html/horse.mp3',
|
|
58
|
+
viewUrl: 'https://www.w3schools.com/html/horse.mp3',
|
|
59
|
+
downloadUrl: 'https://www.w3schools.com/html/horse.mp3'
|
|
60
|
+
}];
|
|
11
61
|
describe('AttachmentViewer', () => {
|
|
12
62
|
test('rendering the defult props', () => {
|
|
13
63
|
const {
|
|
14
64
|
asFragment
|
|
15
65
|
} = render( /*#__PURE__*/React.createElement(AttachmentViewer, {
|
|
16
66
|
previewObj: {
|
|
17
|
-
previewData:
|
|
18
|
-
id: '1',
|
|
19
|
-
name: 'slack0.jpg',
|
|
20
|
-
size: '100412',
|
|
21
|
-
href: 'https://2.bp.blogspot.com/_H-PCzW2K720/SlXXLLMOzsI/AAAAAAAAAFE/efv7GBth9cQ/s280/Elva+Hill+04.JPG',
|
|
22
|
-
viewUrl: 'https://2.bp.blogspot.com/_H-PCzW2K720/SlXXLLMOzsI/AAAAAAAAAFE/efv7GBth9cQ/s280/Elva+Hill+04.JPG',
|
|
23
|
-
downloadUrl: 'https://2.bp.blogspot.com/_H-PCzW2K720/SlXXLLMOzsI/AAAAAAAAAFE/efv7GBth9cQ/s280/Elva+Hill+04.JPG'
|
|
24
|
-
}, {
|
|
25
|
-
id: '2',
|
|
26
|
-
name: 'slack1.jpg',
|
|
27
|
-
size: '100412',
|
|
28
|
-
href: 'https://p.bigstockphoto.com/GeFvQkBbSLaMdpKXF1Zv_bigstock-Aerial-View-Of-Blue-Lakes-And--227291596.jpg',
|
|
29
|
-
viewUrl: 'https://p.bigstockphoto.com/GeFvQkBbSLaMdpKXF1Zv_bigstock-Aerial-View-Of-Blue-Lakes-And--227291596.jpg',
|
|
30
|
-
downloadUrl: 'https://p.bigstockphoto.com/GeFvQkBbSLaMdpKXF1Zv_bigstock-Aerial-View-Of-Blue-Lakes-And--227291596.jpg'
|
|
31
|
-
}, {
|
|
32
|
-
id: '3',
|
|
33
|
-
name: 'slack2.jpg',
|
|
34
|
-
size: '100412',
|
|
35
|
-
href: 'https://wallpapercave.com/wp/wp3913900.jpg',
|
|
36
|
-
viewUrl: 'https://wallpapercave.com/wp/wp3913900.jpg',
|
|
37
|
-
downloadUrl: 'https://wallpapercave.com/wp/wp3913900.jpg'
|
|
38
|
-
}, {
|
|
39
|
-
id: '4',
|
|
40
|
-
name: 'slack3.jpg',
|
|
41
|
-
size: '100412',
|
|
42
|
-
href: 'https://upload.wikimedia.org/wikipedia/commons/thumb/0/09/Giraffe_2019-07-28.jpg/682px-Giraffe_2019-07-28.jpg',
|
|
43
|
-
viewUrl: 'https://upload.wikimedia.org/wikipedia/commons/thumb/0/09/Giraffe_2019-07-28.jpg/682px-Giraffe_2019-07-28.jpg',
|
|
44
|
-
downloadUrl: 'https://upload.wikimedia.org/wikipedia/commons/thumb/0/09/Giraffe_2019-07-28.jpg/682px-Giraffe_2019-07-28.jpg'
|
|
45
|
-
}, {
|
|
46
|
-
id: '5',
|
|
47
|
-
name: 'slack4.jpg',
|
|
48
|
-
size: '100412',
|
|
49
|
-
href: 'https://wallpapercave.com/wp/wp3913900.jpg',
|
|
50
|
-
viewUrl: 'https://wallpapercave.com/wp/wp3913900.jpg',
|
|
51
|
-
downloadUrl: 'https://wallpapercave.com/wp/wp3913900.jpg'
|
|
52
|
-
}, {
|
|
53
|
-
id: '6',
|
|
54
|
-
name: 'slack5.jpg',
|
|
55
|
-
size: '100412',
|
|
56
|
-
href: 'https://upload.wikimedia.org/wikipedia/commons/thumb/0/09/Giraffe_2019-07-28.jpg/682px-Giraffe_2019-07-28.jpg',
|
|
57
|
-
viewUrl: 'https://upload.wikimedia.org/wikipedia/commons/thumb/0/09/Giraffe_2019-07-28.jpg/682px-Giraffe_2019-07-28.jpg',
|
|
58
|
-
downloadUrl: 'https://upload.wikimedia.org/wikipedia/commons/thumb/0/09/Giraffe_2019-07-28.jpg/682px-Giraffe_2019-07-28.jpg'
|
|
59
|
-
}, {
|
|
60
|
-
id: '6',
|
|
61
|
-
name: 'slack5.mp3',
|
|
62
|
-
size: '100412',
|
|
63
|
-
href: 'https://www.w3schools.com/html/horse.mp3',
|
|
64
|
-
viewUrl: 'https://www.w3schools.com/html/horse.mp3',
|
|
65
|
-
downloadUrl: 'https://www.w3schools.com/html/horse.mp3'
|
|
66
|
-
}],
|
|
67
|
+
previewData: mockData,
|
|
67
68
|
selectedIndex: 0
|
|
68
69
|
}
|
|
69
70
|
}));
|
|
@@ -75,59 +76,62 @@ describe('AttachmentViewer', () => {
|
|
|
75
76
|
} = render( /*#__PURE__*/React.createElement(AttachmentViewer, {
|
|
76
77
|
isActive: true,
|
|
77
78
|
previewObj: {
|
|
78
|
-
previewData:
|
|
79
|
-
id: '1',
|
|
80
|
-
name: 'slack0.jpg',
|
|
81
|
-
size: '100412',
|
|
82
|
-
href: 'https://2.bp.blogspot.com/_H-PCzW2K720/SlXXLLMOzsI/AAAAAAAAAFE/efv7GBth9cQ/s280/Elva+Hill+04.JPG',
|
|
83
|
-
viewUrl: 'https://2.bp.blogspot.com/_H-PCzW2K720/SlXXLLMOzsI/AAAAAAAAAFE/efv7GBth9cQ/s280/Elva+Hill+04.JPG',
|
|
84
|
-
downloadUrl: 'https://2.bp.blogspot.com/_H-PCzW2K720/SlXXLLMOzsI/AAAAAAAAAFE/efv7GBth9cQ/s280/Elva+Hill+04.JPG'
|
|
85
|
-
}, {
|
|
86
|
-
id: '2',
|
|
87
|
-
name: 'slack1.jpg',
|
|
88
|
-
size: '100412',
|
|
89
|
-
href: 'https://p.bigstockphoto.com/GeFvQkBbSLaMdpKXF1Zv_bigstock-Aerial-View-Of-Blue-Lakes-And--227291596.jpg',
|
|
90
|
-
viewUrl: 'https://p.bigstockphoto.com/GeFvQkBbSLaMdpKXF1Zv_bigstock-Aerial-View-Of-Blue-Lakes-And--227291596.jpg',
|
|
91
|
-
downloadUrl: 'https://p.bigstockphoto.com/GeFvQkBbSLaMdpKXF1Zv_bigstock-Aerial-View-Of-Blue-Lakes-And--227291596.jpg'
|
|
92
|
-
}, {
|
|
93
|
-
id: '3',
|
|
94
|
-
name: 'slack2.jpg',
|
|
95
|
-
size: '100412',
|
|
96
|
-
href: 'https://wallpapercave.com/wp/wp3913900.jpg',
|
|
97
|
-
viewUrl: 'https://wallpapercave.com/wp/wp3913900.jpg',
|
|
98
|
-
downloadUrl: 'https://wallpapercave.com/wp/wp3913900.jpg'
|
|
99
|
-
}, {
|
|
100
|
-
id: '4',
|
|
101
|
-
name: 'slack3.jpg',
|
|
102
|
-
size: '100412',
|
|
103
|
-
href: 'https://upload.wikimedia.org/wikipedia/commons/thumb/0/09/Giraffe_2019-07-28.jpg/682px-Giraffe_2019-07-28.jpg',
|
|
104
|
-
viewUrl: 'https://upload.wikimedia.org/wikipedia/commons/thumb/0/09/Giraffe_2019-07-28.jpg/682px-Giraffe_2019-07-28.jpg',
|
|
105
|
-
downloadUrl: 'https://upload.wikimedia.org/wikipedia/commons/thumb/0/09/Giraffe_2019-07-28.jpg/682px-Giraffe_2019-07-28.jpg'
|
|
106
|
-
}, {
|
|
107
|
-
id: '5',
|
|
108
|
-
name: 'slack4.jpg',
|
|
109
|
-
size: '100412',
|
|
110
|
-
href: 'https://wallpapercave.com/wp/wp3913900.jpg',
|
|
111
|
-
viewUrl: 'https://wallpapercave.com/wp/wp3913900.jpg',
|
|
112
|
-
downloadUrl: 'https://wallpapercave.com/wp/wp3913900.jpg'
|
|
113
|
-
}, {
|
|
114
|
-
id: '6',
|
|
115
|
-
name: 'slack5.jpg',
|
|
116
|
-
size: '100412',
|
|
117
|
-
href: 'https://upload.wikimedia.org/wikipedia/commons/thumb/0/09/Giraffe_2019-07-28.jpg/682px-Giraffe_2019-07-28.jpg',
|
|
118
|
-
viewUrl: 'https://upload.wikimedia.org/wikipedia/commons/thumb/0/09/Giraffe_2019-07-28.jpg/682px-Giraffe_2019-07-28.jpg',
|
|
119
|
-
downloadUrl: 'https://upload.wikimedia.org/wikipedia/commons/thumb/0/09/Giraffe_2019-07-28.jpg/682px-Giraffe_2019-07-28.jpg'
|
|
120
|
-
}, {
|
|
121
|
-
id: '6',
|
|
122
|
-
name: 'slack5.mp3',
|
|
123
|
-
size: '100412',
|
|
124
|
-
href: 'https://www.w3schools.com/html/horse.mp3',
|
|
125
|
-
viewUrl: 'https://www.w3schools.com/html/horse.mp3',
|
|
126
|
-
downloadUrl: 'https://www.w3schools.com/html/horse.mp3'
|
|
127
|
-
}],
|
|
79
|
+
previewData: mockData,
|
|
128
80
|
selectedIndex: 0
|
|
129
81
|
}
|
|
130
82
|
}));
|
|
131
83
|
expect(asFragment()).toMatchSnapshot();
|
|
132
84
|
});
|
|
85
|
+
test('rendering with renderCustomIcons', () => {
|
|
86
|
+
const {
|
|
87
|
+
asFragment
|
|
88
|
+
} = render( /*#__PURE__*/React.createElement(AttachmentViewer, {
|
|
89
|
+
isActive: true,
|
|
90
|
+
previewObj: {
|
|
91
|
+
previewData: mockData,
|
|
92
|
+
selectedIndex: 0
|
|
93
|
+
},
|
|
94
|
+
renderCustomIcons: props => {
|
|
95
|
+
const {
|
|
96
|
+
selectedAttachment,
|
|
97
|
+
selectedIndex,
|
|
98
|
+
totalLen
|
|
99
|
+
} = props;
|
|
100
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
101
|
+
"data-id": "customIcons"
|
|
102
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
103
|
+
"data-id": "customIcons_name"
|
|
104
|
+
}, selectedAttachment.name), /*#__PURE__*/React.createElement("span", {
|
|
105
|
+
"data-id": "customIcons_index"
|
|
106
|
+
}, selectedIndex + 1, "/", totalLen));
|
|
107
|
+
}
|
|
108
|
+
}));
|
|
109
|
+
expect(asFragment()).toMatchSnapshot();
|
|
110
|
+
});
|
|
111
|
+
test('rendering with renderCustomImagePreviewElement', () => {
|
|
112
|
+
const {
|
|
113
|
+
asFragment
|
|
114
|
+
} = render( /*#__PURE__*/React.createElement(AttachmentViewer, {
|
|
115
|
+
isActive: true,
|
|
116
|
+
previewObj: {
|
|
117
|
+
previewData: mockData,
|
|
118
|
+
selectedIndex: 0
|
|
119
|
+
},
|
|
120
|
+
renderCustomImagePreviewElement: props => {
|
|
121
|
+
const {
|
|
122
|
+
defaultView,
|
|
123
|
+
data,
|
|
124
|
+
index: selectedIndex
|
|
125
|
+
} = props;
|
|
126
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
127
|
+
"data-id": "customImagePreview"
|
|
128
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
129
|
+
"data-id": "customImagePreview_name"
|
|
130
|
+
}, data.name), /*#__PURE__*/React.createElement("span", {
|
|
131
|
+
"data-id": "customImagePreview_index"
|
|
132
|
+
}, selectedIndex + 1, "/", data.length));
|
|
133
|
+
}
|
|
134
|
+
}));
|
|
135
|
+
expect(asFragment()).toMatchSnapshot();
|
|
136
|
+
});
|
|
133
137
|
});
|