Skip to content

Commit

Permalink
test: update accoun info tests
Browse files Browse the repository at this point in the history
  • Loading branch information
g-saracca committed Dec 4, 2024
1 parent 67de855 commit 93c4d4b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
21 changes: 21 additions & 0 deletions tests/component/sections/account/AccountInfoSection.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,25 @@ describe('AccountInfoSection', () => {
})
})
})

it('should display the user affiliation and position if present', () => {
cy.mountAuthenticated(<AccountInfoSection />, undefined, {
affiliation: 'Harvard University',
position: 'Researcher'
})

cy.findAllByRole('row').spread(
(_usernameRow, _givenNameRow, _familyNameRow, _emailRow, affiliationRow, positionRow) => {
cy.wrap(affiliationRow).within(() => {
cy.findByText('Affiliation').should('exist')
cy.findByText('Harvard University').should('exist')
})

cy.wrap(positionRow).within(() => {
cy.findByText('Position').should('exist')
cy.findByText('Researcher').should('exist')
})
}
)
})
})
5 changes: 3 additions & 2 deletions tests/component/users/domain/models/UserMother.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { User } from '../../../../../src/users/domain/models/User'

export class UserMother {
static create(): User {
static create(props?: Partial<User>): User {
return {
displayName: 'James D. Potts',
persistentId: 'jamesPotts',
Expand All @@ -10,7 +10,8 @@ export class UserMother {
email: '[email protected]',
affiliation: 'Harvard University',
superuser: false,
identifier: 'jamespotts'
identifier: 'jamespotts',
...props
}
}
static createSuperUser(): User {
Expand Down
5 changes: 3 additions & 2 deletions tests/support/commands.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import { TestsUtils } from '@tests/e2e-integration/shared/TestsUtils'
import { Utils } from '@/shared/helpers/Utils'
import { OIDC_AUTH_CONFIG } from '@/config'
import { SessionContext } from '@/sections/session/SessionContext'
import { User } from '@/users/domain/models/User'

// Define your custom mount function

Expand All @@ -68,11 +69,11 @@ Cypress.Commands.add(

Cypress.Commands.add(
'mountAuthenticated',
(component: ReactNode, initialEntries?: RouterInitialEntry[]) => {
(component: ReactNode, initialEntries?: RouterInitialEntry[], userOverrides?: Partial<User>) => {
return cy.customMount(
<SessionContext.Provider
value={{
user: UserMother.create(),
user: UserMother.create(userOverrides),
logout: () => Promise.resolve(),
setUser: () => {},
isLoadingUser: false,
Expand Down
4 changes: 3 additions & 1 deletion tests/support/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import 'react-loading-skeleton/dist/skeleton.css'
import { mount, MountReturn } from 'cypress/react18'
import { RouterInitialEntry } from './commands'
import { ReactNode } from 'react'
import { User } from '@/users/domain/models/User'

// Augment the Cypress namespace to include type definitions for
// your custom command.
Expand All @@ -42,7 +43,8 @@ declare global {
) => Cypress.Chainable<MountReturn>
mountAuthenticated: (
component: ReactNode,
initialEntries?: RouterInitialEntry[]
initialEntries?: RouterInitialEntry[],
userOverrides?: Partial<User>
) => Cypress.Chainable<MountReturn>
mountSuperuser: (
component: ReactNode,
Expand Down

0 comments on commit 93c4d4b

Please sign in to comment.