2024-07-25 11:13:52 -04:00
|
|
|
import { login } from './login'
|
2024-07-29 05:56:56 -04:00
|
|
|
import { openEmail } from './email'
|
2024-07-25 11:13:52 -04:00
|
|
|
|
2023-11-23 05:40:13 -05:00
|
|
|
export function createProject(
|
|
|
|
name: string,
|
|
|
|
{
|
|
|
|
type = 'Blank Project',
|
2024-06-11 07:01:21 -04:00
|
|
|
newProjectButtonMatcher = /new project/i,
|
2024-01-16 04:40:22 -05:00
|
|
|
}: {
|
|
|
|
type?: 'Blank Project' | 'Example Project'
|
2024-06-11 07:01:21 -04:00
|
|
|
newProjectButtonMatcher?: RegExp
|
2024-01-16 04:40:22 -05:00
|
|
|
} = {}
|
2023-11-23 05:40:13 -05:00
|
|
|
): Cypress.Chainable<string> {
|
2024-06-11 07:01:21 -04:00
|
|
|
cy.findAllByRole('button').contains(newProjectButtonMatcher).click()
|
2023-11-23 05:40:13 -05:00
|
|
|
// FIXME: This should only look in the left menu
|
|
|
|
cy.findAllByText(type).first().click()
|
|
|
|
cy.findByRole('dialog').within(() => {
|
|
|
|
cy.get('input').type(name)
|
|
|
|
cy.findByText('Create').click()
|
|
|
|
})
|
|
|
|
return cy
|
|
|
|
.url()
|
|
|
|
.should('match', /\/project\/[a-fA-F0-9]{24}/)
|
|
|
|
.then(url => url.split('/').pop())
|
|
|
|
}
|
2024-07-25 11:13:52 -04:00
|
|
|
|
2024-07-29 05:56:56 -04:00
|
|
|
function shareProjectByEmail(
|
2024-07-25 11:13:52 -04:00
|
|
|
projectName: string,
|
|
|
|
email: string,
|
|
|
|
level: 'Read only' | 'Can edit'
|
|
|
|
) {
|
|
|
|
cy.visit('/project')
|
|
|
|
cy.findByText(projectName).click()
|
|
|
|
cy.findByText('Share').click()
|
|
|
|
cy.findByRole('dialog').within(() => {
|
|
|
|
cy.get('input').type(`${email},`)
|
|
|
|
cy.get('input')
|
|
|
|
.parents('form')
|
|
|
|
.within(() => cy.findByText('Can edit').parent().select(level))
|
|
|
|
cy.findByText('Share').click({ force: true })
|
|
|
|
})
|
2024-07-29 05:56:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export function shareProjectByEmailAndAcceptInviteViaDash(
|
|
|
|
projectName: string,
|
|
|
|
email: string,
|
|
|
|
level: 'Read only' | 'Can edit'
|
|
|
|
) {
|
|
|
|
shareProjectByEmail(projectName, email, level)
|
2024-07-25 11:13:52 -04:00
|
|
|
|
|
|
|
login(email)
|
|
|
|
cy.visit('/project')
|
|
|
|
cy.findByText(new RegExp(projectName))
|
|
|
|
.parent()
|
|
|
|
.parent()
|
|
|
|
.within(() => {
|
|
|
|
cy.findByText('Join Project').click()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-07-29 05:56:56 -04:00
|
|
|
export function shareProjectByEmailAndAcceptInviteViaEmail(
|
|
|
|
projectName: string,
|
|
|
|
email: string,
|
|
|
|
level: 'Read only' | 'Can edit'
|
|
|
|
) {
|
|
|
|
shareProjectByEmail(projectName, email, level)
|
|
|
|
|
|
|
|
login(email)
|
|
|
|
|
|
|
|
openEmail(projectName, frame => {
|
|
|
|
frame.contains('View project').then(a => {
|
|
|
|
cy.log(
|
|
|
|
'bypass target=_blank and navigate current browser tab/cypress-iframe to project invite'
|
|
|
|
)
|
|
|
|
cy.visit(a.attr('href')!)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
cy.url().should('match', /\/project\/[a-f0-9]+\/invite\/token\/[a-f0-9]+/)
|
|
|
|
cy.findByText(/user would like you to join/)
|
|
|
|
cy.contains(new RegExp(`You are accepting this invite as ${email}`))
|
|
|
|
cy.findByText('Join Project').click()
|
|
|
|
}
|
|
|
|
|
2024-07-25 11:13:52 -04:00
|
|
|
export function enableLinkSharing() {
|
|
|
|
let linkSharingReadOnly: string
|
|
|
|
let linkSharingReadAndWrite: string
|
|
|
|
|
|
|
|
cy.findByText('Share').click()
|
|
|
|
cy.findByText('Turn on link sharing').click()
|
|
|
|
cy.findByText('Anyone with this link can view this project')
|
|
|
|
.next()
|
|
|
|
.should('contain.text', 'http://sharelatex/')
|
|
|
|
.then(el => {
|
|
|
|
linkSharingReadOnly = el.text()
|
|
|
|
})
|
|
|
|
cy.findByText('Anyone with this link can edit this project')
|
|
|
|
.next()
|
|
|
|
.should('contain.text', 'http://sharelatex/')
|
|
|
|
.then(el => {
|
|
|
|
linkSharingReadAndWrite = el.text()
|
|
|
|
})
|
|
|
|
|
|
|
|
return cy.then(() => {
|
|
|
|
return { linkSharingReadOnly, linkSharingReadAndWrite }
|
|
|
|
})
|
|
|
|
}
|