-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
647 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { chartEmitItemTooltip as render } from '../plots/api/chart-emit-item-tooltip'; | ||
import { kebabCase } from './utils/kebabCase'; | ||
import { | ||
dispatchFirstElementEvent, | ||
createPromise, | ||
receiveExpectData, | ||
} from './utils/event'; | ||
import './utils/useSnapshotMatchers'; | ||
import { createDOMGCanvas } from './utils/createDOMGCanvas'; | ||
|
||
describe('chart.emit', () => { | ||
const dir = `${__dirname}/snapshots/api/${kebabCase(render.name)}`; | ||
const canvas = createDOMGCanvas(800, 500); | ||
|
||
it('chart.emit and chart.on should control item tooltip display.', async () => { | ||
const { finished, chart, clear } = render({ | ||
canvas, | ||
container: document.createElement('div'), | ||
}); | ||
await finished; | ||
clear(); | ||
|
||
// chart.emit("tooltip:show", options) should show tooltip. | ||
await expect(canvas).toMatchDOMSnapshot(dir, 'step0', { | ||
selector: '.tooltip', | ||
}); | ||
|
||
// chart.emit("tooltip:hide") should hide tooltip. | ||
chart.emit('tooltip:hide'); | ||
await expect(canvas).toMatchDOMSnapshot(dir, 'step1', { | ||
selector: '.tooltip', | ||
}); | ||
|
||
chart.off(); | ||
// chart.on("tooltip:show", callback) should revive selected data. | ||
const [tooltipShowed, resolveShow] = createPromise(); | ||
chart.on('tooltip:show', receiveExpectData(resolveShow)); | ||
dispatchFirstElementEvent(canvas, 'pointerover'); | ||
await tooltipShowed; | ||
|
||
// chart.on("tooltip:hide") should be called when hiding tooltip. | ||
const [tooltipHided, resolveHide] = createPromise(); | ||
chart.on('tooltip:hide', receiveExpectData(resolveHide, null)); | ||
dispatchFirstElementEvent(canvas, 'pointerout'); | ||
await tooltipHided; | ||
}); | ||
|
||
afterAll(() => { | ||
canvas?.destroy(); | ||
}); | ||
}); |
59 changes: 59 additions & 0 deletions
59
__tests__/integration/api-chart-emit-series-tooltip.spec.ts
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,59 @@ | ||
import { chartEmitSeriesTooltip as render } from '../plots/api/chart-emit-series-tooltip'; | ||
import { kebabCase } from './utils/kebabCase'; | ||
import { | ||
dispatchPlotEvent, | ||
createPromise, | ||
receiveExpectData, | ||
} from './utils/event'; | ||
import { createDOMGCanvas } from './utils/createDOMGCanvas'; | ||
import './utils/useCustomFetch'; | ||
import './utils/useSnapshotMatchers'; | ||
|
||
describe('chart.emit', () => { | ||
const dir = `${__dirname}/snapshots/api/${kebabCase(render.name)}`; | ||
const canvas = createDOMGCanvas(800, 500); | ||
|
||
it('chart.emit and chart.on should control item tooltip display.', async () => { | ||
const { finished, chart, clear } = render({ | ||
canvas, | ||
container: document.createElement('div'), | ||
}); | ||
await finished; | ||
clear(); | ||
|
||
// chart.emit("tooltip:show", options) should show tooltip. | ||
await expect(canvas).toMatchDOMSnapshot(dir, 'step0', { | ||
selector: '.tooltip', | ||
}); | ||
|
||
// chart.emit("tooltip:hide") should hide tooltip. | ||
chart.emit('tooltip:hide'); | ||
await expect(canvas).toMatchDOMSnapshot(dir, 'step1', { | ||
selector: '.tooltip', | ||
}); | ||
|
||
chart.off(); | ||
// chart.on("tooltip:show", callback) should revive selected data. | ||
const [tooltipShowed, resolveShow] = createPromise(); | ||
chart.on('tooltip:show', (event) => { | ||
const { x } = event.data.data; | ||
expect(x.toUTCString()).toBe('Tue, 23 Oct 2007 05:18:47 GMT'); | ||
resolveShow(); | ||
}); | ||
dispatchPlotEvent(canvas, 'pointermove', { | ||
offsetX: 100, | ||
offsetY: 100, | ||
}); | ||
await tooltipShowed; | ||
|
||
// chart.on("tooltip:hide") should be called when hiding tooltip. | ||
const [tooltipHided, resolveHide] = createPromise(); | ||
chart.on('tooltip:hide', receiveExpectData(resolveHide, null)); | ||
dispatchPlotEvent(canvas, 'pointerleave'); | ||
await tooltipHided; | ||
}); | ||
|
||
afterAll(() => { | ||
canvas?.destroy(); | ||
}); | ||
}); |
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
46 changes: 46 additions & 0 deletions
46
__tests__/integration/snapshots/api/chart-emit-item-tooltip/step0.html
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,46 @@ | ||
<div | ||
xmlns="http://www.w3.org/1999/xhtml" | ||
class="tooltip" | ||
style="pointer-events: none; position: absolute; visibility: visible; z-index: 8; transition: visibility 0.2s cubic-bezier(0.23, 1, 0.32, 1), left 0.4s cubic-bezier(0.23, 1, 0.32, 1), top 0.4s cubic-bezier(0.23, 1, 0.32, 1); background-color: rgba(255, 255, 255, 0.96); box-shadow: 0 6px 12px 0 rgba(0, 0, 0, 0.12); border-radius: 4px; color: rgba(0, 0, 0, 0.65); font-size: 12px; line-height: 20px; padding: 12px; min-width: 120px; max-width: 360px; font-family: Roboto-Regular; left: 226.7156883688534px; top: 380.10715157645086px;" | ||
> | ||
<div | ||
class="tooltip-title" | ||
style="color: rgba(0, 0, 0, 0.45); overflow: hidden; white-space: nowrap; text-overflow: ellipsis;" | ||
> | ||
Strategy | ||
</div> | ||
<ul | ||
class="tooltip-list" | ||
style="margin: 0px; list-style-type: none; padding: 0px;" | ||
> | ||
<li | ||
class="tooltip-list-item" | ||
data-index="0" | ||
style="list-style-type: none; display: flex; line-height: 2em; align-items: center; justify-content: space-between; white-space: nowrap;" | ||
> | ||
<span | ||
class="tooltip-list-item-name" | ||
style="display: flex; align-items: center; max-width: 216px;" | ||
> | ||
<span | ||
class="tooltip-list-item-marker" | ||
style="background: rgb(90, 216, 166); width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 4px;" | ||
/> | ||
<span | ||
class="tooltip-list-item-name-label" | ||
title="sold" | ||
style="flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;" | ||
> | ||
sold | ||
</span> | ||
</span> | ||
<span | ||
class="tooltip-list-item-value" | ||
title="115" | ||
style="display: inline-block; float: right; flex: 1; text-align: right; min-width: 28px; margin-left: 30px; color: rgba(0, 0, 0, 0.85); overflow: hidden; white-space: nowrap; text-overflow: ellipsis;" | ||
> | ||
115 | ||
</span> | ||
</li> | ||
</ul> | ||
</div>; |
Oops, something went wrong.