2020-11-16 05:01:01 -05:00
|
|
|
import { screen, render, fireEvent } from '@testing-library/react'
|
|
|
|
import PreviewPane from '../../../../../frontend/js/features/preview/components/preview-pane'
|
|
|
|
const { expect } = require('chai')
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('<PreviewPane />', function () {
|
2020-11-16 05:01:01 -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:01:01 -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:01:01 -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:01:01 -05:00
|
|
|
}
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('first error pop-up', function () {
|
|
|
|
it('renders a first error pop-up with the first error', function () {
|
2020-11-16 05:01:01 -05:00
|
|
|
const propsAfterCompileWithErrors = getProps(false, {
|
|
|
|
errors: [sampleError1, sampleError2],
|
2021-04-27 03:52:58 -04:00
|
|
|
warnings: [sampleWarning],
|
2020-11-16 05:01:01 -05:00
|
|
|
})
|
|
|
|
render(<PreviewPane {...propsAfterCompileWithErrors} />)
|
|
|
|
screen.getByRole('alertdialog', {
|
2021-04-27 03:52:58 -04:00
|
|
|
name: 'This project has errors. This is the first one.',
|
2020-11-16 05:01:01 -05:00
|
|
|
})
|
|
|
|
screen.getByText(sampleError1.message)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('does not render a first error pop-up when there are only warnings', function () {
|
2020-11-16 05:01:01 -05:00
|
|
|
const propsAfterCompileWithWarningsOnly = getProps(false, {
|
|
|
|
errors: [],
|
2021-04-27 03:52:58 -04:00
|
|
|
warnings: [sampleWarning],
|
2020-11-16 05:01:01 -05:00
|
|
|
})
|
|
|
|
render(<PreviewPane {...propsAfterCompileWithWarningsOnly} />)
|
|
|
|
expect(
|
|
|
|
screen.queryByRole('alertdialog', {
|
2021-04-27 03:52:58 -04:00
|
|
|
name: 'This project has errors. This is the first one.',
|
2020-11-16 05:01:01 -05:00
|
|
|
})
|
|
|
|
).to.not.exist
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('does not render a first error pop-up when a compile is ongoing', function () {
|
2020-11-16 05:01:01 -05:00
|
|
|
const propsWhileCompiling = getProps(true, {
|
|
|
|
errors: [sampleError1, sampleError2],
|
2021-04-27 03:52:58 -04:00
|
|
|
warnings: [sampleWarning],
|
2020-11-16 05:01:01 -05:00
|
|
|
})
|
|
|
|
render(<PreviewPane {...propsWhileCompiling} />)
|
|
|
|
expect(
|
|
|
|
screen.queryByRole('alertdialog', {
|
2021-04-27 03:52:58 -04:00
|
|
|
name: 'This project has errors. This is the first one.',
|
2020-11-16 05:01:01 -05:00
|
|
|
})
|
|
|
|
).to.not.exist
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('does not render a first error pop-up when viewing logs', function () {
|
2020-11-16 05:01:01 -05:00
|
|
|
const propsWithErrorsViewingLogs = getProps(
|
|
|
|
false,
|
|
|
|
{
|
|
|
|
errors: [sampleError1, sampleError2],
|
2021-04-27 03:52:58 -04:00
|
|
|
warnings: [sampleWarning],
|
2020-11-16 05:01:01 -05:00
|
|
|
},
|
|
|
|
Date.now(),
|
|
|
|
true
|
|
|
|
)
|
|
|
|
render(<PreviewPane {...propsWithErrorsViewingLogs} />)
|
|
|
|
expect(
|
|
|
|
screen.queryByRole('alertdialog', {
|
2021-04-27 03:52:58 -04:00
|
|
|
name: 'This project has errors. This is the first one.',
|
2020-11-16 05:01:01 -05:00
|
|
|
})
|
|
|
|
).to.not.exist
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('does not render a first error pop-up when going back to the PDF view after viewing logs', function () {
|
2020-11-16 05:01:01 -05:00
|
|
|
const nowTimestamp = Date.now()
|
|
|
|
const propsWithErrorsViewingLogs = getProps(
|
|
|
|
false,
|
|
|
|
{
|
|
|
|
errors: [sampleError1, sampleError2],
|
2021-04-27 03:52:58 -04:00
|
|
|
warnings: [sampleWarning],
|
2020-11-16 05:01:01 -05:00
|
|
|
},
|
|
|
|
nowTimestamp,
|
|
|
|
true
|
|
|
|
)
|
|
|
|
const propsWithErrorsAfterViewingLogs = getProps(
|
|
|
|
false,
|
|
|
|
{
|
|
|
|
errors: [sampleError1, sampleError2],
|
2021-04-27 03:52:58 -04:00
|
|
|
warnings: [sampleWarning],
|
2020-11-16 05:01:01 -05:00
|
|
|
},
|
|
|
|
nowTimestamp,
|
|
|
|
false
|
|
|
|
)
|
|
|
|
const { rerender } = render(
|
|
|
|
<PreviewPane {...propsWithErrorsViewingLogs} />
|
|
|
|
)
|
|
|
|
rerender(<PreviewPane {...propsWithErrorsAfterViewingLogs} />)
|
|
|
|
expect(
|
|
|
|
screen.queryByRole('alertdialog', {
|
2021-04-27 03:52:58 -04:00
|
|
|
name: 'This project has errors. This is the first one.',
|
2020-11-16 05:01:01 -05:00
|
|
|
})
|
|
|
|
).to.not.exist
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('renders a first error pop-up with updated errors after recompiling', function () {
|
2020-11-16 05:01:01 -05:00
|
|
|
const nowTimestamp = Date.now()
|
|
|
|
const laterTimestamp = Date.now() + 1000
|
|
|
|
const propsWithErrorsAfterFirstCompile = getProps(
|
|
|
|
false,
|
|
|
|
{
|
|
|
|
errors: [sampleError1, sampleError2],
|
2021-04-27 03:52:58 -04:00
|
|
|
warnings: [sampleWarning],
|
2020-11-16 05:01:01 -05:00
|
|
|
},
|
|
|
|
nowTimestamp,
|
|
|
|
true
|
|
|
|
)
|
|
|
|
const propsWithErrorsAfterSecondCompile = getProps(
|
|
|
|
false,
|
|
|
|
{
|
|
|
|
errors: [sampleError2],
|
2021-04-27 03:52:58 -04:00
|
|
|
warnings: [sampleWarning],
|
2020-11-16 05:01:01 -05:00
|
|
|
},
|
|
|
|
laterTimestamp,
|
|
|
|
false
|
|
|
|
)
|
|
|
|
const { rerender } = render(
|
|
|
|
<PreviewPane {...propsWithErrorsAfterFirstCompile} />
|
|
|
|
)
|
|
|
|
rerender(<PreviewPane {...propsWithErrorsAfterSecondCompile} />)
|
|
|
|
screen.getByRole('alertdialog', {
|
2021-04-27 03:52:58 -04:00
|
|
|
name: 'This project has errors. This is the first one.',
|
2020-11-16 05:01:01 -05:00
|
|
|
})
|
|
|
|
screen.getByText(sampleError2.message)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('allows dismissing the first error pop-up', function () {
|
2020-11-16 05:01:01 -05:00
|
|
|
const propsWithErrors = getProps(false, {
|
|
|
|
errors: [sampleError1, sampleError2],
|
2021-04-27 03:52:58 -04:00
|
|
|
warnings: [sampleWarning],
|
2020-11-16 05:01:01 -05:00
|
|
|
})
|
|
|
|
render(<PreviewPane {...propsWithErrors} />)
|
|
|
|
const dismissPopUpButton = screen.getByRole('button', {
|
2021-04-27 03:52:58 -04:00
|
|
|
name: 'Dismiss first error alert',
|
2020-11-16 05:01:01 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
fireEvent.click(dismissPopUpButton)
|
|
|
|
expect(
|
|
|
|
screen.queryByRole('alertdialog', {
|
2021-04-27 03:52:58 -04:00
|
|
|
name: 'This project has errors. This is the first one.',
|
2020-11-16 05:01:01 -05:00
|
|
|
})
|
|
|
|
).to.not.exist
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('does not render the first error pop-up with new recompiles after it being dismissed once', function () {
|
2020-11-16 05:01:01 -05:00
|
|
|
const nowTimestamp = Date.now()
|
|
|
|
const laterTimestamp = Date.now() + 1000
|
|
|
|
const propsWithErrorsForFirstCompile = getProps(
|
|
|
|
false,
|
|
|
|
{
|
|
|
|
errors: [sampleError1, sampleError2],
|
2021-04-27 03:52:58 -04:00
|
|
|
warnings: [sampleWarning],
|
2020-11-16 05:01:01 -05:00
|
|
|
},
|
|
|
|
nowTimestamp
|
|
|
|
)
|
|
|
|
const propsWithErrorsForSecondCompile = getProps(
|
|
|
|
false,
|
|
|
|
{
|
|
|
|
errors: [sampleError2],
|
2021-04-27 03:52:58 -04:00
|
|
|
warnings: [sampleWarning],
|
2020-11-16 05:01:01 -05:00
|
|
|
},
|
|
|
|
laterTimestamp
|
|
|
|
)
|
|
|
|
const { rerender } = render(
|
|
|
|
<PreviewPane {...propsWithErrorsForFirstCompile} />
|
|
|
|
)
|
|
|
|
const dismissPopUpButton = screen.getByRole('button', {
|
2021-04-27 03:52:58 -04:00
|
|
|
name: 'Dismiss first error alert',
|
2020-11-16 05:01:01 -05:00
|
|
|
})
|
|
|
|
fireEvent.click(dismissPopUpButton)
|
|
|
|
rerender(<PreviewPane {...propsWithErrorsForSecondCompile} />)
|
|
|
|
expect(
|
|
|
|
screen.queryByRole('alertdialog', {
|
2021-04-27 03:52:58 -04:00
|
|
|
name: 'This project has errors. This is the first one.',
|
2020-11-16 05:01:01 -05:00
|
|
|
})
|
|
|
|
).to.not.exist
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('accessible description of the compile result', function () {
|
|
|
|
it('renders an accessible description with the errors and warnings count', function () {
|
2020-11-26 04:58:42 -05:00
|
|
|
const errors = [sampleError1, sampleError2]
|
|
|
|
const warnings = [sampleWarning]
|
|
|
|
const propsWithErrorsAndWarnings = getProps(false, {
|
|
|
|
errors,
|
2021-04-27 03:52:58 -04:00
|
|
|
warnings,
|
2020-11-26 04:58:42 -05:00
|
|
|
})
|
|
|
|
render(<PreviewPane {...propsWithErrorsAndWarnings} />)
|
|
|
|
|
|
|
|
screen.getByText(`${errors.length} error${errors.length > 1 ? 's' : ''}`)
|
|
|
|
screen.getByText(
|
|
|
|
`${warnings.length} warning${warnings.length > 1 ? 's' : ''}`
|
|
|
|
)
|
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
it('renders an accessible description for failed compiles with CLSI errors', function () {
|
2020-11-26 04:58:42 -05:00
|
|
|
const sampleCLSIError = {
|
2021-04-27 03:52:58 -04:00
|
|
|
clsiMaintenance: true,
|
2020-11-26 04:58:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
const propsWithCLSIError = getProps(
|
|
|
|
false,
|
|
|
|
{},
|
|
|
|
Date.now(),
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
{},
|
|
|
|
sampleCLSIError
|
|
|
|
)
|
|
|
|
render(<PreviewPane {...propsWithCLSIError} />)
|
|
|
|
|
2020-12-02 05:03:03 -05:00
|
|
|
screen.getByText('This project did not compile because of an error')
|
2020-11-26 04:58:42 -05:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('renders an accessible description for failed compiles with validation issues', function () {
|
2020-11-26 04:58:42 -05:00
|
|
|
const sampleValidationIssue = {
|
2021-04-27 03:52:58 -04:00
|
|
|
clsiMaintenance: true,
|
2020-11-26 04:58:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
const propsWithValidationIssue = getProps(
|
|
|
|
false,
|
|
|
|
{},
|
|
|
|
Date.now(),
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
sampleValidationIssue,
|
|
|
|
{}
|
|
|
|
)
|
|
|
|
render(<PreviewPane {...propsWithValidationIssue} />)
|
|
|
|
|
|
|
|
screen.getByText(
|
2020-12-02 05:03:03 -05:00
|
|
|
'This project did not compile because of a validation issue'
|
2020-11-26 04:58:42 -05:00
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-11-16 05:01:01 -05:00
|
|
|
function getProps(
|
|
|
|
isCompiling = false,
|
|
|
|
logEntries = {},
|
|
|
|
lastCompileTimestamp = Date.now(),
|
2020-11-26 04:58:42 -05:00
|
|
|
isShowingLogs = false,
|
|
|
|
compileFailed = false,
|
|
|
|
validationIssues = {},
|
|
|
|
errors = {}
|
2020-11-16 05:01:01 -05:00
|
|
|
) {
|
2020-12-02 05:03:03 -05:00
|
|
|
const logEntriesWithDefaults = {
|
|
|
|
errors: [],
|
|
|
|
warnings: [],
|
|
|
|
typesetting: [],
|
2021-04-27 03:52:58 -04:00
|
|
|
...logEntries,
|
2020-12-02 05:03:03 -05:00
|
|
|
}
|
|
|
|
logEntriesWithDefaults.all = [
|
|
|
|
...logEntriesWithDefaults.errors,
|
|
|
|
...logEntriesWithDefaults.warnings,
|
2021-04-27 03:52:58 -04:00
|
|
|
...logEntriesWithDefaults.typesetting,
|
2020-12-02 05:03:03 -05:00
|
|
|
]
|
2020-11-16 05:01:01 -05:00
|
|
|
return {
|
|
|
|
compilerState: {
|
2021-03-18 09:49:01 -04:00
|
|
|
autoCompileHasChanges: false,
|
2020-11-16 05:01:01 -05:00
|
|
|
isAutoCompileOn: false,
|
|
|
|
isCompiling: isCompiling,
|
|
|
|
isClearingCache: false,
|
|
|
|
isDraftModeOn: false,
|
|
|
|
isSyntaxCheckOn: false,
|
2020-11-26 04:58:42 -05:00
|
|
|
lastCompileTimestamp,
|
2020-12-02 05:03:03 -05:00
|
|
|
logEntries: logEntriesWithDefaults,
|
2020-11-26 04:58:42 -05:00
|
|
|
compileFailed,
|
|
|
|
validationIssues,
|
2021-04-27 03:52:58 -04:00
|
|
|
errors,
|
2020-11-16 05:01:01 -05:00
|
|
|
},
|
|
|
|
onClearCache: () => {},
|
|
|
|
onLogEntryLocationClick: () => {},
|
|
|
|
onRecompile: () => {},
|
2020-12-02 05:03:03 -05:00
|
|
|
onRecompileFromScratch: () => {},
|
2020-11-16 05:01:01 -05:00
|
|
|
onRunSyntaxCheckNow: () => {},
|
|
|
|
onSetAutoCompile: () => {},
|
|
|
|
onSetDraftMode: () => {},
|
|
|
|
onSetSyntaxCheck: () => {},
|
|
|
|
onToggleLogs: () => {},
|
2020-12-02 05:03:03 -05:00
|
|
|
onSetSplitLayout: () => {},
|
|
|
|
onSetFullLayout: () => {},
|
|
|
|
onStopCompilation: () => {},
|
|
|
|
showLogs: isShowingLogs,
|
2021-04-27 03:52:58 -04:00
|
|
|
splitLayout: true,
|
2020-11-16 05:01:01 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|