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'
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
|
|
describe('<PdfLogsEntries/>', function () {
|
|
|
|
const fakeEntity = { type: 'doc' }
|
|
|
|
|
|
|
|
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: '',
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
2022-05-27 08:32:27 -04:00
|
|
|
let props: Record<string, any>
|
2022-04-06 06:14:43 -04:00
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
props = {
|
|
|
|
fileTreeManager: {
|
|
|
|
findEntityByPath: cy.stub().as('findEntityByPath').returns(fakeEntity),
|
|
|
|
},
|
|
|
|
editorManager: {
|
2022-10-18 04:46:53 -04:00
|
|
|
openDoc: cy.spy().as('openDoc'),
|
2022-04-06 06:14:43 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
cy.interceptCompile()
|
|
|
|
cy.interceptEvents()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('displays human readable hint', function () {
|
2022-06-08 03:39:09 -04:00
|
|
|
cy.mount(
|
2022-04-06 06:14:43 -04:00
|
|
|
<EditorProviders {...props}>
|
|
|
|
<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(
|
2022-04-06 06:14:43 -04:00
|
|
|
<EditorProviders {...props}>
|
|
|
|
<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()
|
|
|
|
|
2023-05-24 06:03:36 -04:00
|
|
|
cy.get('@findEntityByPath').should('have.been.calledOnce')
|
|
|
|
cy.get('@openDoc').should('have.been.calledOnceWith', fakeEntity, {
|
2023-01-09 07:52:11 -05:00
|
|
|
gotoLine: 9,
|
|
|
|
gotoColumn: 8,
|
2022-04-06 06:14:43 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('opens doc via detached action', function () {
|
|
|
|
cy.window().then(win => {
|
|
|
|
win.metaAttributesCache = new Map([['ol-detachRole', 'detacher']])
|
|
|
|
})
|
|
|
|
|
2022-06-08 03:39:09 -04:00
|
|
|
cy.mount(
|
2022-04-06 06:14:43 -04:00
|
|
|
<EditorProviders {...props}>
|
|
|
|
<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')
|
|
|
|
cy.get('@openDoc').should('have.been.calledOnceWith', fakeEntity, {
|
2023-01-09 07:52:11 -05:00
|
|
|
gotoLine: 7,
|
|
|
|
gotoColumn: 6,
|
2022-04-06 06:14:43 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('sends open doc clicks via detached action', function () {
|
|
|
|
cy.window().then(win => {
|
|
|
|
win.metaAttributesCache = new Map([['ol-detachRole', 'detached']])
|
|
|
|
})
|
|
|
|
|
2022-06-08 03:39:09 -04:00
|
|
|
cy.mount(
|
2022-04-06 06:14:43 -04:00
|
|
|
<EditorProviders {...props}>
|
|
|
|
<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')
|
|
|
|
cy.get('@openDoc').should('not.have.been.called')
|
|
|
|
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
|
|
|
})
|
|
|
|
})
|