|
| 1 | +import type { Graph, Label, Title } from '@/src'; |
| 2 | +import { pluginTitle } from '@@/demos'; |
| 3 | +import { createDemoGraph } from '../../utils'; |
| 4 | + |
| 5 | +describe('plugin title', () => { |
| 6 | + let graph: Graph; |
| 7 | + let titlePlugin: Title; |
| 8 | + |
| 9 | + const executeTest = () => { |
| 10 | + expect(typeof titlePlugin).toBe('object'); |
| 11 | + |
| 12 | + const [width] = graph.getSize(); |
| 13 | + |
| 14 | + // eslint-disable-next-line @typescript-eslint/ban-ts-comment |
| 15 | + // @ts-ignore |
| 16 | + const [titleLabel, subtitleLabel] = titlePlugin.canvas.getRoot().childNodes; |
| 17 | + |
| 18 | + const titleAttr = (titleLabel as Label).attributes; |
| 19 | + const titleX = titleAttr.x; |
| 20 | + expect(titleX).toBe(width / 2); |
| 21 | + |
| 22 | + const subtitleAttr = (subtitleLabel as Label).attributes; |
| 23 | + const subtitleX = subtitleAttr.x; |
| 24 | + expect(subtitleX).toBe(width / 2); |
| 25 | + |
| 26 | + expect(titleAttr.text).toBe('这是一个标题这是一个标题'); |
| 27 | + expect(subtitleAttr.text).toBe('这是一个副标'); |
| 28 | + |
| 29 | + expect(titleAttr.fontSize).toBe(28); |
| 30 | + expect(subtitleAttr.fill).toBe('#2989FF'); |
| 31 | + }; |
| 32 | + |
| 33 | + beforeAll(async () => { |
| 34 | + graph = await createDemoGraph(pluginTitle); |
| 35 | + titlePlugin = graph.getPluginInstance('title'); |
| 36 | + }); |
| 37 | + |
| 38 | + it('title', executeTest); |
| 39 | + |
| 40 | + afterAll(() => { |
| 41 | + graph.destroy(); |
| 42 | + }); |
| 43 | +}); |
0 commit comments