-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from eea/develop
Add preview image middlware to save preview image
- Loading branch information
Showing
9 changed files
with
404 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { createImageUrl } from './helpers'; | ||
|
||
describe('createImageUrl', () => { | ||
it('should create a valid image URL from the base64 encoded data', () => { | ||
// Mock data for the test | ||
const mockResult = { | ||
data: 'aGVsbG8gd29ybGQ=', // "hello world" in base64 | ||
'content-type': 'image/png', | ||
}; | ||
|
||
// Mock the atob function | ||
jest.spyOn(window, 'atob').mockImplementation(() => 'hello world'); | ||
|
||
// Mock the URL.createObjectURL function | ||
const mockUrl = 'blob:http://localhost:3000/some-url'; | ||
global.URL.createObjectURL = jest.fn().mockReturnValue(mockUrl); | ||
|
||
// Call the function | ||
const imageUrl = createImageUrl(mockResult); | ||
|
||
// Assertions | ||
expect(window.atob).toHaveBeenCalledWith(mockResult.data); | ||
expect(URL.createObjectURL).toHaveBeenCalledWith(expect.any(Blob)); | ||
expect(imageUrl).toBe(mockUrl); | ||
|
||
// Verify the Blob creation | ||
const blobArgs = URL.createObjectURL.mock.calls[0][0]; | ||
expect(blobArgs.type).toBe(mockResult['content-type']); | ||
expect(blobArgs.size).toBe(11); // "hello world" is 11 bytes | ||
|
||
// Clean up mocks | ||
jest.restoreAllMocks(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import React from 'react'; | ||
import { render, fireEvent, screen } from '@testing-library/react'; | ||
import Sources from './Sources'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
|
||
const mockSources = [ | ||
{ | ||
chart_source: 'Source 1', | ||
chart_source_link: 'http://example.com/source1', | ||
organisation: 'Organisation 1', | ||
title: 'Title 1', | ||
link: 'http://example.com/link1', | ||
}, | ||
{ | ||
chart_source: 'Source 2', | ||
chart_source_link: 'http://example.com/source2', | ||
organisation: 'Organisation 2', | ||
title: 'Title 2', | ||
link: 'http://example.com/link2', | ||
}, | ||
]; | ||
|
||
describe('Sources', () => { | ||
it('renders the Sources button', () => { | ||
render(<Sources sources={mockSources} />); | ||
expect(screen.getByText('Sources')).toBeInTheDocument(); | ||
}); | ||
|
||
it('opens and closes the popup on click', () => { | ||
render(<Sources sources={mockSources} />); | ||
|
||
const triggerButton = screen.getByText('Sources'); | ||
|
||
expect(screen.queryByText('Source 1')).toBeInTheDocument(); | ||
|
||
fireEvent.click(triggerButton); | ||
expect(screen.getByText('Source 1')).toBeInTheDocument(); | ||
expect(screen.getByText('Source 2')).toBeInTheDocument(); | ||
|
||
fireEvent.click(triggerButton); | ||
}); | ||
|
||
it('renders sources correctly', () => { | ||
render(<Sources sources={mockSources} />); | ||
|
||
const triggerButton = screen.getByText('Sources'); | ||
fireEvent.click(triggerButton); | ||
|
||
expect(screen.getByText('Source 1')).toBeInTheDocument(); | ||
expect(screen.getByText('Source 2')).toBeInTheDocument(); | ||
|
||
expect(screen.getByText('Source 1').closest('a')).toHaveAttribute( | ||
'href', | ||
'http://example.com/source1', | ||
); | ||
expect(screen.getByText('Source 2').closest('a')).toHaveAttribute( | ||
'href', | ||
'http://example.com/source2', | ||
); | ||
}); | ||
|
||
it('renders a message when there are no sources', () => { | ||
render(<Sources sources={[]} />); | ||
|
||
const triggerButton = screen.getByText('Sources'); | ||
fireEvent.click(triggerButton); | ||
|
||
expect( | ||
screen.getByText('Data provenance is not set for this visualization.'), | ||
).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { Provider } from 'react-redux'; | ||
import configureStore from 'redux-mock-store'; | ||
import MapsViewWidget from './MapsViewWidget'; | ||
import EmbedMap from '@eeacms/volto-embed/EmbedMap/EmbedMap'; | ||
import { pickMetadata } from '@eeacms/volto-embed/helpers'; | ||
import '@testing-library/jest-dom/extend-expect'; // Importă jest-dom | ||
|
||
jest.mock('@eeacms/volto-embed/EmbedMap/EmbedMap', () => | ||
jest.fn(() => <div>Mocked EmbedMap</div>), | ||
); | ||
jest.mock('@eeacms/volto-embed/helpers', () => ({ | ||
pickMetadata: jest.fn(), | ||
})); | ||
|
||
const mockStore = configureStore([]); | ||
|
||
describe('MapsViewWidget', () => { | ||
let store; | ||
|
||
beforeEach(() => { | ||
store = mockStore({ | ||
content: { | ||
data: { | ||
metadata: { | ||
title: 'Test Title', | ||
description: 'Test Description', | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should render EmbedMap with the correct data props', () => { | ||
const mockValue = { | ||
map_url: 'http://example.com/map', | ||
}; | ||
const mockId = 'map-widget-1'; | ||
|
||
pickMetadata.mockReturnValue({ | ||
title: 'Test Title', | ||
description: 'Test Description', | ||
}); | ||
|
||
const { getByText } = render( | ||
<Provider store={store}> | ||
<MapsViewWidget id={mockId} value={mockValue} /> | ||
</Provider>, | ||
); | ||
|
||
expect(EmbedMap).toHaveBeenCalledWith( | ||
{ | ||
data: { | ||
map_url: 'http://example.com/map', | ||
title: 'Test Title', | ||
description: 'Test Description', | ||
with_share: true, | ||
}, | ||
id: mockId, | ||
}, | ||
{}, | ||
); | ||
|
||
expect(getByText('Mocked EmbedMap')).toBeInTheDocument(); // Verifică dacă elementul este în document | ||
}); | ||
|
||
it('should handle empty value prop correctly', () => { | ||
const mockId = 'map-widget-2'; | ||
|
||
pickMetadata.mockReturnValue({ | ||
title: 'Test Title', | ||
description: 'Test Description', | ||
}); | ||
|
||
const { getByText } = render( | ||
<Provider store={store}> | ||
<MapsViewWidget id={mockId} value={null} /> | ||
</Provider>, | ||
); | ||
|
||
expect(EmbedMap).toHaveBeenCalledWith( | ||
{ | ||
data: { | ||
title: 'Test Title', | ||
description: 'Test Description', | ||
with_share: true, | ||
}, | ||
id: mockId, | ||
}, | ||
{}, | ||
); | ||
|
||
expect(getByText('Mocked EmbedMap')).toBeInTheDocument(); // Verifică dacă elementul este în document | ||
}); | ||
}); |
Oops, something went wrong.