@zohodesk/dot
Version:
In this Library, we Provide Some Basic Components to Build Your Application
137 lines • 4.96 kB
JavaScript
import React from 'react';
import { render, cleanup } from '@testing-library/react';
import { setGlobalId } from '@zohodesk/components/es/Provider/IdProvider';
import AttachmentViewer from "../AttachmentViewer";
beforeEach(() => {
setGlobalId(0);
});
afterEach(() => {
cleanup();
});
const mockData = [{
id: '1',
name: 'slack0.jpg',
size: '100412',
href: 'https://2.bp.blogspot.com/_H-PCzW2K720/SlXXLLMOzsI/AAAAAAAAAFE/efv7GBth9cQ/s280/Elva+Hill+04.JPG',
viewUrl: 'https://2.bp.blogspot.com/_H-PCzW2K720/SlXXLLMOzsI/AAAAAAAAAFE/efv7GBth9cQ/s280/Elva+Hill+04.JPG',
downloadUrl: 'https://2.bp.blogspot.com/_H-PCzW2K720/SlXXLLMOzsI/AAAAAAAAAFE/efv7GBth9cQ/s280/Elva+Hill+04.JPG'
}, {
id: '2',
name: 'slack1.jpg',
size: '100412',
href: 'https://p.bigstockphoto.com/GeFvQkBbSLaMdpKXF1Zv_bigstock-Aerial-View-Of-Blue-Lakes-And--227291596.jpg',
viewUrl: 'https://p.bigstockphoto.com/GeFvQkBbSLaMdpKXF1Zv_bigstock-Aerial-View-Of-Blue-Lakes-And--227291596.jpg',
downloadUrl: 'https://p.bigstockphoto.com/GeFvQkBbSLaMdpKXF1Zv_bigstock-Aerial-View-Of-Blue-Lakes-And--227291596.jpg'
}, {
id: '3',
name: 'slack2.jpg',
size: '100412',
href: 'https://wallpapercave.com/wp/wp3913900.jpg',
viewUrl: 'https://wallpapercave.com/wp/wp3913900.jpg',
downloadUrl: 'https://wallpapercave.com/wp/wp3913900.jpg'
}, {
id: '4',
name: 'slack3.jpg',
size: '100412',
href: 'https://upload.wikimedia.org/wikipedia/commons/thumb/0/09/Giraffe_2019-07-28.jpg/682px-Giraffe_2019-07-28.jpg',
viewUrl: 'https://upload.wikimedia.org/wikipedia/commons/thumb/0/09/Giraffe_2019-07-28.jpg/682px-Giraffe_2019-07-28.jpg',
downloadUrl: 'https://upload.wikimedia.org/wikipedia/commons/thumb/0/09/Giraffe_2019-07-28.jpg/682px-Giraffe_2019-07-28.jpg'
}, {
id: '5',
name: 'slack4.jpg',
size: '100412',
href: 'https://wallpapercave.com/wp/wp3913900.jpg',
viewUrl: 'https://wallpapercave.com/wp/wp3913900.jpg',
downloadUrl: 'https://wallpapercave.com/wp/wp3913900.jpg'
}, {
id: '6',
name: 'slack5.jpg',
size: '100412',
href: 'https://upload.wikimedia.org/wikipedia/commons/thumb/0/09/Giraffe_2019-07-28.jpg/682px-Giraffe_2019-07-28.jpg',
viewUrl: 'https://upload.wikimedia.org/wikipedia/commons/thumb/0/09/Giraffe_2019-07-28.jpg/682px-Giraffe_2019-07-28.jpg',
downloadUrl: 'https://upload.wikimedia.org/wikipedia/commons/thumb/0/09/Giraffe_2019-07-28.jpg/682px-Giraffe_2019-07-28.jpg'
}, {
id: '6',
name: 'slack5.mp3',
size: '100412',
href: 'https://www.w3schools.com/html/horse.mp3',
viewUrl: 'https://www.w3schools.com/html/horse.mp3',
downloadUrl: 'https://www.w3schools.com/html/horse.mp3'
}];
describe('AttachmentViewer', () => {
test('rendering the defult props', () => {
const {
asFragment
} = render( /*#__PURE__*/React.createElement(AttachmentViewer, {
previewObj: {
previewData: mockData,
selectedIndex: 0
}
}));
expect(asFragment()).toMatchSnapshot();
});
test('rendering the when isActive is true ', () => {
const {
asFragment
} = render( /*#__PURE__*/React.createElement(AttachmentViewer, {
isActive: true,
previewObj: {
previewData: mockData,
selectedIndex: 0
}
}));
expect(asFragment()).toMatchSnapshot();
});
test('rendering with renderCustomIcons', () => {
const {
asFragment
} = render( /*#__PURE__*/React.createElement(AttachmentViewer, {
isActive: true,
previewObj: {
previewData: mockData,
selectedIndex: 0
},
renderCustomIcons: props => {
const {
selectedAttachment,
selectedIndex,
totalLen
} = props;
return /*#__PURE__*/React.createElement("div", {
"data-id": "customIcons"
}, /*#__PURE__*/React.createElement("span", {
"data-id": "customIcons_name"
}, selectedAttachment.name), /*#__PURE__*/React.createElement("span", {
"data-id": "customIcons_index"
}, selectedIndex + 1, "/", totalLen));
}
}));
expect(asFragment()).toMatchSnapshot();
});
test('rendering with renderCustomImagePreviewElement', () => {
const {
asFragment
} = render( /*#__PURE__*/React.createElement(AttachmentViewer, {
isActive: true,
previewObj: {
previewData: mockData,
selectedIndex: 0
},
renderCustomImagePreviewElement: props => {
const {
defaultView,
data,
index: selectedIndex
} = props;
return /*#__PURE__*/React.createElement("div", {
"data-id": "customImagePreview"
}, /*#__PURE__*/React.createElement("span", {
"data-id": "customImagePreview_name"
}, data.name), /*#__PURE__*/React.createElement("span", {
"data-id": "customImagePreview_index"
}, selectedIndex + 1, "/", data.length));
}
}));
expect(asFragment()).toMatchSnapshot();
});
});