project.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { login } from './login'
  2. export function createProject(
  3. name: string,
  4. {
  5. type = 'Blank Project',
  6. newProjectButtonMatcher = /new project/i,
  7. }: {
  8. type?: 'Blank Project' | 'Example Project'
  9. newProjectButtonMatcher?: RegExp
  10. } = {}
  11. ): Cypress.Chainable<string> {
  12. cy.findAllByRole('button').contains(newProjectButtonMatcher).click()
  13. // FIXME: This should only look in the left menu
  14. cy.findAllByText(type).first().click()
  15. cy.findByRole('dialog').within(() => {
  16. cy.get('input').type(name)
  17. cy.findByText('Create').click()
  18. })
  19. return cy
  20. .url()
  21. .should('match', /\/project\/[a-fA-F0-9]{24}/)
  22. .then(url => url.split('/').pop())
  23. }
  24. export function shareProjectByEmailAndAcceptInvite(
  25. projectName: string,
  26. email: string,
  27. level: 'Read only' | 'Can edit'
  28. ) {
  29. cy.visit('/project')
  30. cy.findByText(projectName).click()
  31. cy.findByText('Share').click()
  32. cy.findByRole('dialog').within(() => {
  33. cy.get('input').type(`${email},`)
  34. cy.get('input')
  35. .parents('form')
  36. .within(() => cy.findByText('Can edit').parent().select(level))
  37. cy.findByText('Share').click({ force: true })
  38. })
  39. login(email)
  40. cy.visit('/project')
  41. cy.findByText(new RegExp(projectName))
  42. .parent()
  43. .parent()
  44. .within(() => {
  45. cy.findByText('Join Project').click()
  46. })
  47. }
  48. export function enableLinkSharing() {
  49. let linkSharingReadOnly: string
  50. let linkSharingReadAndWrite: string
  51. cy.findByText('Share').click()
  52. cy.findByText('Turn on link sharing').click()
  53. cy.findByText('Anyone with this link can view this project')
  54. .next()
  55. .should('contain.text', 'http://sharelatex/')
  56. .then(el => {
  57. linkSharingReadOnly = el.text()
  58. })
  59. cy.findByText('Anyone with this link can edit this project')
  60. .next()
  61. .should('contain.text', 'http://sharelatex/')
  62. .then(el => {
  63. linkSharingReadAndWrite = el.text()
  64. })
  65. return cy.then(() => {
  66. return { linkSharingReadOnly, linkSharingReadAndWrite }
  67. })
  68. }