2021-01-14 10:16:54 -05:00
|
|
|
import { screen, fireEvent } from '@testing-library/react'
|
2020-11-16 05:15:29 -05:00
|
|
|
import PreviewLogsPane from '../../../../../frontend/js/features/preview/components/preview-logs-pane'
|
|
|
|
import sinon from 'sinon'
|
2021-01-14 10:16:54 -05:00
|
|
|
import { renderWithEditorContext } from '../../../helpers/render-with-context'
|
2020-11-16 05:15:29 -05:00
|
|
|
|
|
|
|
const { expect } = require('chai')
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('<PreviewLogsPane />', function () {
|
2020-11-16 05:15:29 -05:00
|
|
|
const sampleError1 = {
|
|
|
|
content: 'error 1 content',
|
|
|
|
file: 'main.tex',
|
|
|
|
level: 'error',
|
|
|
|
line: 17,
|
2021-04-27 03:52:58 -04:00
|
|
|
message: 'Misplaced alignment tab character &.',
|
2020-11-16 05:15:29 -05:00
|
|
|
}
|
|
|
|
const sampleError2 = {
|
|
|
|
content: 'error 1 content',
|
|
|
|
file: 'main.tex',
|
|
|
|
level: 'error',
|
|
|
|
line: 22,
|
2021-04-27 03:52:58 -04:00
|
|
|
message: 'Extra alignment tab has been changed to cr.',
|
2020-11-16 05:15:29 -05:00
|
|
|
}
|
|
|
|
const sampleWarning = {
|
|
|
|
file: 'main.tex',
|
|
|
|
level: 'warning',
|
|
|
|
line: 30,
|
2021-04-27 03:52:58 -04:00
|
|
|
message: "Reference `idontexist' on page 1 undefined on input line 30.",
|
2020-11-16 05:15:29 -05:00
|
|
|
}
|
2020-11-26 04:58:42 -05:00
|
|
|
const sampleTypesettingIssue = {
|
|
|
|
file: 'main.tex',
|
|
|
|
level: 'typesetting',
|
|
|
|
line: 12,
|
2021-04-27 03:52:58 -04:00
|
|
|
message: "Reference `idontexist' on page 1 undefined on input line 30.",
|
2020-11-26 04:58:42 -05:00
|
|
|
}
|
2020-11-16 05:15:29 -05:00
|
|
|
const sampleRawLog = `
|
|
|
|
This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020) (preloaded format=pdflatex 2020.9.10) 6 NOV 2020 15:23
|
|
|
|
entering extended mode
|
|
|
|
\\write18 enabled.
|
|
|
|
%&-line parsing enabled.
|
|
|
|
**main.tex
|
|
|
|
(/compile/main.tex
|
|
|
|
LaTeX2e <2020-02-02> patch level 5
|
|
|
|
L3 programming layer <2020-07-17> (/usr/local/texlive/2020/texmf-dist/tex/latex
|
|
|
|
/base/article.cls
|
|
|
|
Document Class: article 2019/12/20 v1.4l Standard LaTeX document class
|
|
|
|
(/usr/local/texlive/2020/texmf-dist/tex/latex/base/size10.clo
|
|
|
|
File: size10.clo 2019/12/20 v1.4l Standard LaTeX file (size option)
|
|
|
|
)`
|
|
|
|
const errors = [sampleError1, sampleError2]
|
|
|
|
const warnings = [sampleWarning]
|
2020-11-26 04:58:42 -05:00
|
|
|
const typesetting = [sampleTypesettingIssue]
|
2020-12-02 05:03:03 -05:00
|
|
|
const logEntries = {
|
|
|
|
all: [...errors, ...warnings, ...typesetting],
|
|
|
|
errors,
|
|
|
|
warnings,
|
2021-04-27 03:52:58 -04:00
|
|
|
typesetting,
|
2020-12-02 05:03:03 -05:00
|
|
|
}
|
2021-03-18 09:49:01 -04:00
|
|
|
const noOp = () => {}
|
2020-11-16 05:15:29 -05:00
|
|
|
const onLogEntryLocationClick = sinon.stub()
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('with logs', function () {
|
|
|
|
beforeEach(function () {
|
2021-03-18 09:49:01 -04:00
|
|
|
renderWithEditorContext(
|
|
|
|
<PreviewLogsPane
|
|
|
|
logEntries={logEntries}
|
|
|
|
rawLog={sampleRawLog}
|
|
|
|
onLogEntryLocationClick={onLogEntryLocationClick}
|
|
|
|
onClearCache={noOp}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
it('renders all log entries with appropriate labels', function () {
|
2021-03-18 09:49:01 -04:00
|
|
|
const errorEntries = screen.getAllByLabelText(
|
|
|
|
`Log entry with level: error`
|
|
|
|
)
|
|
|
|
const warningEntries = screen.getAllByLabelText(
|
|
|
|
`Log entry with level: warning`
|
|
|
|
)
|
|
|
|
const typesettingEntries = screen.getAllByLabelText(
|
|
|
|
`Log entry with level: typesetting`
|
|
|
|
)
|
|
|
|
expect(errorEntries).to.have.lengthOf(errors.length)
|
|
|
|
expect(warningEntries).to.have.lengthOf(warnings.length)
|
|
|
|
expect(typesettingEntries).to.have.lengthOf(typesetting.length)
|
|
|
|
})
|
2020-11-16 05:15:29 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('renders the raw log', function () {
|
2021-03-18 09:49:01 -04:00
|
|
|
screen.getByLabelText('Raw logs from the LaTeX compiler')
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('renders a link to location button for every error and warning log entry', function () {
|
2021-03-18 09:49:01 -04:00
|
|
|
logEntries.all.forEach((entry, index) => {
|
|
|
|
const linkToSourceButton = screen.getByRole('button', {
|
2021-04-27 03:52:58 -04:00
|
|
|
name: `Navigate to log position in source code: ${entry.file}, ${entry.line}`,
|
2020-12-02 05:03:03 -05:00
|
|
|
})
|
2021-03-18 09:49:01 -04:00
|
|
|
fireEvent.click(linkToSourceButton)
|
|
|
|
expect(onLogEntryLocationClick).to.have.callCount(index + 1)
|
|
|
|
const call = onLogEntryLocationClick.getCall(index)
|
|
|
|
expect(
|
|
|
|
call.calledWith({
|
|
|
|
file: entry.file,
|
|
|
|
line: entry.line,
|
2021-04-27 03:52:58 -04:00
|
|
|
column: entry.column,
|
2021-03-18 09:49:01 -04:00
|
|
|
})
|
|
|
|
).to.be.true
|
2020-12-02 05:03:03 -05:00
|
|
|
})
|
2020-11-26 04:58:42 -05:00
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
it(' does not render a link to location button for the raw log entry', function () {
|
2021-03-18 09:49:01 -04:00
|
|
|
const rawLogEntry = screen.getByLabelText(
|
|
|
|
'Raw logs from the LaTeX compiler'
|
|
|
|
)
|
|
|
|
expect(rawLogEntry.querySelector('.log-entry-header-link')).to.not.exist
|
|
|
|
})
|
|
|
|
})
|
2020-11-26 04:58:42 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('with validation issues', function () {
|
2020-11-26 04:58:42 -05:00
|
|
|
const sampleValidationIssues = {
|
|
|
|
sizeCheck: {
|
|
|
|
resources: [
|
|
|
|
{ path: 'foo/bar', kbSize: 76221 },
|
2021-04-27 03:52:58 -04:00
|
|
|
{ path: 'bar/baz', kbSize: 2342 },
|
|
|
|
],
|
2020-11-26 04:58:42 -05:00
|
|
|
},
|
2021-04-27 03:52:58 -04:00
|
|
|
mainFile: true,
|
2020-11-26 04:58:42 -05:00
|
|
|
}
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('renders a validation entry for known issues', function () {
|
2021-01-14 10:16:54 -05:00
|
|
|
renderWithEditorContext(
|
2020-11-26 04:58:42 -05:00
|
|
|
<PreviewLogsPane
|
|
|
|
validationIssues={sampleValidationIssues}
|
|
|
|
onLogEntryLocationClick={onLogEntryLocationClick}
|
2020-12-02 05:03:03 -05:00
|
|
|
onClearCache={noOp}
|
2020-11-26 04:58:42 -05:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
const validationEntries = screen.getAllByLabelText(
|
2020-12-02 05:03:03 -05:00
|
|
|
'A validation issue which prevented this project from compiling'
|
2020-11-26 04:58:42 -05:00
|
|
|
)
|
|
|
|
expect(validationEntries).to.have.lengthOf(
|
|
|
|
Object.keys(sampleValidationIssues).length
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('ignores unknown issues', function () {
|
2021-01-14 10:16:54 -05:00
|
|
|
renderWithEditorContext(
|
2020-11-26 04:58:42 -05:00
|
|
|
<PreviewLogsPane
|
|
|
|
validationIssues={{ unknownIssue: true }}
|
|
|
|
onLogEntryLocationClick={onLogEntryLocationClick}
|
2020-12-02 05:03:03 -05:00
|
|
|
onClearCache={noOp}
|
2020-11-26 04:58:42 -05:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
const validationEntries = screen.queryAllByLabelText(
|
2020-12-02 05:03:03 -05:00
|
|
|
'A validation issue prevented this project from compiling'
|
2020-11-26 04:58:42 -05:00
|
|
|
)
|
|
|
|
expect(validationEntries).to.have.lengthOf(0)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('with compilation errors', function () {
|
2020-11-26 04:58:42 -05:00
|
|
|
const sampleErrors = {
|
|
|
|
clsiMaintenance: true,
|
|
|
|
tooRecentlyCompiled: true,
|
2021-04-27 03:52:58 -04:00
|
|
|
compileTerminated: true,
|
2020-11-26 04:58:42 -05:00
|
|
|
}
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('renders an error entry for known errors', function () {
|
2021-01-14 10:16:54 -05:00
|
|
|
renderWithEditorContext(
|
2020-11-26 04:58:42 -05:00
|
|
|
<PreviewLogsPane
|
|
|
|
errors={sampleErrors}
|
|
|
|
onLogEntryLocationClick={onLogEntryLocationClick}
|
2020-12-02 05:03:03 -05:00
|
|
|
onClearCache={noOp}
|
2020-11-26 04:58:42 -05:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
const errorEntries = screen.getAllByLabelText(
|
2020-12-02 05:03:03 -05:00
|
|
|
'An error which prevented this project from compiling'
|
2020-11-26 04:58:42 -05:00
|
|
|
)
|
|
|
|
expect(errorEntries).to.have.lengthOf(Object.keys(sampleErrors).length)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('ignores unknown errors', function () {
|
2021-01-14 10:16:54 -05:00
|
|
|
renderWithEditorContext(
|
2020-11-26 04:58:42 -05:00
|
|
|
<PreviewLogsPane
|
|
|
|
errors={{ unknownIssue: true }}
|
|
|
|
onLogEntryLocationClick={onLogEntryLocationClick}
|
2020-12-02 05:03:03 -05:00
|
|
|
onClearCache={noOp}
|
2020-11-26 04:58:42 -05:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
const errorEntries = screen.queryAllByLabelText(
|
2020-12-02 05:03:03 -05:00
|
|
|
'There was an error compiling this project'
|
2020-11-26 04:58:42 -05:00
|
|
|
)
|
|
|
|
expect(errorEntries).to.have.lengthOf(0)
|
|
|
|
})
|
2020-11-16 05:15:29 -05:00
|
|
|
})
|
2021-03-18 09:49:01 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('with failing code check', function () {
|
|
|
|
beforeEach(function () {
|
2021-03-18 09:49:01 -04:00
|
|
|
renderWithEditorContext(
|
|
|
|
<PreviewLogsPane
|
|
|
|
logEntries={logEntries}
|
|
|
|
rawLog={sampleRawLog}
|
|
|
|
onLogEntryLocationClick={onLogEntryLocationClick}
|
|
|
|
onClearCache={noOp}
|
|
|
|
autoCompileHasLintingError
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
it('renders a code check failed entry', function () {
|
2021-03-18 09:49:01 -04:00
|
|
|
screen.getByText(
|
|
|
|
'Your code has errors that need to be fixed before the auto-compile can run'
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
2020-11-16 05:15:29 -05:00
|
|
|
})
|