components#Tree TypeScript Examples

The following examples show how to use components#Tree. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.test.tsx    From geist-ui with MIT License 6 votes vote down vote up
describe('Tree', () => {
  it('should mount correctly', () => {
    const wrapper = mount(
      <Tree>
        <Tree.File name="package.json" />
        <Tree.Folder name="components">
          <Tree.File name="layout.js" />
          <Tree.File name="header.js" />
        </Tree.Folder>
        <Tree.File name="readme.md" />
      </Tree>,
    )
    expect(<Tree.File name="package.json" />).toMatchSnapshot()
    expect(<Tree.Folder name="components" />).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(<Tree value={files} />)
    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(<Tree value={mockFiles} onClick={callback} />)
    wrapper.find('.file').at(0).simulate('click', nativeEvent)
    expect(callback).toHaveBeenCalled()
  })

  it('should be work when value is empty', () => {
    const wrapper = mount(<Tree value={[]} />)
    expect(() => wrapper.unmount()).not.toThrow()
  })
})