From c7ac8d91ee6d3591b2db9fd8ec6e73fb9ce03e46 Mon Sep 17 00:00:00 2001 From: unix Date: Sun, 19 Apr 2020 10:19:06 +0800 Subject: [PATCH] test(file-tree): add testcase --- .../__snapshots__/index.test.tsx.snap | 21 ++++++ components/file-tree/__tests__/index.test.tsx | 75 +++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 components/file-tree/__tests__/__snapshots__/index.test.tsx.snap create mode 100644 components/file-tree/__tests__/index.test.tsx diff --git a/components/file-tree/__tests__/__snapshots__/index.test.tsx.snap b/components/file-tree/__tests__/__snapshots__/index.test.tsx.snap new file mode 100644 index 0000000..8763a6f --- /dev/null +++ b/components/file-tree/__tests__/__snapshots__/index.test.tsx.snap @@ -0,0 +1,21 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Tree should mount correctly 1`] = ` + +`; + +exports[`Tree should mount correctly 2`] = ` + +`; + +exports[`Tree should mount correctly 3`] = `ReactWrapper {}`; diff --git a/components/file-tree/__tests__/index.test.tsx b/components/file-tree/__tests__/index.test.tsx new file mode 100644 index 0000000..f64ac1f --- /dev/null +++ b/components/file-tree/__tests__/index.test.tsx @@ -0,0 +1,75 @@ +import React from 'react' +import { mount } from 'enzyme' +import { Tree } from 'components' +import { nativeEvent } from 'tests/utils' +import { FileTreeValue } from 'components/file-tree/tree' + +const mockFiles: Array = [{ + type: 'file', + name: 'cs.js', +}, { + type: 'directory', + name: 'bin', + files: [{ + type: 'file', + name: 'cs.js', + }], +}, { + type: 'directory', + name: 'docs', + files: [{ + type: 'file', + name: 'controllers.md', + }, { + type: 'file', + name: 'es6.md', + }, { + type: 'file', + name: 'production.md', + }, { + type: 'file', + name: 'views.md', + }], +}, { + type: 'file', + name: 'views.md', +}] + +describe('Tree', () => { + it('should mount correctly', () => { + const wrapper = mount( + + + + + + + + + ) + expect().toMatchSnapshot() + expect().toMatchSnapshot() + expect(wrapper).toMatchSnapshot() + expect(() => wrapper.unmount()).not.toThrow() + }) + + it('should show extra messages', () => { + const files = mockFiles.map(item => ({ ...item, extra: 'extra' })) + const wrapper = mount() + const firstName = wrapper.find('.name').at(0) + expect(firstName.text()).toContain('extra') + expect(() => wrapper.unmount()).not.toThrow() + }) + + it('should trigger event when file clicked', () => { + const callback = jest.fn() + const wrapper = mount() + wrapper.find('.file').at(0).simulate('click', nativeEvent) + expect(callback).toHaveBeenCalled() + }) + + it('should be work when value is empty', () => { + const wrapper = mount() + expect(() => wrapper.unmount()).not.toThrow() + }) +})