Skip to content

Commit

Permalink
test: add cases for unauthenticated users redirection
Browse files Browse the repository at this point in the history
  • Loading branch information
g-saracca committed Sep 9, 2024
1 parent d8986a9 commit 436ebf7
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,12 @@ describe('Create Collection', () => {
cy.findByRole('heading', { name: collectionName }).should('exist')
cy.findByText('Success!').should('exist')
})

it('redirects to the Log i¡In page when the user is not authenticated', () => {
cy.wrap(TestsUtils.logout())

cy.visit('/spa/collections/root/create')
cy.get('#login-container').should('exist')
cy.url().should('include', '/loginpage.xhtml')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,12 @@ describe('Create Dataset', () => {

cy.findByRole('heading', { name: 'Root' }).should('exist')
})

it('redirects to the Log In page when the user is not authenticated', () => {
cy.wrap(TestsUtils.logout())

cy.visit('/spa/datasets/create')
cy.get('#login-container').should('exist')
cy.url().should('include', '/loginpage.xhtml')
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { faker } from '@faker-js/faker'
import { TestsUtils } from '../../../shared/TestsUtils'
import {
DatasetLabelValue,
DatasetNonNumericVersionSearchParam
} from '../../../../../src/dataset/domain/models/Dataset'
import { DatasetHelper } from '../../../shared/datasets/DatasetHelper'
import { QueryParamKey, Route } from '../../../../../src/sections/Route.enum'

describe('Edit Dataset metadata', () => {
before(() => {
TestsUtils.setup()
})

beforeEach(() => {
TestsUtils.login()
})

it('visits the Edit Dataset Metadata Page as a logged in user', () => {
const datasetTitle = faker.lorem.sentence()

cy.wrap(DatasetHelper.createWithTitle(datasetTitle), { timeout: 10000 }).then((dataset) => {
const searchParams = new URLSearchParams()
searchParams.set(QueryParamKey.PERSISTENT_ID, dataset.persistentId)
searchParams.set(QueryParamKey.VERSION, DatasetNonNumericVersionSearchParam.DRAFT)

const editDatasetMetadataUrl = `/spa${Route.EDIT_DATASET_METADATA}?${searchParams.toString()}`

cy.visit(editDatasetMetadataUrl)

cy.findByRole('link', { name: 'Root' })
.closest('.breadcrumb')
.within(() => {
cy.findByRole('link', { name: datasetTitle }).should('exist')
cy.findByText('Edit Dataset Metadata').should('exist')
})
})
})

it('navigates to the edited dataset after submitting a valid form', () => {
const datasetTitle = faker.lorem.sentence()

cy.wrap(DatasetHelper.createWithTitle(datasetTitle), { timeout: 10000 }).then((dataset) => {
const searchParams = new URLSearchParams()
searchParams.set(QueryParamKey.PERSISTENT_ID, dataset.persistentId)
searchParams.set(QueryParamKey.VERSION, DatasetNonNumericVersionSearchParam.DRAFT)

const editDatasetMetadataUrl = `/spa${Route.EDIT_DATASET_METADATA}?${searchParams.toString()}`

cy.visit(editDatasetMetadataUrl)

cy.findByLabelText(/^Title/i)
.clear({ force: true })
.type('Edited title', { force: true })

cy.findAllByText(/Save Changes/i)
.first()
.click({ force: true })

cy.findByRole('heading', { name: 'Edited title' }).should('exist')
cy.findByText('Success!').should('exist')
cy.contains('The metadata for this dataset has been updated.').should('exist')
cy.findByText(DatasetLabelValue.DRAFT).should('exist')
cy.findByText(DatasetLabelValue.UNPUBLISHED).should('exist')
})
})

it('redirects to the Log In page when the user is not authenticated', () => {
cy.wrap(TestsUtils.logout())

const datasetTitle = faker.lorem.sentence()

cy.wrap(DatasetHelper.createWithTitle(datasetTitle), { timeout: 10000 }).then((dataset) => {
const searchParams = new URLSearchParams()
searchParams.set(QueryParamKey.PERSISTENT_ID, dataset.persistentId)
searchParams.set(QueryParamKey.VERSION, DatasetNonNumericVersionSearchParam.DRAFT)

const editDatasetMetadataUrl = `/spa${Route.EDIT_DATASET_METADATA}?${searchParams.toString()}`

cy.visit(editDatasetMetadataUrl)

cy.get('#login-container').should('exist')
cy.url().should('include', '/loginpage.xhtml')
})
})
})

0 comments on commit 436ebf7

Please sign in to comment.