2020-11-05 05:22:05 -05:00
|
|
|
import React from 'react'
|
|
|
|
import { expect } from 'chai'
|
|
|
|
import sinon from 'sinon'
|
|
|
|
import { screen, render, fireEvent } from '@testing-library/react'
|
|
|
|
|
2020-11-26 04:58:42 -05:00
|
|
|
import PreviewLogsPaneEntry from '../../../../../frontend/js/features/preview/components/preview-logs-pane-entry.js'
|
2020-11-05 05:22:05 -05:00
|
|
|
|
2020-11-26 04:58:42 -05:00
|
|
|
describe('<PreviewLogsPaneEntry />', function() {
|
2020-11-05 05:22:05 -05:00
|
|
|
const level = 'error'
|
|
|
|
|
2020-11-26 04:58:42 -05:00
|
|
|
it('renders a configurable aria-label', function() {
|
|
|
|
const sampleAriaLabel = 'lorem ipsum dolor sit amet'
|
|
|
|
render(
|
|
|
|
<PreviewLogsPaneEntry entryAriaLabel={sampleAriaLabel} level={level} />
|
|
|
|
)
|
|
|
|
screen.getByLabelText(sampleAriaLabel)
|
2020-11-05 05:22:05 -05:00
|
|
|
})
|
|
|
|
|
2020-11-26 04:58:42 -05:00
|
|
|
describe('logs pane source location link', function() {
|
2020-11-05 05:22:05 -05:00
|
|
|
const file = 'foo.tex'
|
|
|
|
const line = 42
|
|
|
|
const column = 21
|
2020-11-26 04:58:42 -05:00
|
|
|
const onSourceLocationClick = sinon.stub()
|
2020-11-05 05:22:05 -05:00
|
|
|
|
|
|
|
afterEach(function() {
|
2020-11-26 04:58:42 -05:00
|
|
|
onSourceLocationClick.reset()
|
2020-11-05 05:22:05 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('renders both file and line', function() {
|
2020-11-26 04:58:42 -05:00
|
|
|
render(
|
|
|
|
<PreviewLogsPaneEntry sourceLocation={{ file, line }} level={level} />
|
|
|
|
)
|
2020-11-05 05:22:05 -05:00
|
|
|
screen.getByRole('button', {
|
|
|
|
name: `Navigate to log position in source code: ${file}, ${line}`
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('renders only file when line information is not available', function() {
|
2020-11-26 04:58:42 -05:00
|
|
|
render(<PreviewLogsPaneEntry sourceLocation={{ file }} level={level} />)
|
2020-11-05 05:22:05 -05:00
|
|
|
screen.getByRole('button', {
|
|
|
|
name: `Navigate to log position in source code: ${file}`
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('does not render when file information is not available', function() {
|
2020-11-26 04:58:42 -05:00
|
|
|
render(<PreviewLogsPaneEntry level={level} />)
|
2020-11-05 05:22:05 -05:00
|
|
|
expect(
|
|
|
|
screen.queryByRole('button', {
|
|
|
|
name: `Navigate to log position in source code: `
|
|
|
|
})
|
|
|
|
).to.not.exist
|
|
|
|
})
|
|
|
|
|
|
|
|
it('calls the callback with file, line and column on click', function() {
|
|
|
|
render(
|
2020-11-26 04:58:42 -05:00
|
|
|
<PreviewLogsPaneEntry
|
|
|
|
sourceLocation={{ file, line, column }}
|
2020-11-05 05:22:05 -05:00
|
|
|
level={level}
|
2020-11-26 04:58:42 -05:00
|
|
|
onSourceLocationClick={onSourceLocationClick}
|
2020-11-05 05:22:05 -05:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
const linkToSourceButton = screen.getByRole('button', {
|
|
|
|
name: `Navigate to log position in source code: ${file}, ${line}`
|
|
|
|
})
|
|
|
|
|
|
|
|
fireEvent.click(linkToSourceButton)
|
2020-11-26 04:58:42 -05:00
|
|
|
expect(onSourceLocationClick).to.be.calledOnce
|
|
|
|
expect(onSourceLocationClick).to.be.calledWith({
|
2020-11-05 05:22:05 -05:00
|
|
|
file,
|
2020-11-26 04:58:42 -05:00
|
|
|
line,
|
|
|
|
column
|
2020-11-05 05:22:05 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-11-26 04:58:42 -05:00
|
|
|
describe('logs pane entry raw contents', function() {
|
|
|
|
const rawContent = 'foo bar latex error stuff baz'
|
2020-11-05 05:22:05 -05:00
|
|
|
|
|
|
|
it('renders collapsed contents by default', function() {
|
2020-11-26 04:58:42 -05:00
|
|
|
render(<PreviewLogsPaneEntry rawContent={rawContent} level={level} />)
|
|
|
|
screen.getByText(rawContent)
|
2020-11-05 05:22:05 -05:00
|
|
|
screen.getByRole('button', {
|
|
|
|
name: 'Expand'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('supports expanding contents', function() {
|
2020-11-26 04:58:42 -05:00
|
|
|
render(<PreviewLogsPaneEntry rawContent={rawContent} level={level} />)
|
|
|
|
screen.getByText(rawContent)
|
2020-11-05 05:22:05 -05:00
|
|
|
const expandCollapseBtn = screen.getByRole('button', {
|
|
|
|
name: 'Expand'
|
|
|
|
})
|
|
|
|
fireEvent.click(expandCollapseBtn)
|
|
|
|
screen.getByRole('button', {
|
|
|
|
name: 'Collapse'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should not render at all when there are no log contents', function() {
|
2020-11-26 04:58:42 -05:00
|
|
|
const { container } = render(<PreviewLogsPaneEntry level={level} />)
|
2020-11-05 05:22:05 -05:00
|
|
|
expect(container.querySelector('.log-entry-content')).to.not.exist
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-11-26 04:58:42 -05:00
|
|
|
describe('formatted content', function() {
|
|
|
|
const rawContent = 'foo bar latex error stuff baz'
|
|
|
|
const formattedContentText = 'foo bar baz'
|
|
|
|
const formattedContent = <>{formattedContentText}</>
|
2020-11-05 05:22:05 -05:00
|
|
|
const infoURL = 'www.overleaf.com/learn/latex'
|
|
|
|
|
|
|
|
it('renders the hint', function() {
|
|
|
|
render(
|
2020-11-26 04:58:42 -05:00
|
|
|
<PreviewLogsPaneEntry
|
|
|
|
rawContent={rawContent}
|
|
|
|
formattedContent={formattedContent}
|
2020-11-05 05:22:05 -05:00
|
|
|
extraInfoURL={infoURL}
|
|
|
|
level={level}
|
|
|
|
/>
|
|
|
|
)
|
2020-11-26 04:58:42 -05:00
|
|
|
screen.getByText(formattedContentText)
|
2020-11-05 05:22:05 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('renders the link to learn more', function() {
|
|
|
|
render(
|
2020-11-26 04:58:42 -05:00
|
|
|
<PreviewLogsPaneEntry
|
|
|
|
rawContent={rawContent}
|
|
|
|
formattedContent={formattedContent}
|
2020-11-05 05:22:05 -05:00
|
|
|
extraInfoURL={infoURL}
|
|
|
|
level={level}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
screen.getByRole('link', { name: 'Learn more' })
|
|
|
|
})
|
|
|
|
|
|
|
|
it('does not render the link when it is not available', function() {
|
|
|
|
render(
|
2020-11-26 04:58:42 -05:00
|
|
|
<PreviewLogsPaneEntry
|
|
|
|
rawContent={rawContent}
|
|
|
|
formattedContent={formattedContent}
|
2020-11-05 05:22:05 -05:00
|
|
|
level={level}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
expect(screen.queryByRole('link', { name: 'Learn more' })).to.not.exist
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|