Ensure that the TimeoutUpgradePrompt component returns null (#5482)

GitOrigin-RevId: 95e58537c82d9bedd055839cfb916a06c1ef96df
This commit is contained in:
Alf Eaton 2021-10-15 10:46:12 +01:00 committed by Copybot
parent 12eab99990
commit 09f3962ded
2 changed files with 33 additions and 12 deletions

View file

@ -11,7 +11,7 @@ function TimeoutUpgradePrompt() {
const { hasPremiumCompile, isProjectOwner } = useEditorContext() const { hasPremiumCompile, isProjectOwner } = useEditorContext()
if (!window.ExposedSettings.enableSubscriptions || hasPremiumCompile) { if (!window.ExposedSettings.enableSubscriptions || hasPremiumCompile) {
return return null
} }
return ( return (

View file

@ -1,7 +1,7 @@
import { expect } from 'chai' import { expect } from 'chai'
import sinon from 'sinon' import sinon from 'sinon'
import fetchMock from 'fetch-mock' import fetchMock from 'fetch-mock'
import { screen, fireEvent, waitFor } from '@testing-library/react' import { screen, fireEvent, waitFor, cleanup } from '@testing-library/react'
import PdfPreview from '../../../../../frontend/js/features/pdf-preview/components/pdf-preview' import PdfPreview from '../../../../../frontend/js/features/pdf-preview/components/pdf-preview'
import { renderWithEditorContext } from '../../../helpers/render-with-context' import { renderWithEditorContext } from '../../../helpers/render-with-context'
@ -255,7 +255,32 @@ describe('<PdfPreview/>', function () {
}) })
it('displays an error message if there was a compile error', async function () { it('displays an error message if there was a compile error', async function () {
mockCompileError('compile-in-progress') const compileErrorStatuses = {
'clear-cache':
'Sorry, something went wrong and your project could not be compiled. Please try again in a few moments.',
'clsi-maintenance':
'The compile servers are down for maintenance, and will be back shortly.',
'compile-in-progress':
'A previous compile is still running. Please wait a minute and try compiling again.',
exited: 'Server Error',
failure: 'No PDF',
generic: 'Server Error',
'project-too-large': 'Project too large',
'rate-limited': 'Compile rate limit hit',
terminated: 'Compilation cancelled',
timedout: 'Timed out',
'too-recently-compiled':
'This project was compiled very recently, so this compile has been skipped.',
unavailable:
'Sorry, the compile server for your project was temporarily unavailable. Please try again in a few moments.',
foo:
'Sorry, something went wrong and your project could not be compiled. Please try again in a few moments.',
}
for (const [status, message] of Object.entries(compileErrorStatuses)) {
cleanup()
fetchMock.restore()
mockCompileError(status)
renderWithEditorContext(<PdfPreview />, { scope }) renderWithEditorContext(<PdfPreview />, { scope })
@ -263,12 +288,8 @@ describe('<PdfPreview/>', function () {
await screen.findByRole('button', { name: 'Compiling…' }) await screen.findByRole('button', { name: 'Compiling…' })
await screen.findByRole('button', { name: 'Recompile' }) await screen.findByRole('button', { name: 'Recompile' })
screen.getByText( screen.getByText(message)
'Please wait for your other compile to finish before trying again.' }
)
expect(fetchMock.called('express:/project/:projectId/compile')).to.be.true // TODO: auto_compile query param
expect(fetchMock.called('express:/build/:file')).to.be.false // TODO: actual path
}) })
it('displays expandable raw logs', async function () { it('displays expandable raw logs', async function () {