From ee915c39dccc6189d27a697218f168462d51626b Mon Sep 17 00:00:00 2001 From: Jeff Avallone Date: Thu, 31 Jan 2019 21:10:33 -0500 Subject: [PATCH] Tests for Text rendering component --- jest/setup.js | 2 + src/rendering/Text/__snapshots__/test.js.snap | 92 +++++++++++++++++++ src/rendering/Text/test.js | 53 +++++++++++ 3 files changed, 147 insertions(+) create mode 100644 src/rendering/Text/__snapshots__/test.js.snap create mode 100644 src/rendering/Text/test.js diff --git a/jest/setup.js b/jest/setup.js index ea1c273..6c6f32f 100644 --- a/jest/setup.js +++ b/jest/setup.js @@ -6,3 +6,5 @@ Enzyme.configure({ adapter: new Adapter() }); global.___loader = { enqueue: jest.fn() }; + +global.Element.prototype.getBBox = jest.fn(); diff --git a/src/rendering/Text/__snapshots__/test.js.snap b/src/rendering/Text/__snapshots__/test.js.snap new file mode 100644 index 0000000..0543be4 --- /dev/null +++ b/src/rendering/Text/__snapshots__/test.js.snap @@ -0,0 +1,92 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Text layout 1`] = ` +Object { + "box": Object { + "height": 20, + "width": 100, + }, + "children": Array [ + "Example content", + ], + "props": Object { + "property": "example", + "transform": "translate(0 -18)", + }, + "type": "Text", +} +`; + +exports[`Text positioning text 1`] = ` + + Example + +`; + +exports[`Text rendering 1`] = ` + + Example + +`; + +exports[`Text rendering quoted text 1`] = ` + + + “ + + + Example + + + ” + + +`; + +exports[`Text rendering with a theme 1`] = ` + + Example + +`; diff --git a/src/rendering/Text/test.js b/src/rendering/Text/test.js new file mode 100644 index 0000000..068b59e --- /dev/null +++ b/src/rendering/Text/test.js @@ -0,0 +1,53 @@ +import React from 'react'; +import { shallow } from 'enzyme'; + +import Text, { layout } from 'rendering/Text'; + +describe('Text', () => { + test('rendering', () => { + const component = shallow( + Example + ); + expect(component).toMatchSnapshot(); + }); + + test('positioning text', () => { + const component = shallow( + Example + ); + expect(component).toMatchSnapshot(); + }); + + test('rendering with a theme', () => { + const component = shallow( + Example + ); + expect(component).toMatchSnapshot(); + }); + + test('rendering quoted text', () => { + const component = shallow( + Example + ); + expect(component).toMatchSnapshot(); + }); + + test('layout', () => { + global.Element.prototype.getBBox.mockReturnValue({ + width: 100, + height: 20, + y: 18 + }); + + const processed = layout({ + type: 'Text', + props: { + property: 'example' + }, + children: [ + 'Example content' + ] + }); + expect(processed).toMatchSnapshot(); + }); +});