-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Complete code coverage for external runtime (#11)
Complete code coverage for external runtime
- Loading branch information
Showing
52 changed files
with
1,799 additions
and
260 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
34 changes: 34 additions & 0 deletions
34
x-pack/legacy/plugins/canvas/external_runtime/__mocks__/supported_renderers.js
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 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import ReactDOM from 'react-dom'; | ||
import React from 'react'; | ||
|
||
const renderers = [ | ||
'debug', | ||
'error', | ||
'image', | ||
'repeatImage', | ||
'revealImage', | ||
'markdown', | ||
'metric', | ||
'pie', | ||
'plot', | ||
'progress', | ||
'shape', | ||
'table', | ||
'text', | ||
]; | ||
|
||
export const renderFunctions = renderers.map(fn => () => ({ | ||
name: fn, | ||
displayName: fn, | ||
help: fn, | ||
reuseDomNode: true, | ||
render: domNode => { | ||
ReactDOM.render(<div>{fn} mock</div>, domNode); | ||
}, | ||
})); |
71 changes: 71 additions & 0 deletions
71
...ck/legacy/plugins/canvas/external_runtime/api/__tests__/__snapshots__/embed.test.tsx.snap
Large diffs are not rendered by default.
Oops, something went wrong.
120 changes: 120 additions & 0 deletions
120
x-pack/legacy/plugins/canvas/external_runtime/api/__tests__/embed.test.tsx
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,120 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { mount } from 'enzyme'; | ||
import React from 'react'; | ||
import { snapshots, tick } from '../../test'; | ||
import { embed } from '../embed'; | ||
|
||
jest.mock('../../supported_renderers'); | ||
|
||
describe('Embed API', () => { | ||
beforeEach(function() { | ||
// @ts-ignore Applying a global in Jest is alright. | ||
global.fetch = jest.fn().mockImplementation(() => { | ||
const p = new Promise((resolve, _reject) => { | ||
resolve({ | ||
ok: true, | ||
json: () => { | ||
return snapshots.hello; | ||
}, | ||
}); | ||
}); | ||
return p; | ||
}); | ||
}); | ||
|
||
test('Embeds successfully with default properties', async () => { | ||
const container = document.createElement('div'); | ||
document.body.appendChild(container); | ||
const wrapper = mount(<div kbn-canvas-embed="canvas" kbn-canvas-url="workpad.json"></div>, { | ||
attachTo: container, | ||
}); | ||
|
||
expect(wrapper.html()).toMatchSnapshot(); | ||
embed(); | ||
await tick(); | ||
expect(wrapper.html()).toMatchSnapshot(); | ||
}); | ||
|
||
test('Embeds successfully with height specified', async () => { | ||
const container = document.createElement('div'); | ||
document.body.appendChild(container); | ||
const wrapper = mount( | ||
<div kbn-canvas-embed="canvas" kbn-canvas-height="350" kbn-canvas-url="workpad.json"></div>, | ||
{ | ||
attachTo: container, | ||
} | ||
); | ||
|
||
expect(wrapper.html()).toMatchSnapshot(); | ||
embed(); | ||
await tick(); | ||
expect(wrapper.html()).toMatch( | ||
/<div class=\"container\" style="height: 350px; width: 525px;\">/ | ||
); | ||
expect(wrapper.html()).toMatchSnapshot(); | ||
}); | ||
|
||
test('Embeds successfully with width specified', async () => { | ||
const container = document.createElement('div'); | ||
document.body.appendChild(container); | ||
const wrapper = mount( | ||
<div kbn-canvas-embed="canvas" kbn-canvas-width="400" kbn-canvas-url="workpad.json"></div>, | ||
{ | ||
attachTo: container, | ||
} | ||
); | ||
|
||
expect(wrapper.html()).toMatchSnapshot(); | ||
embed(); | ||
await tick(); | ||
expect(wrapper.html()).toMatch( | ||
/<div class=\"container\" style="height: 267px; width: 400px;\">/ | ||
); | ||
expect(wrapper.html()).toMatchSnapshot(); | ||
}); | ||
|
||
test('Embeds successfully with width and height specified', async () => { | ||
const container = document.createElement('div'); | ||
document.body.appendChild(container); | ||
const wrapper = mount( | ||
<div | ||
kbn-canvas-embed="canvas" | ||
kbn-canvas-width="350" | ||
kbn-canvas-height="350" | ||
kbn-canvas-url="workpad.json" | ||
></div>, | ||
{ | ||
attachTo: container, | ||
} | ||
); | ||
|
||
expect(wrapper.html()).toMatchSnapshot(); | ||
embed(); | ||
await tick(); | ||
expect(wrapper.html()).toMatch( | ||
/<div class=\"container\" style="height: 350px; width: 350px;\">/ | ||
); | ||
expect(wrapper.html()).toMatchSnapshot(); | ||
}); | ||
|
||
test('Embeds successfully with page specified', async () => { | ||
const container = document.createElement('div'); | ||
document.body.appendChild(container); | ||
const wrapper = mount( | ||
<div kbn-canvas-embed="canvas" kbn-canvas-page="0" kbn-canvas-url="workpad.json"></div>, | ||
{ | ||
attachTo: container, | ||
} | ||
); | ||
|
||
expect(wrapper.html()).toMatchSnapshot(); | ||
embed(); | ||
await tick(); | ||
expect(wrapper.html()).toMatchSnapshot(); | ||
}); | ||
}); |
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
41 changes: 0 additions & 41 deletions
41
x-pack/legacy/plugins/canvas/external_runtime/components/__examples__/footer.examples.tsx
This file was deleted.
Oops, something went wrong.
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
11 changes: 11 additions & 0 deletions
11
...gacy/plugins/canvas/external_runtime/components/__tests__/__snapshots__/app.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.