2020-11-26 09:22:30 -05:00
|
|
|
import { expect } from 'chai'
|
|
|
|
import React from 'react'
|
|
|
|
import { screen, fireEvent } from '@testing-library/react'
|
|
|
|
import renderWithContext from '../helpers/render-with-context'
|
|
|
|
|
|
|
|
import FileTreeDoc from '../../../../../frontend/js/features/file-tree/components/file-tree-doc'
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('<FileTreeDoc/>', function () {
|
|
|
|
it('renders unselected', function () {
|
2020-11-26 09:22:30 -05:00
|
|
|
const { container } = renderWithContext(
|
|
|
|
<FileTreeDoc name="foo.tex" id="123abc" isLinkedFile={false} />
|
|
|
|
)
|
|
|
|
|
|
|
|
screen.getByRole('treeitem', { selected: false })
|
|
|
|
expect(container.querySelector('i.linked-file-highlight')).to.not.exist
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('renders selected', function () {
|
2020-11-26 09:22:30 -05:00
|
|
|
renderWithContext(
|
2021-03-18 05:52:36 -04:00
|
|
|
<FileTreeDoc name="foo.tex" id="123abc" isLinkedFile={false} />,
|
|
|
|
{
|
|
|
|
contextProps: {
|
|
|
|
rootFolder: [
|
|
|
|
{
|
|
|
|
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 })
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('renders as linked file', function () {
|
2020-11-26 09:22:30 -05:00
|
|
|
const { container } = renderWithContext(
|
|
|
|
<FileTreeDoc name="foo.tex" id="123abc" isLinkedFile />
|
|
|
|
)
|
|
|
|
|
|
|
|
screen.getByRole('treeitem')
|
|
|
|
expect(container.querySelector('i.linked-file-highlight')).to.exist
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('selects', function () {
|
2021-03-18 05:52:36 -04:00
|
|
|
renderWithContext(<FileTreeDoc name="foo.tex" id="123abc" expanded />, {
|
|
|
|
contextProps: {
|
|
|
|
rootFolder: [
|
|
|
|
{
|
|
|
|
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 })
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('multi-selects', function () {
|
2021-03-18 05:52:36 -04:00
|
|
|
renderWithContext(<FileTreeDoc name="foo.tex" id="123abc" expanded />, {
|
|
|
|
contextProps: {
|
|
|
|
rootFolder: [
|
|
|
|
{
|
|
|
|
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')
|
|
|
|
|
|
|
|
fireEvent.click(treeitem, { ctrlKey: true })
|
|
|
|
screen.getByRole('treeitem', { selected: true })
|
|
|
|
})
|
|
|
|
})
|