-
Notifications
You must be signed in to change notification settings - Fork 647
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
8 changed files
with
113 additions
and
13 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
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
Binary file added
BIN
+2.82 KB
...image_snapshots__/empty-data-test-tsx-empty-data-data-array-is-empty-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,71 @@ | ||
import { jsx } from '../../../src/jsx'; | ||
import Geometry from '../../../src/components/geometry'; | ||
import { createContext, delay } from '../../util'; | ||
import { Canvas, createRef, Chart, Axis } from '../../../src'; | ||
const context = createContext(); | ||
|
||
class Custom extends Geometry { | ||
render() { | ||
const records = this.mapping(); | ||
return ( | ||
<group> | ||
{records.map((record) => { | ||
const { children } = record; | ||
return children.map((item) => { | ||
const { x, y } = item; | ||
return ( | ||
<circle | ||
attrs={{ | ||
x, | ||
y, | ||
r: '20px', | ||
fill: '#000', | ||
}} | ||
/> | ||
); | ||
}); | ||
})} | ||
</group> | ||
); | ||
} | ||
} | ||
|
||
describe('empty data', () => { | ||
it('data is null', async () => { | ||
const { props } = ( | ||
<Canvas context={context} pixelRatio={1}> | ||
<Chart data={null}> | ||
<Axis field="x" /> | ||
<Custom x="x" y="y" /> | ||
</Chart> | ||
</Canvas> | ||
); | ||
const canvas = new Canvas(props); | ||
canvas.render(); | ||
|
||
await delay(100); | ||
|
||
expect(canvas.container.get('children').length).toBe(1); | ||
expect(canvas.container.get('children')[0].get('children').length).toBe(0); | ||
}); | ||
|
||
it('data array is empty', async () => { | ||
const ref = createRef(); | ||
const { props } = ( | ||
<Canvas context={context} pixelRatio={1} animate={false}> | ||
<Chart data={[]}> | ||
<Axis field="x" /> | ||
<Axis field="y" /> | ||
<Custom ref={ref} x="x" y="y" /> | ||
</Chart> | ||
</Canvas> | ||
); | ||
const canvas = new Canvas(props); | ||
canvas.render(); | ||
|
||
await delay(100); | ||
expect(context).toMatchImageSnapshot(); | ||
expect(ref.current.records.length).toBe(1); | ||
expect(ref.current.records[0].children).toEqual([]); | ||
}); | ||
}); |
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,29 @@ | ||
import { jsx, Canvas, createRef, Chart, Line } from '../../../src'; | ||
import { createContext, delay } from '../../util'; | ||
|
||
describe('空数据', () => { | ||
it('空数组', async () => { | ||
const context = createContext('空数组'); | ||
const ref = createRef(); | ||
const { props } = ( | ||
<Canvas context={context} pixelRatio={1} animate={false}> | ||
<Chart data={[]}> | ||
<Line ref={ref} x="x" y="y" /> | ||
</Chart> | ||
</Canvas> | ||
); | ||
|
||
const canvas = new Canvas(props); | ||
canvas.render(); | ||
|
||
await delay(100); | ||
|
||
expect( | ||
ref.current.container | ||
.get('children')[0] | ||
.get('children')[0] | ||
.get('children')[0] | ||
.get('children').length | ||
).toBe(0); | ||
}); | ||
}); |