Merge pull request #18170 from overleaf/ae-token-access-page
Convert token access page to React GitOrigin-RevId: d7434f0de395c47a95d00767727fbe9d43f9abca
This commit is contained in:
@@ -0,0 +1,168 @@
|
||||
import TokenAccessPage from '@/features/token-access/components/token-access-root'
|
||||
import { location } from '@/shared/components/location'
|
||||
|
||||
describe('<TokenAccessPage/>', function () {
|
||||
// this is a URL for a read-only token, but the process is the same for read-write tokens
|
||||
const url = '/read/123/grant'
|
||||
|
||||
beforeEach(function () {
|
||||
cy.window().then(win => {
|
||||
win.metaAttributesCache = new Map<string, any>([
|
||||
['ol-postUrl', url],
|
||||
['ol-user', { email: 'test@example.com' }],
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
it('handles a successful token access request', function () {
|
||||
cy.intercept(
|
||||
{ method: 'post', url, times: 1 },
|
||||
{
|
||||
body: {
|
||||
requireAccept: { projectName: 'Test Project' },
|
||||
},
|
||||
}
|
||||
).as('grantRequest')
|
||||
|
||||
cy.mount(<TokenAccessPage />)
|
||||
|
||||
cy.wait('@grantRequest').then(interception => {
|
||||
expect(interception.request.body.confirmedByUser).to.be.false
|
||||
})
|
||||
|
||||
cy.get('h1').should(
|
||||
'have.text',
|
||||
['You have been invited to join', 'Test Project'].join('')
|
||||
)
|
||||
|
||||
cy.contains('You are accepting this invite as test@example.com')
|
||||
|
||||
cy.intercept(
|
||||
{ method: 'post', url, times: 1 },
|
||||
{
|
||||
body: {
|
||||
redirect: '/project/123',
|
||||
},
|
||||
}
|
||||
).as('confirmedGrantRequest')
|
||||
|
||||
cy.stub(location, 'replace').as('replaceLocation')
|
||||
|
||||
cy.findByRole('button', { name: 'Join Project' }).click()
|
||||
|
||||
cy.wait('@confirmedGrantRequest').then(interception => {
|
||||
expect(interception.request.body.confirmedByUser).to.be.true
|
||||
})
|
||||
|
||||
cy.get('@replaceLocation').should(
|
||||
'have.been.calledOnceWith',
|
||||
'/project/123'
|
||||
)
|
||||
})
|
||||
|
||||
it('handles a project not found response', function () {
|
||||
cy.intercept({ method: 'post', url, times: 1 }, { statusCode: 404 }).as(
|
||||
'grantRequest'
|
||||
)
|
||||
|
||||
cy.mount(<TokenAccessPage />)
|
||||
|
||||
cy.wait('@grantRequest')
|
||||
|
||||
cy.get('h3').should('have.text', 'Join Project')
|
||||
cy.get('h4').should('have.text', 'Project not found')
|
||||
|
||||
cy.findByRole('button', { name: 'Join Project' }).should('not.exist')
|
||||
})
|
||||
|
||||
it('handles a redirect response', function () {
|
||||
cy.intercept(
|
||||
{ method: 'post', url, times: 1 },
|
||||
{
|
||||
body: {
|
||||
redirect: '/restricted',
|
||||
},
|
||||
}
|
||||
).as('grantRequest')
|
||||
|
||||
cy.stub(location, 'replace').as('replaceLocation')
|
||||
|
||||
cy.mount(<TokenAccessPage />)
|
||||
|
||||
cy.wait('@grantRequest')
|
||||
|
||||
cy.get('@replaceLocation').should('have.been.calledOnceWith', '/restricted')
|
||||
})
|
||||
|
||||
it('handles a v1 "must login" response', function () {
|
||||
cy.intercept(
|
||||
{ method: 'post', url, times: 1 },
|
||||
{
|
||||
body: {
|
||||
v1Import: { status: 'mustLogin' },
|
||||
},
|
||||
}
|
||||
).as('grantRequest')
|
||||
|
||||
cy.stub(location, 'replace').as('replaceLocation')
|
||||
|
||||
cy.mount(<TokenAccessPage />)
|
||||
|
||||
cy.wait('@grantRequest')
|
||||
|
||||
cy.get('h1').should('have.text', 'Please log in')
|
||||
|
||||
cy.findByRole('link', { name: 'Log in to access project' })
|
||||
.should('have.attr', 'href')
|
||||
.and('match', /^\/login\?redir=/)
|
||||
})
|
||||
|
||||
it('handles a v1 "cannot import" response', function () {
|
||||
cy.intercept(
|
||||
{ method: 'post', url, times: 1 },
|
||||
{
|
||||
body: {
|
||||
v1Import: { status: 'cannotImport' },
|
||||
},
|
||||
}
|
||||
).as('grantRequest')
|
||||
|
||||
cy.stub(location, 'replace').as('replaceLocation')
|
||||
|
||||
cy.mount(<TokenAccessPage />)
|
||||
|
||||
cy.wait('@grantRequest')
|
||||
|
||||
cy.get('h1').should('have.text', 'Overleaf v1 Project')
|
||||
cy.get('h2').should('have.text', 'Cannot Access Overleaf v1 Project')
|
||||
})
|
||||
|
||||
it('handles a v1 "can download zip" response', function () {
|
||||
cy.intercept(
|
||||
{ method: 'post', url, times: 1 },
|
||||
{
|
||||
body: {
|
||||
v1Import: {
|
||||
status: 'canDownloadZip',
|
||||
projectId: '123',
|
||||
name: 'Test Project',
|
||||
},
|
||||
},
|
||||
}
|
||||
).as('grantRequest')
|
||||
|
||||
cy.stub(location, 'replace').as('replaceLocation')
|
||||
|
||||
cy.mount(<TokenAccessPage />)
|
||||
|
||||
cy.wait('@grantRequest')
|
||||
|
||||
cy.get('h1').should('have.text', 'Overleaf v1 Project')
|
||||
|
||||
cy.findByRole('link', { name: 'Download project zip file' }).should(
|
||||
'have.attr',
|
||||
'href',
|
||||
'/overleaf/project/123/download/zip'
|
||||
)
|
||||
})
|
||||
})
|
||||
+1
@@ -14,6 +14,7 @@ describe('<ActionsCopyProject />', function () {
|
||||
assignStub = sinon.stub()
|
||||
this.locationStub = sinon.stub(useLocationModule, 'useLocation').returns({
|
||||
assign: assignStub,
|
||||
replace: sinon.stub(),
|
||||
reload: sinon.stub(),
|
||||
})
|
||||
})
|
||||
|
||||
+1
@@ -12,6 +12,7 @@ describe('<ModalContentNewProjectForm />', function () {
|
||||
assignStub = sinon.stub()
|
||||
this.locationStub = sinon.stub(useLocationModule, 'useLocation').returns({
|
||||
assign: assignStub,
|
||||
replace: sinon.stub(),
|
||||
reload: sinon.stub(),
|
||||
})
|
||||
})
|
||||
|
||||
@@ -699,6 +699,7 @@ describe('<UserNotifications />', function () {
|
||||
assignStub = sinon.stub()
|
||||
this.locationStub = sinon.stub(useLocationModule, 'useLocation').returns({
|
||||
assign: assignStub,
|
||||
replace: sinon.stub(),
|
||||
reload: sinon.stub(),
|
||||
})
|
||||
fetchMock.reset()
|
||||
|
||||
@@ -57,6 +57,7 @@ describe('<ProjectListRoot />', function () {
|
||||
assignStub = sinon.stub()
|
||||
this.locationStub = sinon.stub(useLocationModule, 'useLocation').returns({
|
||||
assign: assignStub,
|
||||
replace: sinon.stub(),
|
||||
reload: sinon.stub(),
|
||||
})
|
||||
})
|
||||
|
||||
+1
@@ -17,6 +17,7 @@ describe('<CompileAndDownloadProjectPDFButton />', function () {
|
||||
assignStub = sinon.stub()
|
||||
locationStub = sinon.stub(useLocationModule, 'useLocation').returns({
|
||||
assign: assignStub,
|
||||
replace: sinon.stub(),
|
||||
reload: sinon.stub(),
|
||||
})
|
||||
render(
|
||||
|
||||
+1
@@ -12,6 +12,7 @@ describe('<DownloadProjectButton />', function () {
|
||||
assignStub = sinon.stub()
|
||||
this.locationStub = sinon.stub(useLocationModule, 'useLocation').returns({
|
||||
assign: assignStub,
|
||||
replace: sinon.stub(),
|
||||
reload: sinon.stub(),
|
||||
})
|
||||
render(<DownloadProjectButtonTooltip project={projectsData[0]} />)
|
||||
|
||||
+1
@@ -35,6 +35,7 @@ describe('<ReconfirmationInfo/>', function () {
|
||||
assignStub = sinon.stub()
|
||||
this.locationStub = sinon.stub(useLocationModule, 'useLocation').returns({
|
||||
assign: assignStub,
|
||||
replace: sinon.stub(),
|
||||
reload: sinon.stub(),
|
||||
})
|
||||
})
|
||||
|
||||
@@ -61,6 +61,7 @@ describe('<LeaveModalForm />', function () {
|
||||
assignStub = sinon.stub()
|
||||
this.locationStub = sinon.stub(useLocationModule, 'useLocation').returns({
|
||||
assign: assignStub,
|
||||
replace: sinon.stub(),
|
||||
reload: sinon.stub(),
|
||||
})
|
||||
window.metaAttributesCache.set('ol-ExposedSettings', { isOverleaf: true })
|
||||
|
||||
+1
@@ -88,6 +88,7 @@ describe('<ShareProjectModal/>', function () {
|
||||
beforeEach(function () {
|
||||
this.locationStub = sinon.stub(useLocationModule, 'useLocation').returns({
|
||||
assign: sinon.stub(),
|
||||
replace: sinon.stub(),
|
||||
reload: sinon.stub(),
|
||||
})
|
||||
fetchMock.get('/user/contacts', { contacts })
|
||||
|
||||
+1
@@ -82,6 +82,7 @@ describe('<GroupSubscriptionMemberships />', function () {
|
||||
reloadStub = sinon.stub()
|
||||
this.locationStub = sinon.stub(useLocationModule, 'useLocation').returns({
|
||||
assign: sinon.stub(),
|
||||
replace: sinon.stub(),
|
||||
reload: reloadStub,
|
||||
})
|
||||
|
||||
|
||||
+1
@@ -54,6 +54,7 @@ describe('<PersonalSubscription />', function () {
|
||||
reloadStub = sinon.stub()
|
||||
this.locationStub = sinon.stub(useLocationModule, 'useLocation').returns({
|
||||
assign: sinon.stub(),
|
||||
replace: sinon.stub(),
|
||||
reload: reloadStub,
|
||||
})
|
||||
})
|
||||
|
||||
+1
@@ -196,6 +196,7 @@ describe('<ActiveSubscription />', function () {
|
||||
beforeEach(function () {
|
||||
this.locationStub = sinon.stub(useLocationModule, 'useLocation').returns({
|
||||
assign: assignStub,
|
||||
replace: sinon.stub(),
|
||||
reload: reloadStub,
|
||||
})
|
||||
})
|
||||
|
||||
+1
@@ -31,6 +31,7 @@ describe('<ChangePlanModal />', function () {
|
||||
reloadStub = sinon.stub()
|
||||
this.locationStub = sinon.stub(useLocationModule, 'useLocation').returns({
|
||||
assign: sinon.stub(),
|
||||
replace: sinon.stub(),
|
||||
reload: reloadStub,
|
||||
})
|
||||
})
|
||||
|
||||
@@ -66,6 +66,12 @@ describe('TokenAccessController', function () {
|
||||
},
|
||||
}
|
||||
|
||||
this.SplitTestHandler = {
|
||||
promises: {
|
||||
getAssignment: sinon.stub().resolves({ variant: 'default' }),
|
||||
},
|
||||
}
|
||||
|
||||
this.TokenAccessController = SandboxedModule.require(MODULE_PATH, {
|
||||
requires: {
|
||||
'@overleaf/settings': this.Settings,
|
||||
@@ -77,6 +83,7 @@ describe('TokenAccessController', function () {
|
||||
'../Authorization/AuthorizationMiddleware':
|
||||
this.AuthorizationMiddleware,
|
||||
'../Project/ProjectAuditLogHandler': this.ProjectAuditLogHandler,
|
||||
'../SplitTests/SplitTestHandler': this.SplitTestHandler,
|
||||
'../Errors/Errors': (this.Errors = { NotFoundError: sinon.stub() }),
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user