| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- import {
- createNewFile,
- createProjectAndOpenInNewEditor,
- openProjectById,
- testNewFileUpload,
- } from './helpers/project'
- import { isExcludedBySharding, startWith } from './helpers/config'
- import { ensureUserExists, login } from './helpers/login'
- import { v4 as uuid } from 'uuid'
- import { beforeWithReRunOnTestRetry } from './helpers/beforeWithReRunOnTestRetry'
- import { prepareWaitForNextCompileSlot } from './helpers/compile'
- const USER = 'user@example.com'
- const COLLABORATOR = 'collaborator@example.com'
- describe('editor', function () {
- if (isExcludedBySharding('PRO_DEFAULT_1')) return
- startWith({ pro: true })
- ensureUserExists({ email: USER })
- ensureUserExists({ email: COLLABORATOR })
- let projectName: string
- let projectId: string
- let recompile: () => void
- let waitForCompile: (fn: () => void) => void
- beforeWithReRunOnTestRetry(() => {
- projectName = `project-${uuid()}`
- login(USER)
- createProjectAndOpenInNewEditor(projectName, {
- type: 'Example project',
- }).then(id => (projectId = id))
- ;({ recompile, waitForCompile } = prepareWaitForNextCompileSlot())
- })
- beforeEach(function () {
- login(USER)
- waitForCompile(() => {
- openProjectById(projectId, true)
- })
- })
- describe('spelling', function () {
- function changeSpellCheckLanguageTo(lng: string) {
- cy.log(`change project language to '${lng}'`)
- cy.findByRole('button', { name: 'Settings' }).click()
- cy.findByRole('dialog').within(() => {
- cy.findByLabelText('Spellcheck language').select(lng)
- })
- cy.get('body').type('{esc}')
- }
- afterEach(function () {
- changeSpellCheckLanguageTo('Off')
- })
- it('word dictionary and spelling', function () {
- changeSpellCheckLanguageTo('English (American)')
- createNewFile()
- const word = createRandomLetterString()
- cy.log('edit project file')
- cy.get('.cm-line').type(word)
- cy.findByText(word).should('have.class', 'ol-cm-spelling-error')
- changeSpellCheckLanguageTo('Off')
- cy.findByText(word).should('not.have.class', 'ol-cm-spelling-error')
- changeSpellCheckLanguageTo('Spanish')
- cy.findByText(word).should('have.class', 'ol-cm-spelling-error')
- cy.log('add word to dictionary')
- cy.findByText(word).rightclick()
- cy.findByRole('menuitem', { name: 'Add to dictionary' }).click()
- cy.findByText(word).should('not.have.class', 'ol-cm-spelling-error')
- cy.log('remove word from dictionary')
- cy.findByRole('button', { name: 'Settings' }).click()
- cy.findByRole('dialog').within(() => {
- cy.findByLabelText('Dictionary').click()
- })
- cy.findByTestId('dictionary-modal').within(() => {
- cy.findByText(word)
- .parent()
- .within(() =>
- cy.findByRole('button', { name: 'Remove from dictionary' }).click()
- )
- cy.findByRole('button', { name: 'Close dialog' }).click()
- })
- cy.log('close modal')
- cy.get('body').type('{esc}')
- cy.log('rewrite word to force spelling error')
- cy.get('.cm-line').type('{selectAll}{del}' + word + '{enter}')
- cy.get('.ol-cm-spelling-error').should('contain.text', word)
- })
- })
- describe('editor', function () {
- it('renders jpg', function () {
- cy.findByRole('treeitem', { name: 'frog.jpg' }).click({ force: true })
- cy.get('[alt="frog.jpg"]')
- .should('be.visible')
- .and('have.prop', 'naturalWidth')
- .should('be.greaterThan', 0)
- })
- it('symbol palette', function () {
- createNewFile()
- cy.get('button[aria-label="Insert symbol"]').click({
- force: true,
- })
- cy.get('button').contains('𝜉').click()
- cy.findByRole('textbox', { name: 'Source Editor editing' }).should(
- 'contain.text',
- '\\xi'
- )
- cy.log('recompile to force flush and avoid "unsaved changes" prompt')
- recompile()
- })
- })
- describe('add new file to project', function () {
- beforeEach(function () {
- cy.findByRole('button', { name: 'New file' }).click()
- })
- testNewFileUpload()
- it('should not display import from URL', function () {
- cy.findByRole('button', { name: 'From external URL' }).should('not.exist')
- })
- })
- describe('file menu', function () {
- it('can download project sources', function () {
- cy.findByRole('button', { name: 'File' }).click()
- cy.findByRole('menuitem', { name: 'Download as source (.zip)' }).click()
- const zipName = projectName.replaceAll('-', '_')
- cy.task('readFileInZip', {
- pathToZip: `cypress/downloads/${zipName}.zip`,
- fileToRead: 'main.tex',
- }).should('contain', 'Your introduction goes here')
- })
- it('can download project PDF', function () {
- cy.log('ensure project is compiled')
- cy.findByRole('region', { name: 'PDF preview' }).should(
- 'contain.text',
- 'Your Paper'
- )
- cy.findByRole('button', { name: 'File' }).click()
- cy.findByRole('menuitem', { name: 'Download as PDF' }).click()
- const pdfName = projectName.replaceAll('-', '_')
- cy.task('readPdf', `cypress/downloads/${pdfName}.pdf`).should(
- 'contain',
- 'Your introduction goes here'
- )
- })
- it('word count', function () {
- cy.log('ensure project is compiled')
- cy.findByRole('region', { name: 'PDF preview' }).should(
- 'contain.text',
- 'Your Paper'
- )
- cy.findByRole('button', { name: 'File' }).click()
- cy.findByRole('menuitem', { name: 'Word count' }).click()
- cy.findByTestId('word-count-modal').within(() => {
- cy.findByText('Total Words:')
- cy.findByText('607')
- cy.findByText('Headers:')
- cy.findByText('14')
- cy.findByText('Math Inline:')
- cy.findByText('6')
- cy.findByText('Math Display:')
- cy.findByText('1')
- })
- })
- })
- describe('cite key search', function () {
- it('can insert citation from cite key', function () {
- createNewFile()
- cy.get('.cm-line').type('\\cite{{}gre')
- cy.findByRole('listbox').within(() => {
- cy.findByRole('option').should('contain.text', 'greenwade93').click()
- })
- cy.get('.cm-line').should('have.text', '\\cite{greenwade93}')
- })
- it('updates citation search when bib file is changed', function () {
- createNewFile()
- cy.get('.cm-line').type('\\cite{{}new')
- // Wait a reasonable time to ensure the autocomplete would've appeared if there were any matches
- // eslint-disable-next-line cypress/no-unnecessary-waiting
- cy.wait(200)
- cy.findByRole('listbox').should('not.exist')
- cy.findByRole('treeitem', { name: 'sample.bib' }).click()
- cy.get('.cm-line')
- .last()
- .type(
- '\n@article{{}newkey2024,\n author = {{}Doe, John},\n title = {{}A New Article},\n journal = {{}Journal of Testing},\n year = 2024\n}\n'
- )
- createNewFile()
- cy.get('.cm-line').type('\\cite{{}new')
- cy.findByRole('listbox').within(() => {
- cy.findByRole('option').should('contain.text', 'newkey2024').click()
- })
- cy.get('.cm-line').should('have.text', '\\cite{newkey2024}')
- })
- })
- describe('layout selector', function () {
- it('show editor only and switch between editor and pdf', function () {
- cy.findByRole('region', { name: 'PDF preview' }).should('be.visible')
- cy.get('.cm-editor').should('be.visible')
- cy.findByRole('button', { name: 'Layout options' }).click()
- cy.findByRole('menu').within(() => {
- cy.findByRole('menuitem', { name: /Editor only/ }).click()
- })
- cy.findByRole('region', { name: 'PDF preview' }).should('not.be.visible')
- cy.get('.cm-editor').should('be.visible')
- // force click as tooltip may cover button for some reason
- cy.findByRole('button', { name: 'Switch to PDF' }).click({ force: true })
- cy.findByRole('region', { name: 'PDF preview' }).should('be.visible')
- cy.get('.cm-editor').should('not.be.visible')
- cy.findByRole('button', { name: 'Switch to editor' }).click()
- cy.findByRole('region', { name: 'PDF preview' }).should('not.be.visible')
- cy.get('.cm-editor').should('be.visible')
- })
- it('show PDF only and go back to split view', function () {
- cy.findByRole('region', { name: 'PDF preview' }).should('be.visible')
- cy.get('.cm-editor').should('be.visible')
- cy.findByRole('button', { name: 'Layout options' }).click()
- cy.findByRole('menu').within(() => {
- cy.findByRole('menuitem', { name: /PDF only/ }).click()
- })
- cy.findByRole('region', { name: 'PDF preview' }).should('be.visible')
- cy.get('.cm-editor').should('not.be.visible')
- cy.findByRole('button', { name: 'Layout options' }).click()
- cy.findByRole('menu').within(() => {
- cy.findByRole('menuitem', { name: 'Split view' }).click()
- })
- cy.findByRole('region', { name: 'PDF preview' }).should('be.visible')
- cy.get('.cm-editor').should('be.visible')
- })
- it('PDF in a separate tab (tests editor only)', function () {
- cy.findByTestId('pdf-viewer').should('be.visible')
- cy.get('.cm-editor').should('be.visible')
- cy.findByRole('button', { name: 'Layout options' }).click()
- cy.findByRole('menu').within(() => {
- cy.findByRole('menuitem', { name: 'Open PDF in separate tab' }).click()
- })
- cy.findByTestId('pdf-viewer').should('not.exist')
- cy.get('.cm-editor').should('be.visible')
- })
- })
- describe('full project search', function () {
- it('can search for text in project files', function () {
- cy.findByRole('tab', { name: 'Project search' }).click()
- cy.findByRole('searchbox', { name: 'Search' })
- .should('be.visible')
- .type('Some examples to get started')
- cy.get('button').contains('Search').click()
- cy.findByRole('listbox').within(() => {
- cy.findByRole('option', {
- name: /Some examples to get started/,
- }).should('be.visible')
- })
- })
- })
- })
- function createRandomLetterString() {
- const chars = 'abcdefghijklmnopqrstuvwxyz'
- let result = ''
- for (let i = 0; i < 12; i++) {
- result += chars.charAt(Math.floor(Math.random() * chars.length))
- }
- return result
- }
|