-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed bug in
WebvizPluginPlaceholder
preventing download from worki…
…ng (#122) Fixed bug in `WebvizPluginPlaceholder` preventing download button from working. Added tests for `WebvizPluginPlaceholder`.
- Loading branch information
1 parent
a7b5915
commit f8e6690
Showing
6 changed files
with
411 additions
and
21 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
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,75 @@ | ||
import React from 'react'; | ||
import { render, RenderResult } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { WebvizPluginPlaceholder } from '../../src/lib'; | ||
import { WebvizPluginPlaceholderInteractiveContainer } from './WebvizPluginPlaceholderInteractiveContainer'; | ||
|
||
export type PropType = { | ||
data_requested?: number; | ||
}; | ||
|
||
|
||
const renderWebvizPluginPlaceholder = ( | ||
): RenderResult => { | ||
const steps = [ | ||
{ | ||
selector: "#blue-rect", | ||
content: "This is my first step", | ||
}, | ||
{ | ||
selector: "#green-rect", | ||
content: "This is my second step", | ||
}, | ||
]; | ||
return render( | ||
<WebvizPluginPlaceholder | ||
id="WebvizPluginPlaceholder" | ||
tour_steps={steps} | ||
setProps={() => { return; }} | ||
deprecation_warnings={ | ||
[ | ||
{ | ||
message: "Deprecated 1", | ||
url: "https://github.com/equinor/webviz-core-components" | ||
}, | ||
{ | ||
message: "Deprecated 2", | ||
url: "https://github.com/equinor/webviz-core-components" | ||
} | ||
] | ||
} | ||
/> | ||
); | ||
} | ||
|
||
const renderInteractiveWebvizPluginPlaceholder = (): RenderResult => { | ||
return render(<WebvizPluginPlaceholderInteractiveContainer />); | ||
}; | ||
|
||
describe('WebvizPluginPlaceholder', () => { | ||
|
||
it('Renders correctly (compare to snapshot in ./__snapshots__/WebvizPluginPlaceholder.test.tsx.snap)', () => { | ||
const { container } = renderWebvizPluginPlaceholder(); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
it('Data is downloaded correctly', () => { | ||
const { container } = renderInteractiveWebvizPluginPlaceholder(); | ||
|
||
const link = document.createElement("a"); | ||
|
||
jest.spyOn(document, "createElement").mockImplementationOnce(() => link); | ||
|
||
expect(container).toBeDefined(); | ||
|
||
const button = container.querySelectorAll(".webviz-config-plugin-button")[2] as HTMLElement; | ||
expect(button).toBeDefined(); | ||
|
||
userEvent.click(button); | ||
|
||
expect(link.href).toEqual('data:application/txt;base64,test'); | ||
expect(link.download).toEqual("test.txt"); | ||
jest.spyOn(document, "createElement").mockRestore(); | ||
}); | ||
|
||
}); |
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,44 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { WebvizPluginPlaceholder } from '../../src/lib'; | ||
import { PropType } from './WebvizPluginPlaceholder.test'; | ||
|
||
|
||
export const WebvizPluginPlaceholderInteractiveContainer: React.FC = (): JSX.Element => { | ||
const [download, setDownload] = React.useState(undefined); | ||
|
||
const steps = [ | ||
{ | ||
selector: "#blue-rect", | ||
content: "This is my first step", | ||
}, | ||
{ | ||
selector: "#green-rect", | ||
content: "This is my second step", | ||
}, | ||
]; | ||
|
||
const setProps = (props: PropType): void => { | ||
if (props.data_requested) { | ||
setDownload({ | ||
filename: "test.txt", | ||
content: "test", | ||
mime_type: "application/txt" | ||
}); | ||
} | ||
}; | ||
|
||
return ( | ||
<WebvizPluginPlaceholder | ||
id="WebvizPluginPlaceholder" | ||
tour_steps={steps} | ||
setProps={setProps} | ||
download={download} | ||
/> | ||
) | ||
}; | ||
|
||
WebvizPluginPlaceholderInteractiveContainer.propTypes = { | ||
data_requested: PropTypes.number | ||
}; |
Oops, something went wrong.