project.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import { login } from './login'
  2. import { openEmail } from './email'
  3. export function createProject(
  4. name: string,
  5. {
  6. type = 'Blank Project',
  7. newProjectButtonMatcher = /new project/i,
  8. }: {
  9. type?: 'Blank Project' | 'Example Project'
  10. newProjectButtonMatcher?: RegExp
  11. } = {}
  12. ): Cypress.Chainable<string> {
  13. cy.findAllByRole('button').contains(newProjectButtonMatcher).click()
  14. // FIXME: This should only look in the left menu
  15. cy.findAllByText(type).first().click()
  16. cy.findByRole('dialog').within(() => {
  17. cy.get('input').type(name)
  18. cy.findByText('Create').click()
  19. })
  20. return cy
  21. .url()
  22. .should('match', /\/project\/[a-fA-F0-9]{24}/)
  23. .then(url => url.split('/').pop())
  24. }
  25. function shareProjectByEmail(
  26. projectName: string,
  27. email: string,
  28. level: 'Can view' | 'Can edit'
  29. ) {
  30. cy.visit('/project')
  31. cy.findByText(projectName).click()
  32. cy.findByText('Share').click()
  33. cy.findByRole('dialog').within(() => {
  34. cy.get('input').type(`${email},`)
  35. cy.get('input')
  36. .parents('form')
  37. .within(() => cy.findByText('Can edit').parent().select(level))
  38. cy.findByText('Invite').click({ force: true })
  39. cy.findByText('Invite not yet accepted.')
  40. })
  41. }
  42. export function shareProjectByEmailAndAcceptInviteViaDash(
  43. projectName: string,
  44. email: string,
  45. level: 'Can view' | 'Can edit'
  46. ) {
  47. shareProjectByEmail(projectName, email, level)
  48. login(email)
  49. cy.visit('/project')
  50. cy.findByText(new RegExp(projectName))
  51. .parent()
  52. .parent()
  53. .within(() => {
  54. cy.findByText('Join Project').click()
  55. })
  56. }
  57. export function shareProjectByEmailAndAcceptInviteViaEmail(
  58. projectName: string,
  59. email: string,
  60. level: 'Can view' | 'Can edit'
  61. ) {
  62. shareProjectByEmail(projectName, email, level)
  63. login(email)
  64. openEmail(projectName, frame => {
  65. frame.contains('View project').then(a => {
  66. cy.log(
  67. 'bypass target=_blank and navigate current browser tab/cypress-iframe to project invite'
  68. )
  69. cy.visit(a.attr('href')!)
  70. })
  71. })
  72. cy.url().should('match', /\/project\/[a-f0-9]+\/invite\/token\/[a-f0-9]+/)
  73. cy.findByText(/user would like you to join/)
  74. cy.contains(new RegExp(`You are accepting this invite as ${email}`))
  75. cy.findByText('Join Project').click()
  76. }
  77. export function enableLinkSharing() {
  78. let linkSharingReadOnly: string
  79. let linkSharingReadAndWrite: string
  80. cy.findByText('Share').click()
  81. cy.findByText('Turn on link sharing').click()
  82. cy.findByText('Anyone with this link can view this project')
  83. .next()
  84. .should('contain.text', 'http://sharelatex/')
  85. .then(el => {
  86. linkSharingReadOnly = el.text()
  87. })
  88. cy.findByText('Anyone with this link can edit this project')
  89. .next()
  90. .should('contain.text', 'http://sharelatex/')
  91. .then(el => {
  92. linkSharingReadAndWrite = el.text()
  93. })
  94. return cy.then(() => {
  95. return { linkSharingReadOnly, linkSharingReadAndWrite }
  96. })
  97. }