editor-left-menu.spec.tsx 25 KB

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