2024-07-24 09:40:24 -04:00
|
|
|
import '../../helpers/bootstrap-3'
|
2022-04-06 06:14:43 -04:00
|
|
|
import { EditorProviders } from '../../helpers/editor-providers'
|
|
|
|
import PdfLogsEntries from '../../../../frontend/js/features/pdf-preview/components/pdf-logs-entries'
|
2023-01-09 07:52:11 -05:00
|
|
|
import { detachChannel, testDetachChannel } from '../../helpers/detach-channel'
|
2023-10-26 06:01:08 -04:00
|
|
|
import { FileTreePathContext } from '@/features/file-tree/contexts/file-tree-path'
|
|
|
|
import { FindResult } from '@/features/file-tree/util/path'
|
|
|
|
import { FC } from 'react'
|
2024-06-05 04:33:11 -04:00
|
|
|
import {
|
|
|
|
EditorManager,
|
|
|
|
EditorManagerContext,
|
|
|
|
} from '@/features/ide-react/context/editor-manager-context'
|
2024-07-10 07:15:12 -04:00
|
|
|
import { EditorView } from '@codemirror/view'
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
|
|
describe('<PdfLogsEntries/>', function () {
|
2023-10-26 06:01:08 -04:00
|
|
|
const fakeFindEntityResult: FindResult = {
|
|
|
|
type: 'doc',
|
|
|
|
entity: { _id: '123', name: '123 Doc' },
|
|
|
|
}
|
|
|
|
|
|
|
|
const FileTreePathProvider: FC = ({ children }) => (
|
|
|
|
<FileTreePathContext.Provider
|
|
|
|
value={{
|
|
|
|
dirname: cy.stub(),
|
|
|
|
findEntityByPath: cy
|
|
|
|
.stub()
|
|
|
|
.as('findEntityByPath')
|
|
|
|
.returns(fakeFindEntityResult),
|
|
|
|
pathInFolder: cy.stub(),
|
|
|
|
previewByPath: cy.stub(),
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</FileTreePathContext.Provider>
|
|
|
|
)
|
2022-04-06 06:14:43 -04:00
|
|
|
|
2024-06-05 04:33:11 -04:00
|
|
|
const EditorManagerProvider: FC = ({ children }) => {
|
|
|
|
const value = {
|
|
|
|
openDocId: cy.spy().as('openDocId'),
|
|
|
|
} as unknown as EditorManager
|
|
|
|
|
|
|
|
return (
|
|
|
|
<EditorManagerContext.Provider value={value}>
|
|
|
|
{children}
|
|
|
|
</EditorManagerContext.Provider>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-04-06 06:14:43 -04:00
|
|
|
const logEntries = [
|
|
|
|
{
|
|
|
|
file: 'main.tex',
|
|
|
|
line: 9,
|
|
|
|
column: 8,
|
|
|
|
level: 'error',
|
|
|
|
message: 'LaTeX Error',
|
|
|
|
content: 'See the LaTeX manual',
|
|
|
|
raw: '',
|
|
|
|
ruleId: 'hint_misplaced_alignment_tab_character',
|
|
|
|
key: '',
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
2024-07-10 07:15:12 -04:00
|
|
|
const scope = {
|
|
|
|
'editor.view': new EditorView({ doc: '\\documentclass{article}' }),
|
|
|
|
}
|
|
|
|
|
2022-04-06 06:14:43 -04:00
|
|
|
beforeEach(function () {
|
|
|
|
cy.interceptCompile()
|
|
|
|
cy.interceptEvents()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('displays human readable hint', function () {
|
2022-06-08 03:39:09 -04:00
|
|
|
cy.mount(
|
2024-07-10 07:15:12 -04:00
|
|
|
<EditorProviders scope={scope}>
|
2022-04-06 06:14:43 -04:00
|
|
|
<PdfLogsEntries entries={logEntries} />
|
|
|
|
</EditorProviders>
|
|
|
|
)
|
|
|
|
|
|
|
|
cy.contains('You have placed an alignment tab character')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('opens doc on click', function () {
|
2022-06-08 03:39:09 -04:00
|
|
|
cy.mount(
|
2024-06-05 04:33:11 -04:00
|
|
|
<EditorProviders
|
2024-07-10 07:15:12 -04:00
|
|
|
scope={scope}
|
2024-06-05 04:33:11 -04:00
|
|
|
providers={{ EditorManagerProvider, FileTreePathProvider }}
|
|
|
|
>
|
2022-04-06 06:14:43 -04:00
|
|
|
<PdfLogsEntries entries={logEntries} />
|
|
|
|
</EditorProviders>
|
|
|
|
)
|
|
|
|
|
|
|
|
cy.findByRole('button', {
|
|
|
|
name: 'Navigate to log position in source code: main.tex, 9',
|
2023-01-09 07:52:11 -05:00
|
|
|
}).click()
|
|
|
|
|
2024-06-05 04:33:11 -04:00
|
|
|
cy.get('@findEntityByPath').should('have.been.calledOnceWith', 'main.tex')
|
2023-10-26 06:01:08 -04:00
|
|
|
cy.get('@openDocId').should(
|
|
|
|
'have.been.calledOnceWith',
|
|
|
|
fakeFindEntityResult.entity._id,
|
|
|
|
{
|
|
|
|
gotoLine: 9,
|
|
|
|
gotoColumn: 8,
|
2024-06-26 04:06:51 -04:00
|
|
|
keepCurrentView: false,
|
2023-10-26 06:01:08 -04:00
|
|
|
}
|
|
|
|
)
|
2022-04-06 06:14:43 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('opens doc via detached action', function () {
|
|
|
|
cy.window().then(win => {
|
2024-06-18 06:01:37 -04:00
|
|
|
win.metaAttributesCache.set('ol-detachRole', 'detacher')
|
2022-04-06 06:14:43 -04:00
|
|
|
})
|
|
|
|
|
2022-06-08 03:39:09 -04:00
|
|
|
cy.mount(
|
2024-06-05 04:33:11 -04:00
|
|
|
<EditorProviders
|
2024-07-10 07:15:12 -04:00
|
|
|
scope={scope}
|
2024-06-05 04:33:11 -04:00
|
|
|
providers={{ EditorManagerProvider, FileTreePathProvider }}
|
|
|
|
>
|
2022-04-06 06:14:43 -04:00
|
|
|
<PdfLogsEntries entries={logEntries} />
|
|
|
|
</EditorProviders>
|
|
|
|
).then(() => {
|
2023-01-09 07:52:11 -05:00
|
|
|
testDetachChannel.postMessage({
|
2022-04-06 06:14:43 -04:00
|
|
|
role: 'detached',
|
|
|
|
event: 'action-sync-to-entry',
|
|
|
|
data: {
|
|
|
|
args: [
|
|
|
|
{
|
|
|
|
file: 'main.tex',
|
|
|
|
line: 7,
|
|
|
|
column: 6,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
})
|
2023-01-09 07:52:11 -05:00
|
|
|
})
|
2022-04-06 06:14:43 -04:00
|
|
|
|
2023-05-24 06:03:36 -04:00
|
|
|
cy.get('@findEntityByPath').should('have.been.calledOnce')
|
2023-10-26 06:01:08 -04:00
|
|
|
cy.get('@openDocId').should(
|
|
|
|
'have.been.calledOnceWith',
|
|
|
|
fakeFindEntityResult.entity._id,
|
|
|
|
{
|
|
|
|
gotoLine: 7,
|
|
|
|
gotoColumn: 6,
|
2024-06-26 04:06:51 -04:00
|
|
|
keepCurrentView: false,
|
2023-10-26 06:01:08 -04:00
|
|
|
}
|
|
|
|
)
|
2022-04-06 06:14:43 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('sends open doc clicks via detached action', function () {
|
|
|
|
cy.window().then(win => {
|
2024-06-18 06:01:37 -04:00
|
|
|
win.metaAttributesCache.set('ol-detachRole', 'detached')
|
2022-04-06 06:14:43 -04:00
|
|
|
})
|
|
|
|
|
2022-06-08 03:39:09 -04:00
|
|
|
cy.mount(
|
2024-06-05 04:33:11 -04:00
|
|
|
<EditorProviders
|
2024-07-10 07:15:12 -04:00
|
|
|
scope={scope}
|
2024-06-05 04:33:11 -04:00
|
|
|
providers={{ EditorManagerProvider, FileTreePathProvider }}
|
|
|
|
>
|
2022-04-06 06:14:43 -04:00
|
|
|
<PdfLogsEntries entries={logEntries} />
|
|
|
|
</EditorProviders>
|
|
|
|
)
|
|
|
|
|
2023-01-09 07:52:11 -05:00
|
|
|
cy.spy(detachChannel, 'postMessage').as('postDetachMessage')
|
|
|
|
|
2022-04-06 06:14:43 -04:00
|
|
|
cy.findByRole('button', {
|
|
|
|
name: 'Navigate to log position in source code: main.tex, 9',
|
2023-01-09 07:52:11 -05:00
|
|
|
}).click()
|
|
|
|
|
2023-05-24 06:03:36 -04:00
|
|
|
cy.get('@findEntityByPath').should('not.have.been.called')
|
2023-10-26 06:01:08 -04:00
|
|
|
cy.get('@openDocId').should('not.have.been.called')
|
2023-05-24 06:03:36 -04:00
|
|
|
cy.get('@postDetachMessage').should('have.been.calledWith', {
|
2023-01-09 07:52:11 -05:00
|
|
|
role: 'detached',
|
|
|
|
event: 'action-sync-to-entry',
|
|
|
|
data: {
|
|
|
|
args: [
|
|
|
|
{
|
|
|
|
file: 'main.tex',
|
|
|
|
line: 9,
|
|
|
|
column: 8,
|
2022-04-06 06:14:43 -04:00
|
|
|
},
|
2023-01-09 07:52:11 -05:00
|
|
|
],
|
|
|
|
},
|
|
|
|
})
|
2022-04-06 06:14:43 -04:00
|
|
|
})
|
|
|
|
})
|