editor-left-menu.spec.tsx 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899
  1. import EditorLeftMenu from '../../../../frontend/js/features/editor-left-menu/components/editor-left-menu'
  2. import {
  3. AllowedImageName,
  4. OverallThemeMeta,
  5. SpellCheckLanguage,
  6. } from '../../../../types/project-settings'
  7. import { EditorProviders } from '../../helpers/editor-providers'
  8. import { mockScope } from './scope'
  9. import { Folder } from '../../../../types/folder'
  10. import { docsInFolder } from '@/features/file-tree/util/docs-in-folder'
  11. describe('<EditorLeftMenu />', function () {
  12. beforeEach(function () {
  13. cy.viewport(800, 800)
  14. cy.interceptCompile()
  15. })
  16. describe('for non-anonymous users', function () {
  17. const overallThemes: OverallThemeMeta[] = [
  18. {
  19. name: 'Overall Theme 1',
  20. val: '',
  21. path: 'https://overleaf.com/overalltheme-1.css',
  22. },
  23. {
  24. name: 'Overall Theme 2',
  25. val: 'light-',
  26. path: 'https://overleaf.com/overalltheme-2.css',
  27. },
  28. ]
  29. const allowedImageNames: AllowedImageName[] = [
  30. {
  31. imageDesc: 'Image 1',
  32. imageName: 'img-1',
  33. },
  34. {
  35. imageDesc: 'Image 2',
  36. imageName: 'img-2',
  37. },
  38. ]
  39. beforeEach(function () {
  40. window.metaAttributesCache.set('ol-overallThemes', overallThemes)
  41. window.metaAttributesCache.set('ol-allowedImageNames', allowedImageNames)
  42. window.metaAttributesCache.set('ol-anonymous', false)
  43. window.metaAttributesCache.set('ol-gitBridgeEnabled', true)
  44. window.metaAttributesCache.set('ol-showSupport', true)
  45. window.metaAttributesCache.set('ol-user', {
  46. email: 'sherlock@holmes.co.uk',
  47. first_name: 'Sherlock',
  48. last_name: 'Holmes',
  49. })
  50. })
  51. it('render full menu', function () {
  52. const scope = mockScope({
  53. ui: {
  54. leftMenuShown: true,
  55. },
  56. })
  57. cy.mount(
  58. <EditorProviders scope={scope}>
  59. <EditorLeftMenu />
  60. </EditorProviders>
  61. )
  62. // Download Menu
  63. cy.findByRole('heading', { name: 'Download' })
  64. cy.findByRole('link', { name: 'Source' })
  65. cy.findByRole('link', { name: 'PDF' })
  66. // Actions Menu
  67. cy.findByRole('heading', { name: 'Actions' })
  68. cy.findByRole('button', { name: 'Copy Project' })
  69. cy.findByRole('button', { name: 'Word Count' })
  70. // Sync Menu
  71. cy.findByRole('heading', { name: 'Sync' })
  72. cy.findByRole('button', { name: 'Dropbox' })
  73. cy.findByRole('button', { name: 'Git' })
  74. cy.findByRole('button', { name: 'GitHub' })
  75. // Settings Menu
  76. cy.findByRole('heading', { name: 'Settings' })
  77. cy.findByLabelText('Compiler')
  78. cy.findByLabelText('TeX Live version')
  79. cy.findByLabelText('Main document')
  80. cy.findByLabelText('Spell check')
  81. cy.findByLabelText('Auto-complete')
  82. cy.findByLabelText('Auto-close Brackets')
  83. cy.findByLabelText('Code check')
  84. cy.findByLabelText('Editor theme')
  85. cy.findByLabelText('Overall theme')
  86. cy.findByLabelText('Keybindings')
  87. cy.findByLabelText('Font Size')
  88. cy.findByLabelText('Font Family')
  89. cy.findByLabelText('Line Height')
  90. cy.findByLabelText('PDF Viewer')
  91. // Help Menu
  92. cy.findByRole('heading', { name: 'Help' })
  93. cy.findByRole('button', { name: 'Show Hotkeys' })
  94. cy.findByRole('link', { name: 'Documentation' })
  95. cy.findByRole('button', { name: 'Contact Us' })
  96. })
  97. describe('download menu', function () {
  98. it('have a correct source & pdf download url', function () {
  99. const scope = mockScope({
  100. ui: {
  101. leftMenuShown: true,
  102. },
  103. })
  104. cy.mount(
  105. <EditorProviders scope={scope}>
  106. <EditorLeftMenu />
  107. </EditorProviders>
  108. )
  109. cy.findByRole('link', { name: 'Source' }).should(
  110. 'have.attr',
  111. 'href',
  112. '/project/project123/download/zip'
  113. )
  114. cy.findByRole('link', { name: 'PDF' })
  115. .should('have.attr', 'href')
  116. .and('match', /\/download\/project\/project123\/build/)
  117. })
  118. })
  119. describe('actions menu', function () {
  120. it('shows copy project modal correctly', function () {
  121. cy.intercept('POST', '/project/*/clone', {
  122. body: {
  123. project_id: 'new_project_id',
  124. },
  125. })
  126. const scope = mockScope({
  127. ui: {
  128. leftMenuShown: true,
  129. },
  130. })
  131. cy.mount(
  132. <EditorProviders scope={scope}>
  133. <EditorLeftMenu />
  134. </EditorProviders>
  135. )
  136. cy.findByRole('button', { name: 'Copy Project' }).click()
  137. cy.findByRole('heading', { name: 'Copy Project' })
  138. // try closing & re-opening the modal with different methods
  139. cy.findByRole('button', { name: 'Close' }).click()
  140. cy.findByRole('button', { name: 'Copy Project' }).click()
  141. cy.findByRole('button', { name: 'Cancel' }).click()
  142. cy.findByRole('button', { name: 'Copy Project' }).click()
  143. cy.findByLabelText('New Name').focus()
  144. cy.findByLabelText('New Name').clear()
  145. cy.findByLabelText('New Name').type('Project Renamed')
  146. cy.get('#clone-project-form-name[value="Project Renamed"')
  147. })
  148. it('shows word count modal correctly', function () {
  149. cy.intercept('GET', '/project/*/wordcount*', {
  150. texcount: {
  151. encode: 'ascii',
  152. textWords: 781,
  153. headWords: 66,
  154. outside: 11,
  155. headers: 41,
  156. elements: 2,
  157. mathInline: 6,
  158. mathDisplay: 1,
  159. errors: 0,
  160. },
  161. }).as('wordCount')
  162. const scope = mockScope({
  163. ui: {
  164. leftMenuShown: true,
  165. },
  166. })
  167. cy.mount(
  168. <EditorProviders scope={scope}>
  169. <EditorLeftMenu />
  170. </EditorProviders>
  171. )
  172. cy.findByRole('button', { name: 'Word Count' }).click()
  173. cy.wait('@wordCount')
  174. cy.findByText('Total Words:')
  175. cy.findByText('781')
  176. cy.findByText('Headers:')
  177. cy.findByText('41')
  178. cy.findByText('Math Inline:')
  179. cy.findByText('6')
  180. cy.findByText('Math Display:')
  181. cy.findByText('1')
  182. })
  183. })
  184. describe('sync menu', function () {
  185. it('shows dropbox modal correctly', function () {
  186. cy.intercept('GET', '/dropbox/status', {
  187. registered: true,
  188. })
  189. const scope = mockScope({
  190. ui: {
  191. leftMenuShown: true,
  192. },
  193. project: {
  194. members: [],
  195. owner: {
  196. _id: '123',
  197. },
  198. },
  199. user: {
  200. features: {
  201. dropbox: false,
  202. },
  203. },
  204. })
  205. cy.mount(
  206. <EditorProviders scope={scope}>
  207. <EditorLeftMenu />
  208. </EditorProviders>
  209. )
  210. cy.findByRole('button', { name: 'Dropbox' }).click()
  211. cy.findByText('Dropbox Sync')
  212. })
  213. it('shows git modal correctly', function () {
  214. const scope = mockScope({
  215. ui: {
  216. leftMenuShown: true,
  217. },
  218. project: {
  219. owner: {
  220. _id: '123',
  221. },
  222. features: {
  223. gitBridge: true,
  224. },
  225. },
  226. })
  227. cy.mount(
  228. <EditorProviders scope={scope}>
  229. <EditorLeftMenu />
  230. </EditorProviders>
  231. )
  232. cy.findByRole('button', { name: 'Git' }).click()
  233. cy.findByText('Clone with Git')
  234. cy.findByText(/your project using the link displayed below/)
  235. })
  236. it('shows git modal paywall correctly', function () {
  237. const scope = mockScope({
  238. ui: {
  239. leftMenuShown: true,
  240. },
  241. project: {
  242. owner: {
  243. _id: '123',
  244. },
  245. features: {
  246. gitBridge: false,
  247. },
  248. },
  249. })
  250. cy.mount(
  251. <EditorProviders scope={scope}>
  252. <EditorLeftMenu />
  253. </EditorProviders>
  254. )
  255. cy.findByRole('button', { name: 'Git' }).click()
  256. cy.findByText('Collaborate online and offline, using your own workflow')
  257. })
  258. it('shows github modal correctly', function () {
  259. cy.intercept('GET', '/user/github-sync/status', {
  260. available: false,
  261. enabled: false,
  262. }).as('user-status')
  263. cy.intercept('GET', '/project/*/github-sync/status', {
  264. enabled: false,
  265. }).as('project-status')
  266. const scope = mockScope({
  267. ui: {
  268. leftMenuShown: true,
  269. },
  270. })
  271. cy.mount(
  272. <EditorProviders scope={scope}>
  273. <EditorLeftMenu />
  274. </EditorProviders>
  275. )
  276. cy.wait('@compile')
  277. cy.findByRole('button', { name: 'GitHub' }).click()
  278. cy.findByText('GitHub Sync')
  279. cy.wait(['@user-status', '@project-status'])
  280. cy.findByText('Push to GitHub, pull to Overleaf')
  281. })
  282. it('hides the entire sync section when git bridge is disabled', function () {
  283. window.metaAttributesCache.set('ol-gitBridgeEnabled', false)
  284. cy.findByRole('button', { name: 'Dropbox' }).should('not.exist')
  285. cy.findByRole('button', { name: 'Git' }).should('not.exist')
  286. cy.findByRole('button', { name: 'GitHub' }).should('not.exist')
  287. })
  288. })
  289. describe('settings menu', function () {
  290. it('shows compiler menu correctly', function () {
  291. const scope = mockScope({
  292. ui: {
  293. leftMenuShown: true,
  294. },
  295. })
  296. cy.mount(
  297. <EditorProviders scope={scope}>
  298. <EditorLeftMenu />
  299. </EditorProviders>
  300. )
  301. cy.get<HTMLOptionElement>('#settings-menu-compiler option').then(
  302. options => {
  303. const values = [...options].map(o => o.value)
  304. expect(values).to.deep.eq([
  305. 'pdflatex',
  306. 'latex',
  307. 'xelatex',
  308. 'lualatex',
  309. ])
  310. const texts = [...options].map(o => o.text)
  311. expect(texts).to.deep.eq([
  312. 'pdfLaTeX',
  313. 'LaTeX',
  314. 'XeLaTeX',
  315. 'LuaLaTeX',
  316. ])
  317. }
  318. )
  319. })
  320. it('shows texlive version menu correctly', function () {
  321. const scope = mockScope({
  322. ui: {
  323. leftMenuShown: true,
  324. },
  325. })
  326. cy.mount(
  327. <EditorProviders scope={scope}>
  328. <EditorLeftMenu />
  329. </EditorProviders>
  330. )
  331. cy.get<HTMLOptionElement>('#settings-menu-imageName option').then(
  332. options => {
  333. const values = [...options].map(o => o.value)
  334. expect(values).to.deep.eq(['img-1', 'img-2'])
  335. const texts = [...options].map(o => o.text)
  336. expect(texts).to.deep.eq(['Image 1', 'Image 2'])
  337. }
  338. )
  339. })
  340. it('shows document menu correctly', function () {
  341. const rootFolder: Folder = {
  342. _id: 'root-folder-id',
  343. name: 'rootFolder',
  344. docs: [
  345. {
  346. _id: 'id1',
  347. name: 'main.tex',
  348. },
  349. {
  350. _id: 'id2',
  351. name: 'main2.tex',
  352. },
  353. ],
  354. fileRefs: [],
  355. folders: [],
  356. }
  357. const scope = mockScope({
  358. ui: {
  359. leftMenuShown: true,
  360. },
  361. })
  362. cy.mount(
  363. <EditorProviders scope={scope} rootFolder={[rootFolder as any]}>
  364. <EditorLeftMenu />
  365. </EditorProviders>
  366. )
  367. const docs = docsInFolder(rootFolder)
  368. cy.get<HTMLOptionElement>('#settings-menu-rootDocId option').then(
  369. options => {
  370. const values = [...options].map(o => o.value)
  371. expect(values).to.deep.eq(docs.map(doc => doc.doc.id))
  372. const texts = [...options].map(o => o.text)
  373. expect(texts).to.deep.eq(docs.map(doc => doc.path))
  374. }
  375. )
  376. })
  377. it('shows spellcheck menu correctly', function () {
  378. const languages: SpellCheckLanguage[] = [
  379. {
  380. name: 'Lang 1',
  381. code: 'lang-1',
  382. },
  383. {
  384. name: 'Lang 2',
  385. code: 'lang-2',
  386. },
  387. ]
  388. window.metaAttributesCache.set('ol-languages', languages)
  389. const scope = mockScope({
  390. ui: {
  391. leftMenuShown: true,
  392. },
  393. })
  394. cy.mount(
  395. <EditorProviders scope={scope}>
  396. <EditorLeftMenu />
  397. </EditorProviders>
  398. )
  399. cy.get<HTMLOptionElement>(
  400. '#settings-menu-spellCheckLanguage option'
  401. ).then(options => {
  402. const values = [...options].map(o => o.value)
  403. expect(values).to.deep.eq(['', 'lang-1', 'lang-2'])
  404. const texts = [...options].map(o => o.text)
  405. expect(texts).to.deep.eq(['Off', 'Lang 1', 'Lang 2'])
  406. })
  407. })
  408. it('shows dictionary modal correctly', function () {
  409. const scope = mockScope({
  410. ui: {
  411. leftMenuShown: true,
  412. },
  413. })
  414. cy.mount(
  415. <EditorProviders scope={scope}>
  416. <EditorLeftMenu />
  417. </EditorProviders>
  418. )
  419. cy.get('label[for="dictionary"] ~ button').click()
  420. cy.findByText('Edit Dictionary')
  421. cy.findByText('Your custom dictionary is empty.')
  422. })
  423. it('shows auto-complete menu correctly', function () {
  424. const scope = mockScope({
  425. ui: {
  426. leftMenuShown: true,
  427. },
  428. })
  429. cy.mount(
  430. <EditorProviders scope={scope}>
  431. <EditorLeftMenu />
  432. </EditorProviders>
  433. )
  434. cy.get<HTMLOptionElement>('#settings-menu-autoComplete option').then(
  435. options => {
  436. const values = [...options].map(o => o.value)
  437. expect(values).to.deep.eq(['true', 'false'])
  438. const texts = [...options].map(o => o.text)
  439. expect(texts).to.deep.eq(['On', 'Off'])
  440. }
  441. )
  442. })
  443. it('shows auto-close brackets menu correctly', function () {
  444. const scope = mockScope({
  445. ui: {
  446. leftMenuShown: true,
  447. },
  448. })
  449. cy.mount(
  450. <EditorProviders scope={scope}>
  451. <EditorLeftMenu />
  452. </EditorProviders>
  453. )
  454. cy.get<HTMLOptionElement>(
  455. '#settings-menu-autoPairDelimiters option'
  456. ).then(options => {
  457. const values = [...options].map(o => o.value)
  458. expect(values).to.deep.eq(['true', 'false'])
  459. const texts = [...options].map(o => o.text)
  460. expect(texts).to.deep.eq(['On', 'Off'])
  461. })
  462. })
  463. it('shows code check menu correctly', function () {
  464. const scope = mockScope({
  465. ui: {
  466. leftMenuShown: true,
  467. },
  468. })
  469. cy.mount(
  470. <EditorProviders scope={scope}>
  471. <EditorLeftMenu />
  472. </EditorProviders>
  473. )
  474. cy.get<HTMLOptionElement>(
  475. '#settings-menu-syntaxValidation option'
  476. ).then(options => {
  477. const values = [...options].map(o => o.value)
  478. expect(values).to.deep.eq(['true', 'false'])
  479. const texts = [...options].map(o => o.text)
  480. expect(texts).to.deep.eq(['On', 'Off'])
  481. })
  482. })
  483. it('shows editor theme menu correctly', function () {
  484. const editorThemes = ['editortheme-1', 'editortheme-2', 'editortheme-3']
  485. const legacyEditorThemes = [
  486. 'legacytheme-1',
  487. 'legacytheme-2',
  488. 'legacytheme-3',
  489. ]
  490. window.metaAttributesCache.set('ol-editorThemes', editorThemes)
  491. window.metaAttributesCache.set(
  492. 'ol-legacyEditorThemes',
  493. legacyEditorThemes
  494. )
  495. const scope = mockScope({
  496. ui: {
  497. leftMenuShown: true,
  498. },
  499. })
  500. cy.mount(
  501. <EditorProviders scope={scope}>
  502. <EditorLeftMenu />
  503. </EditorProviders>
  504. )
  505. cy.get<HTMLOptionElement>('#settings-menu-editorTheme option').then(
  506. options => {
  507. const values = [...options].map(o => o.value)
  508. expect(values).to.deep.eq([
  509. 'editortheme-1',
  510. 'editortheme-2',
  511. 'editortheme-3',
  512. '-',
  513. 'legacytheme-1',
  514. 'legacytheme-2',
  515. 'legacytheme-3',
  516. ])
  517. const texts = [...options].map(o => o.text)
  518. expect(texts).to.deep.eq([
  519. 'editortheme-1',
  520. 'editortheme-2',
  521. 'editortheme-3',
  522. '—————————————————',
  523. 'legacytheme-1 (Legacy)',
  524. 'legacytheme-2 (Legacy)',
  525. 'legacytheme-3 (Legacy)',
  526. ])
  527. }
  528. )
  529. })
  530. it('shows overall theme menu correctly', function () {
  531. const scope = mockScope({
  532. ui: {
  533. leftMenuShown: true,
  534. },
  535. })
  536. cy.mount(
  537. <EditorProviders scope={scope}>
  538. <EditorLeftMenu />
  539. </EditorProviders>
  540. )
  541. cy.get<HTMLOptionElement>('#settings-menu-overallTheme option').then(
  542. options => {
  543. const values = [...options].map(o => o.value)
  544. expect(values).to.deep.eq(['', 'light-'])
  545. const texts = [...options].map(o => o.text)
  546. expect(texts).to.deep.eq(['Overall Theme 1', 'Overall Theme 2'])
  547. }
  548. )
  549. })
  550. it('shows keybindings menu correctly', function () {
  551. const scope = mockScope({
  552. ui: {
  553. leftMenuShown: true,
  554. },
  555. })
  556. cy.mount(
  557. <EditorProviders scope={scope}>
  558. <EditorLeftMenu />
  559. </EditorProviders>
  560. )
  561. cy.get<HTMLOptionElement>('#settings-menu-mode option').then(
  562. options => {
  563. const values = [...options].map(o => o.value)
  564. expect(values).to.deep.eq(['default', 'vim', 'emacs'])
  565. const texts = [...options].map(o => o.text)
  566. expect(texts).to.deep.eq(['None', 'Vim', 'Emacs'])
  567. }
  568. )
  569. })
  570. it('shows font size menu correctly', function () {
  571. const scope = mockScope({
  572. ui: {
  573. leftMenuShown: true,
  574. },
  575. })
  576. cy.mount(
  577. <EditorProviders scope={scope}>
  578. <EditorLeftMenu />
  579. </EditorProviders>
  580. )
  581. cy.get<HTMLOptionElement>('#settings-menu-fontSize option').then(
  582. options => {
  583. const values = [...options].map(o => o.value)
  584. expect(values).to.deep.eq([
  585. '10',
  586. '11',
  587. '12',
  588. '13',
  589. '14',
  590. '16',
  591. '18',
  592. '20',
  593. '22',
  594. '24',
  595. ])
  596. const texts = [...options].map(o => o.text)
  597. expect(texts).to.deep.eq([
  598. '10px',
  599. '11px',
  600. '12px',
  601. '13px',
  602. '14px',
  603. '16px',
  604. '18px',
  605. '20px',
  606. '22px',
  607. '24px',
  608. ])
  609. }
  610. )
  611. })
  612. it('shows font family menu correctly', function () {
  613. const scope = mockScope({
  614. ui: {
  615. leftMenuShown: true,
  616. },
  617. })
  618. cy.mount(
  619. <EditorProviders scope={scope}>
  620. <EditorLeftMenu />
  621. </EditorProviders>
  622. )
  623. cy.get<HTMLOptionElement>('#settings-menu-fontFamily option').then(
  624. options => {
  625. const values = [...options].map(o => o.value)
  626. expect(values).to.deep.eq(['monaco', 'lucida'])
  627. const texts = [...options].map(o => o.text)
  628. expect(texts).to.deep.eq([
  629. 'Monaco / Menlo / Consolas',
  630. 'Lucida / Source Code Pro',
  631. ])
  632. }
  633. )
  634. })
  635. it('shows line height menu correctly', function () {
  636. const scope = mockScope({
  637. ui: {
  638. leftMenuShown: true,
  639. },
  640. })
  641. cy.mount(
  642. <EditorProviders scope={scope}>
  643. <EditorLeftMenu />
  644. </EditorProviders>
  645. )
  646. cy.get<HTMLOptionElement>('#settings-menu-lineHeight option').then(
  647. options => {
  648. const values = [...options].map(o => o.value)
  649. expect(values).to.deep.eq(['compact', 'normal', 'wide'])
  650. const texts = [...options].map(o => o.text)
  651. expect(texts).to.deep.eq(['Compact', 'Normal', 'Wide'])
  652. }
  653. )
  654. })
  655. it('shows pdf viewer menu correctly', function () {
  656. const scope = mockScope({
  657. ui: {
  658. leftMenuShown: true,
  659. },
  660. })
  661. cy.mount(
  662. <EditorProviders scope={scope}>
  663. <EditorLeftMenu />
  664. </EditorProviders>
  665. )
  666. cy.get<HTMLOptionElement>('#settings-menu-pdfViewer option').then(
  667. options => {
  668. const values = [...options].map(o => o.value)
  669. expect(values).to.deep.eq(['pdfjs', 'native'])
  670. const texts = [...options].map(o => o.text)
  671. expect(texts).to.deep.eq(['Overleaf', 'Browser'])
  672. }
  673. )
  674. })
  675. })
  676. describe('help menu', function () {
  677. it('shows hotkeys modal correctly', function () {
  678. const scope = mockScope({
  679. ui: {
  680. leftMenuShown: true,
  681. },
  682. })
  683. cy.mount(
  684. <EditorProviders scope={scope}>
  685. <EditorLeftMenu />
  686. </EditorProviders>
  687. )
  688. cy.findByRole('button', { name: 'Show Hotkeys' }).click()
  689. cy.findByText('Hotkeys (Source editor)')
  690. })
  691. it('shows correct url for documentation', function () {
  692. const scope = mockScope({
  693. ui: {
  694. leftMenuShown: true,
  695. },
  696. })
  697. cy.mount(
  698. <EditorProviders scope={scope}>
  699. <EditorLeftMenu />
  700. </EditorProviders>
  701. )
  702. cy.findByRole('link', { name: 'Documentation' }).should(
  703. 'have.attr',
  704. 'href',
  705. '/learn'
  706. )
  707. })
  708. it('shows correct contact us modal', function () {
  709. const scope = mockScope({
  710. ui: {
  711. leftMenuShown: true,
  712. },
  713. })
  714. cy.mount(
  715. <EditorProviders scope={scope}>
  716. <EditorLeftMenu />
  717. </EditorProviders>
  718. )
  719. cy.findByRole('button', { name: 'Contact Us' }).click()
  720. cy.findByText('Affected project URL (Optional)')
  721. })
  722. })
  723. })
  724. describe('for anonymous users', function () {
  725. it('render minimal menu', function () {
  726. const scope = mockScope({
  727. ui: {
  728. leftMenuShown: true,
  729. },
  730. })
  731. window.metaAttributesCache.set('ol-anonymous', true)
  732. cy.mount(
  733. <EditorProviders scope={scope}>
  734. <EditorLeftMenu />
  735. </EditorProviders>
  736. )
  737. // Download Menu
  738. cy.findByRole('heading', { name: 'Download' })
  739. cy.findByRole('link', { name: 'Source' })
  740. cy.findByRole('link', { name: 'PDF' })
  741. // Actions Menu
  742. cy.findByRole('heading', { name: 'Actions' }).should('not.exist')
  743. cy.findByRole('button', { name: 'Copy Project' }).should('not.exist')
  744. cy.findByRole('button', { name: 'Word Count' }).should('not.exist')
  745. // Sync Menu
  746. cy.findByRole('heading', { name: 'Sync' }).should('not.exist')
  747. cy.findByRole('button', { name: 'Dropbox' }).should('not.exist')
  748. cy.findByRole('button', { name: 'Git' }).should('not.exist')
  749. cy.findByRole('button', { name: 'GitHub' }).should('not.exist')
  750. // Settings Menu
  751. cy.findByRole('heading', { name: 'Settings' }).should('not.exist')
  752. cy.findByLabelText('Compiler').should('not.exist')
  753. cy.findByLabelText('TeX Live version').should('not.exist')
  754. cy.findByLabelText('Main document').should('not.exist')
  755. cy.findByLabelText('Spell check').should('not.exist')
  756. cy.findByLabelText('Auto-complete').should('not.exist')
  757. cy.findByLabelText('Auto-close Brackets').should('not.exist')
  758. cy.findByLabelText('Code check').should('not.exist')
  759. cy.findByLabelText('Editor theme').should('not.exist')
  760. cy.findByLabelText('Overall theme').should('not.exist')
  761. cy.findByLabelText('Keybindings').should('not.exist')
  762. cy.findByLabelText('Font Size').should('not.exist')
  763. cy.findByLabelText('Font Family').should('not.exist')
  764. cy.findByLabelText('Line Height').should('not.exist')
  765. cy.findByLabelText('PDF Viewer').should('not.exist')
  766. // Help Menu
  767. cy.findByRole('heading', { name: 'Help' })
  768. cy.findByRole('button', { name: 'Show Hotkeys' })
  769. cy.findByRole('button', { name: 'Documentation' }).should('not.exist')
  770. cy.findByRole('link', { name: 'Contact Us' }).should('not.exist')
  771. })
  772. })
  773. })