|
| 1 | +import { describe, expect, test } from 'vitest'; |
| 2 | + |
| 3 | +import getWrap from '../../src/node/getWrap'; |
| 4 | + |
| 5 | +describe('node getWrap', () => { |
| 6 | + test('Should return false by default for non-wrap types', () => { |
| 7 | + const svgResult = getWrap({ type: 'SVG', props: {}, style: {} }); |
| 8 | + expect(svgResult).toBe(false); |
| 9 | + |
| 10 | + const noteResult = getWrap({ type: 'NOTE', props: {}, style: {} }); |
| 11 | + expect(noteResult).toBe(false); |
| 12 | + |
| 13 | + const imageResult = getWrap({ |
| 14 | + type: 'IMAGE', |
| 15 | + props: { src: '' }, |
| 16 | + style: {}, |
| 17 | + }); |
| 18 | + expect(imageResult).toBe(false); |
| 19 | + |
| 20 | + const canvasResult = getWrap({ |
| 21 | + type: 'CANVAS', |
| 22 | + props: { paint: () => null }, |
| 23 | + style: {}, |
| 24 | + }); |
| 25 | + expect(canvasResult).toBe(false); |
| 26 | + }); |
| 27 | + |
| 28 | + test('Should return true by default for other types', () => { |
| 29 | + const viewResult = getWrap({ type: 'VIEW', props: {}, style: {} }); |
| 30 | + expect(viewResult).toBe(true); |
| 31 | + |
| 32 | + const textResult = getWrap({ type: 'TEXT', props: {}, style: {} }); |
| 33 | + expect(textResult).toBe(true); |
| 34 | + }); |
| 35 | + |
| 36 | + test('Should return true if wrap value is null or undefined', () => { |
| 37 | + const undefinedResult = getWrap({ |
| 38 | + type: 'VIEW', |
| 39 | + props: { wrap: undefined }, |
| 40 | + style: {}, |
| 41 | + }); |
| 42 | + expect(undefinedResult).toBe(true); |
| 43 | + |
| 44 | + // @ts-expect-error Deliberately testing an invalid case to ensure it's also handled gracefully |
| 45 | + const nullResult = getWrap({ |
| 46 | + type: 'VIEW', |
| 47 | + props: { wrap: null }, |
| 48 | + style: {}, |
| 49 | + }); |
| 50 | + expect(nullResult).toBe(true); |
| 51 | + }); |
| 52 | + |
| 53 | + test('Should return the custom wrap value if provided', () => { |
| 54 | + const trueResult = getWrap({ |
| 55 | + type: 'VIEW', |
| 56 | + props: { wrap: true }, |
| 57 | + style: {}, |
| 58 | + }); |
| 59 | + expect(trueResult).toBe(true); |
| 60 | + |
| 61 | + const falseResult = getWrap({ |
| 62 | + type: 'VIEW', |
| 63 | + props: { wrap: false }, |
| 64 | + style: {}, |
| 65 | + }); |
| 66 | + expect(falseResult).toBe(false); |
| 67 | + }); |
| 68 | +}); |
0 commit comments