2020-11-26 09:22:30 -05:00
|
|
|
import { expect } from 'chai'
|
|
|
|
import { screen, fireEvent } from '@testing-library/react'
|
|
|
|
import renderWithContext from '../helpers/render-with-context'
|
|
|
|
|
|
|
|
import FileTreeFolder from '../../../../../frontend/js/features/file-tree/components/file-tree-folder'
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('<FileTreeFolder/>', function () {
|
|
|
|
beforeEach(function () {
|
2021-01-07 09:22:40 -05:00
|
|
|
global.localStorage.clear()
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('renders unselected', function () {
|
2020-11-26 09:22:30 -05:00
|
|
|
renderWithContext(
|
|
|
|
<FileTreeFolder
|
|
|
|
name="foo"
|
|
|
|
id="123abc"
|
|
|
|
folders={[]}
|
|
|
|
docs={[]}
|
|
|
|
files={[]}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
|
|
|
|
screen.getByRole('treeitem', { selected: false })
|
|
|
|
expect(screen.queryByRole('tree')).to.not.exist
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('renders selected', function () {
|
2020-11-26 09:22:30 -05:00
|
|
|
renderWithContext(
|
|
|
|
<FileTreeFolder
|
|
|
|
name="foo"
|
|
|
|
id="123abc"
|
|
|
|
folders={[]}
|
|
|
|
docs={[]}
|
|
|
|
files={[]}
|
2021-03-18 05:52:36 -04:00
|
|
|
/>,
|
|
|
|
{
|
|
|
|
contextProps: {
|
2022-01-10 10:47:01 -05:00
|
|
|
rootFolder: [
|
2021-03-18 05:52:36 -04:00
|
|
|
{
|
2022-01-10 10:46:46 -05:00
|
|
|
_id: 'root-folder-id',
|
|
|
|
name: 'rootFolder',
|
2021-03-18 05:52:36 -04:00
|
|
|
docs: [{ _id: '123abc' }],
|
|
|
|
fileRefs: [],
|
2021-04-27 03:52:58 -04:00
|
|
|
folders: [],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2021-03-18 05:52:36 -04:00
|
|
|
}
|
2020-11-26 09:22:30 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
const treeitem = screen.getByRole('treeitem', { selected: false })
|
|
|
|
fireEvent.click(treeitem)
|
|
|
|
|
|
|
|
screen.getByRole('treeitem', { selected: true })
|
|
|
|
expect(screen.queryByRole('tree')).to.not.exist
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('expands', function () {
|
2020-11-26 09:22:30 -05:00
|
|
|
renderWithContext(
|
|
|
|
<FileTreeFolder
|
|
|
|
name="foo"
|
|
|
|
id="123abc"
|
|
|
|
folders={[]}
|
|
|
|
docs={[]}
|
|
|
|
files={[]}
|
2021-03-18 05:52:36 -04:00
|
|
|
/>,
|
|
|
|
{
|
|
|
|
contextProps: {
|
2022-01-10 10:47:01 -05:00
|
|
|
rootFolder: [
|
2021-03-18 05:52:36 -04:00
|
|
|
{
|
2022-01-10 10:46:46 -05:00
|
|
|
_id: 'root-folder-id',
|
|
|
|
name: 'rootFolder',
|
2021-03-18 05:52:36 -04:00
|
|
|
docs: [{ _id: '123abc' }],
|
|
|
|
fileRefs: [],
|
2021-04-27 03:52:58 -04:00
|
|
|
folders: [],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2021-03-18 05:52:36 -04:00
|
|
|
}
|
2020-11-26 09:22:30 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
screen.getByRole('treeitem')
|
|
|
|
const expandButton = screen.getByRole('button', { name: 'Expand' })
|
|
|
|
|
|
|
|
fireEvent.click(expandButton)
|
|
|
|
screen.getByRole('tree')
|
|
|
|
})
|
2021-01-07 09:22:40 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('saves the expanded state for the next render', function () {
|
2021-01-07 09:22:40 -05:00
|
|
|
const { unmount } = renderWithContext(
|
|
|
|
<FileTreeFolder
|
|
|
|
name="foo"
|
|
|
|
id="123abc"
|
|
|
|
folders={[]}
|
|
|
|
docs={[]}
|
|
|
|
files={[]}
|
2021-03-18 05:52:36 -04:00
|
|
|
/>,
|
|
|
|
{
|
|
|
|
contextProps: {
|
2022-01-10 10:47:01 -05:00
|
|
|
rootFolder: [
|
2021-03-18 05:52:36 -04:00
|
|
|
{
|
2022-01-10 10:46:46 -05:00
|
|
|
_id: 'root-folder-id',
|
|
|
|
name: 'rootFolder',
|
2021-03-18 05:52:36 -04:00
|
|
|
docs: [{ _id: '123abc' }],
|
|
|
|
fileRefs: [],
|
2021-04-27 03:52:58 -04:00
|
|
|
folders: [],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2021-03-18 05:52:36 -04:00
|
|
|
}
|
2021-01-07 09:22:40 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
expect(screen.queryByRole('tree')).to.not.exist
|
|
|
|
|
|
|
|
const expandButton = screen.getByRole('button', { name: 'Expand' })
|
|
|
|
fireEvent.click(expandButton)
|
|
|
|
screen.getByRole('tree')
|
|
|
|
|
|
|
|
unmount()
|
|
|
|
|
|
|
|
renderWithContext(
|
|
|
|
<FileTreeFolder
|
|
|
|
name="foo"
|
|
|
|
id="123abc"
|
|
|
|
folders={[]}
|
|
|
|
docs={[]}
|
|
|
|
files={[]}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
|
|
|
|
screen.getByRole('tree')
|
|
|
|
})
|
2020-11-26 09:22:30 -05:00
|
|
|
})
|