project.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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: 'Read only' | '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('Share').click({ force: true })
  39. })
  40. }
  41. export function shareProjectByEmailAndAcceptInviteViaDash(
  42. projectName: string,
  43. email: string,
  44. level: 'Read only' | 'Can edit'
  45. ) {
  46. shareProjectByEmail(projectName, email, level)
  47. login(email)
  48. cy.visit('/project')
  49. cy.findByText(new RegExp(projectName))
  50. .parent()
  51. .parent()
  52. .within(() => {
  53. cy.findByText('Join Project').click()
  54. })
  55. }
  56. export function shareProjectByEmailAndAcceptInviteViaEmail(
  57. projectName: string,
  58. email: string,
  59. level: 'Read only' | 'Can edit'
  60. ) {
  61. shareProjectByEmail(projectName, email, level)
  62. login(email)
  63. openEmail(projectName, frame => {
  64. frame.contains('View project').then(a => {
  65. cy.log(
  66. 'bypass target=_blank and navigate current browser tab/cypress-iframe to project invite'
  67. )
  68. cy.visit(a.attr('href')!)
  69. })
  70. })
  71. cy.url().should('match', /\/project\/[a-f0-9]+\/invite\/token\/[a-f0-9]+/)
  72. cy.findByText(/user would like you to join/)
  73. cy.contains(new RegExp(`You are accepting this invite as ${email}`))
  74. cy.findByText('Join Project').click()
  75. }
  76. export function enableLinkSharing() {
  77. let linkSharingReadOnly: string
  78. let linkSharingReadAndWrite: string
  79. cy.findByText('Share').click()
  80. cy.findByText('Turn on link sharing').click()
  81. cy.findByText('Anyone with this link can view this project')
  82. .next()
  83. .should('contain.text', 'http://sharelatex/')
  84. .then(el => {
  85. linkSharingReadOnly = el.text()
  86. })
  87. cy.findByText('Anyone with this link can edit this project')
  88. .next()
  89. .should('contain.text', 'http://sharelatex/')
  90. .then(el => {
  91. linkSharingReadAndWrite = el.text()
  92. })
  93. return cy.then(() => {
  94. return { linkSharingReadOnly, linkSharingReadAndWrite }
  95. })
  96. }