Skip to content

Commit

Permalink
chore: fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikThePendric committed Sep 12, 2024
1 parent 29eaa18 commit e80039c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/components/ChartProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const throwIfNotInitialized = () => {
}

export const ChartContext = createContext({
getChartInstance: throwIfNotInitialized,
setChartInstance: throwIfNotInitialized,
getChart: throwIfNotInitialized,
setChart: throwIfNotInitialized,
isHighchartsChartInstance: throwIfNotInitialized,
})

Expand Down
6 changes: 6 additions & 0 deletions src/components/Visualization/Visualization.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@ UnconnectedVisualization.propTypes = {
}

UnconnectedVisualization.contextType = ChartContext
// Needed for Jest/Enzyme context mocking to work
UnconnectedVisualization.contextTypes = {
getChart: PropTypes.func,
setChart: PropTypes.func,
isHighchartsChartInstance: PropTypes.func,
}

const mapStateToProps = (state) => ({
visualization: sGetCurrent(state),
Expand Down
16 changes: 10 additions & 6 deletions src/components/Visualization/__tests__/Visualization.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ describe('Visualization', () => {
describe('component', () => {
let props
let shallowVisualization
const setChart = jest.fn()
const vis = () => {
if (!shallowVisualization) {
shallowVisualization = shallow(<Visualization {...props} />)
shallowVisualization = shallow(<Visualization {...props} />, {
context: {
setChart,
},
})
}
return shallowVisualization
}
Expand All @@ -26,7 +31,6 @@ describe('Visualization', () => {
error: null,
rightSidebarOpen: false,
addMetadata: jest.fn(),
setChart: jest.fn(),
clearLoadError: jest.fn(),
setLoadError: jest.fn(),
onLoadingComplete: jest.fn(),
Expand Down Expand Up @@ -71,12 +75,12 @@ describe('Visualization', () => {
})

it('triggers setChart action when chart has been generated', () => {
const svg = 'coolChart'
const highChartChartInstanceMock = {}

vis().instance().onChartGenerated(svg)
vis().instance().onChartGenerated(highChartChartInstanceMock)

expect(props.setChart).toHaveBeenCalled()
expect(props.setChart).toHaveBeenCalledWith(svg)
expect(setChart).toHaveBeenCalled()
expect(setChart).toHaveBeenCalledWith(highChartChartInstanceMock)
})

it('renders visualization with new id when rightSidebarOpen prop changes', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class MockAnalyticsResponse {

const createVisualizationMock = {
visualization: {
getSVGForExport: () => '<svg />',
exportChartLocal: jest.fn(),
},
config: {
getConfig: () => {},
Expand Down Expand Up @@ -148,7 +148,7 @@ describe('ChartPlugin', () => {
setTimeout(() => {
expect(props.onChartGenerated).toHaveBeenCalled()
expect(props.onChartGenerated).toHaveBeenCalledWith(
createVisualizationMock.visualization.getSVGForExport()
createVisualizationMock.visualization
)
done()
})
Expand Down

0 comments on commit e80039c

Please sign in to comment.