Skip to content

Commit

Permalink
Update switch images when zoomed (#116)
Browse files Browse the repository at this point in the history
* fix incorrect image src on zoom

* Update CHANGELOG.md

* Fix downloading

* download test case added

* Update CHANGELOG.md

---------

Co-authored-by: Mikhail Volkov <[email protected]>
  • Loading branch information
vitPinchuk and mikhail-vl authored Jun 24, 2024
1 parent 61f8176 commit 3f09e98
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 6 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Changelog

## 5.1.0 (IN PROGRESS)
## 5.1.0 (2024-06-23)

### Features / Enhancements

- Updated video overview (#100)
- Added plugin e2e tests and remove cypress (#101, #102, #103, #105)
- Added ability to load image, videos from URL and video toolbar (#111)
- Added ability to load image, videos from URL and video toolbar (#111, #116)
- Updated to Grafana 11 and dependencies (#114)
- Updated to use frame utils from packages (#115)
- Updated E2E workflow using Docker (#117)

## 5.0.0 (2024-03-25)
Expand Down
94 changes: 92 additions & 2 deletions src/components/ImagePanel/ImagePanel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ describe('Image Panel', () => {
Object.defineProperty(HTMLElement.prototype, 'clientHeight', { configurable: true, value: elementHeight });
});

afterEach(() => {
jest.clearAllMocks();
});

it('Should output message', async () => {
render(
getComponent({
Expand Down Expand Up @@ -1023,7 +1027,7 @@ describe('Image Panel', () => {
* Toolbar
*/
describe('Toolbar', () => {
it('Should show download button for image', () => {
it('Should show download button for image and download image with base64 source type if url not specified', () => {
const image = '/9j/4AAQSkZJRAAdLxAACEAAIX/9k=';
render(
getComponent({
Expand All @@ -1049,7 +1053,49 @@ describe('Image Panel', () => {

fireEvent.click(screen.getByTestId(TEST_IDS.panel.buttonDownload));

expect(saveAs).toHaveBeenCalledWith(`data:image/jpeg;base64,${image}`);
expect(saveAs).toHaveBeenCalledWith('data:image/jpeg;base64,/9j/4AAQSkZJRAAdLxAACEAAIX/9k=');
});

it('Should show download button for image and download image with url source', () => {
const image = '/9j/4AAQSkZJRAAdLxAACEAAIX/9k=';
const imageUrl = 'https://volkovlabs.io/img/index/main.svg';
render(
getComponent({
data: {
series: [
toDataFrame({
name: 'data',
fields: [
{
type: FieldType.string,
name: ImageField.IMG,
values: [image],
},
{
type: FieldType.string,
name: 'imageUrl',
values: [imageUrl],
},
],
}),
],
},
options: {
toolbar: true,
buttons: [ButtonType.DOWNLOAD],
formats: DEFAULT_OPTIONS.formats,
videoUrl: '',
name: '',
imageUrl: 'imageUrl',
},
})
);

expect(screen.getByTestId(TEST_IDS.panel.buttonDownload)).toBeInTheDocument();

fireEvent.click(screen.getByTestId(TEST_IDS.panel.buttonDownload));

expect(saveAs).toHaveBeenCalledWith(imageUrl);
});

it('Should not show download button', () => {
Expand Down Expand Up @@ -1106,6 +1152,50 @@ describe('Image Panel', () => {
expect(screen.getByTestId(TEST_IDS.panel.zoomedImage)).toBeInTheDocument();
});

it('Should show zoom button for image with url', () => {
const image = '/9j/4AAQSkZJRAAdLxAACEAAIX/9k=';
const imageUrl = 'https://volkovlabs.io/img/index/main.svg';
render(
getComponent({
data: {
series: [
toDataFrame({
name: 'data',
fields: [
{
type: FieldType.string,
name: ImageField.IMG,
values: [image],
},
{
type: FieldType.string,
name: 'imageUrl',
values: [imageUrl],
},
],
}),
],
},
options: {
toolbar: true,
buttons: [ButtonType.ZOOM],
formats: DEFAULT_OPTIONS.formats,
videoUrl: '',
name: '',
imageUrl: 'imageUrl',
},
})
);

expect(screen.getByTestId(TEST_IDS.panel.buttonZoom)).toBeInTheDocument();
expect(screen.queryByTestId(TEST_IDS.panel.zoomedImage)).not.toBeInTheDocument();

fireEvent.click(screen.getByTestId(TEST_IDS.panel.buttonZoom));

expect(screen.getByTestId(TEST_IDS.panel.zoomedImage)).toBeInTheDocument();
expect(screen.getByTestId(TEST_IDS.panel.zoomedImage)).toHaveAttribute('src', imageUrl);
});

it('Should show pan pinch zoom controls for image', () => {
const image = '/9j/4AAQSkZJRAAdLxAACEAAIX/9k=';
render(
Expand Down
4 changes: 2 additions & 2 deletions src/components/ImagePanel/ImagePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ export const ImagePanel: React.FC<Props> = ({ options, data, width, height, repl
onZoomChange={setIsZoomed}
zoomImg={{
alt: '',
src: media,
src: imageUrl || media,
}}
classDialog={styles.zoom}
>
Expand Down Expand Up @@ -404,7 +404,7 @@ export const ImagePanel: React.FC<Props> = ({ options, data, width, height, repl
<ToolbarButton
icon="save"
onClick={() => {
saveAs(media);
saveAs(imageUrl || media);
}}
data-testid={TEST_IDS.panel.buttonDownload}
>
Expand Down

0 comments on commit 3f09e98

Please sign in to comment.