2020-09-29 07:08:49 -04:00
|
|
|
import React from 'react'
|
2020-11-09 09:52:22 -05:00
|
|
|
import { expect } from 'chai'
|
2020-09-29 07:08:49 -04:00
|
|
|
import { screen, render } from '@testing-library/react'
|
|
|
|
|
|
|
|
import PreviewLogsToggleButton from '../../../../../frontend/js/features/preview/components/preview-logs-toggle-button'
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('<PreviewLogsToggleButton />', function () {
|
2020-11-09 09:52:22 -05:00
|
|
|
function renderPreviewLogsToggleButton(
|
|
|
|
logsState,
|
|
|
|
onToggleLogs,
|
|
|
|
showLogs,
|
2021-03-18 09:49:01 -04:00
|
|
|
showText = false,
|
|
|
|
autoCompileLintingError = false,
|
|
|
|
compileFailed = false
|
2020-11-09 09:52:22 -05:00
|
|
|
) {
|
|
|
|
render(
|
|
|
|
<PreviewLogsToggleButton
|
|
|
|
logsState={logsState}
|
|
|
|
onToggle={onToggleLogs}
|
|
|
|
showLogs={showLogs}
|
|
|
|
showText={showText}
|
2021-03-18 09:49:01 -04:00
|
|
|
autoCompileLintingError={autoCompileLintingError}
|
|
|
|
compileFailed={compileFailed}
|
2020-11-09 09:52:22 -05:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('basic toggle functionality', function () {
|
2020-09-29 07:08:49 -04:00
|
|
|
const logsState = {
|
|
|
|
nErrors: 0,
|
2021-03-18 09:49:01 -04:00
|
|
|
nWarnings: 0
|
2020-09-29 07:08:49 -04:00
|
|
|
}
|
|
|
|
const onToggleLogs = () => {}
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should render a view logs button when previewing the PDF', function () {
|
2020-09-29 07:08:49 -04:00
|
|
|
const showLogs = false
|
2020-11-09 09:52:22 -05:00
|
|
|
renderPreviewLogsToggleButton(logsState, onToggleLogs, showLogs)
|
2020-10-07 06:50:03 -04:00
|
|
|
screen.getByText('View logs')
|
2020-09-29 07:08:49 -04:00
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should render a view PDF button when viewing logs', function () {
|
2020-09-29 07:08:49 -04:00
|
|
|
const showLogs = true
|
2020-11-09 09:52:22 -05:00
|
|
|
renderPreviewLogsToggleButton(logsState, onToggleLogs, showLogs)
|
2020-10-07 06:50:03 -04:00
|
|
|
screen.getByText('View PDF')
|
2020-09-29 07:08:49 -04:00
|
|
|
})
|
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('compile status indicator', function () {
|
2020-09-29 07:08:49 -04:00
|
|
|
const showLogs = false
|
|
|
|
const onToggleLogs = () => {}
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should render a view logs button by default', function () {
|
2020-09-29 07:08:49 -04:00
|
|
|
const logsState = {
|
|
|
|
nErrors: 0,
|
2021-03-18 09:49:01 -04:00
|
|
|
nWarnings: 0
|
2020-09-29 07:08:49 -04:00
|
|
|
}
|
2020-11-09 09:52:22 -05:00
|
|
|
renderPreviewLogsToggleButton(logsState, onToggleLogs, showLogs)
|
2020-10-07 06:50:03 -04:00
|
|
|
screen.getByText('View logs')
|
2020-09-29 07:08:49 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should render the code check failed notice', function () {
|
2021-03-18 09:49:01 -04:00
|
|
|
const logsState = {
|
|
|
|
nErrors: 1,
|
|
|
|
nWarnings: 0
|
|
|
|
}
|
|
|
|
renderPreviewLogsToggleButton(
|
|
|
|
logsState,
|
|
|
|
onToggleLogs,
|
|
|
|
showLogs,
|
|
|
|
false,
|
|
|
|
true
|
|
|
|
)
|
|
|
|
screen.getByText('Code check failed')
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should render an error status message when there are errors', function () {
|
2020-09-29 07:08:49 -04:00
|
|
|
const logsState = {
|
|
|
|
nErrors: 1,
|
2021-03-18 09:49:01 -04:00
|
|
|
nWarnings: 0
|
2020-09-29 07:08:49 -04:00
|
|
|
}
|
2020-11-09 09:52:22 -05:00
|
|
|
renderPreviewLogsToggleButton(logsState, onToggleLogs, showLogs)
|
2020-12-02 05:03:03 -05:00
|
|
|
screen.getByText(`This project has errors (${logsState.nErrors})`)
|
2020-09-29 07:08:49 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should render an error status message when there are both errors and warnings', function () {
|
2020-09-29 07:08:49 -04:00
|
|
|
const logsState = {
|
|
|
|
nErrors: 1,
|
2021-03-18 09:49:01 -04:00
|
|
|
nWarnings: 1
|
2020-09-29 07:08:49 -04:00
|
|
|
}
|
2020-11-09 09:52:22 -05:00
|
|
|
renderPreviewLogsToggleButton(logsState, onToggleLogs, showLogs)
|
2020-12-02 05:03:03 -05:00
|
|
|
screen.getByText(`This project has errors (${logsState.nErrors})`)
|
2020-09-29 07:08:49 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should render a warning status message when there are warnings but no errors', function () {
|
2020-09-29 07:08:49 -04:00
|
|
|
const logsState = {
|
|
|
|
nErrors: 0,
|
2021-03-18 09:49:01 -04:00
|
|
|
nWarnings: 1
|
2020-09-29 07:08:49 -04:00
|
|
|
}
|
2020-11-09 09:52:22 -05:00
|
|
|
renderPreviewLogsToggleButton(logsState, onToggleLogs, showLogs)
|
2020-10-07 06:50:03 -04:00
|
|
|
screen.getByText(`View warnings (${logsState.nWarnings})`)
|
2020-09-29 07:08:49 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should render 99+ errors when there are more than 99 errors', function () {
|
2020-09-29 07:08:49 -04:00
|
|
|
const logsState = {
|
2021-02-17 09:07:21 -05:00
|
|
|
nErrors: 100,
|
2021-03-18 09:49:01 -04:00
|
|
|
nWarnings: 0
|
2020-09-29 07:08:49 -04:00
|
|
|
}
|
2020-11-09 09:52:22 -05:00
|
|
|
renderPreviewLogsToggleButton(logsState, onToggleLogs, showLogs)
|
2021-02-17 09:07:21 -05:00
|
|
|
screen.getByText('This project has errors (99+)')
|
2020-09-29 07:08:49 -04:00
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should show the button text when prop showText=true', function () {
|
2020-11-09 09:52:22 -05:00
|
|
|
const logsState = {
|
|
|
|
nErrors: 0,
|
2021-03-18 09:49:01 -04:00
|
|
|
nWarnings: 0
|
2020-11-09 09:52:22 -05:00
|
|
|
}
|
|
|
|
const showText = true
|
|
|
|
renderPreviewLogsToggleButton(logsState, onToggleLogs, showLogs, showText)
|
|
|
|
expect(screen.getByText('View logs').getAttribute('style')).to.be.null
|
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should not show the button text when prop showText=false', function () {
|
2020-11-09 09:52:22 -05:00
|
|
|
const logsState = {
|
|
|
|
nErrors: 0,
|
2021-03-18 09:49:01 -04:00
|
|
|
nWarnings: 0
|
2020-11-09 09:52:22 -05:00
|
|
|
}
|
|
|
|
const showText = false
|
|
|
|
renderPreviewLogsToggleButton(logsState, onToggleLogs, showLogs, showText)
|
|
|
|
expect(screen.getByText('View logs').getAttribute('style')).to.equal(
|
|
|
|
'position: absolute; right: -100vw;'
|
|
|
|
)
|
|
|
|
})
|
2020-09-29 07:08:49 -04:00
|
|
|
})
|
|
|
|
})
|