-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { StoryFn } from '@storybook/react' | ||
import { AuthContext } from 'react-oauth2-code-pkce' | ||
import { AuthContextMother } from '@tests/component/auth/AuthContextMother' | ||
|
||
export const WithOIDCAuthContext = (Story: StoryFn) => { | ||
return ( | ||
<AuthContext.Provider | ||
value={{ | ||
token: AuthContextMother.createToken(), | ||
idToken: AuthContextMother.createToken(), | ||
logIn: () => {}, | ||
logOut: () => {}, | ||
loginInProgress: false, | ||
tokenData: AuthContextMother.createTokenData(), | ||
idTokenData: AuthContextMother.createTokenData(), | ||
error: null, | ||
login: () => {} // 👈 deprecated | ||
}}> | ||
<Story /> | ||
</AuthContext.Provider> | ||
) | ||
} |
13 changes: 13 additions & 0 deletions
13
src/stories/shared-mock-repositories/info/DataverseInfoMockLoadingkRepository.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { DataverseInfoMockRepository } from './DataverseInfoMockRepository' | ||
import { DataverseVersion } from '@/info/domain/models/DataverseVersion' | ||
import { TermsOfUse } from '@/info/domain/models/TermsOfUse' | ||
|
||
export class DataverseInfoMockLoadingRepository implements DataverseInfoMockRepository { | ||
getVersion(): Promise<DataverseVersion> { | ||
return new Promise(() => {}) | ||
} | ||
|
||
getTermsOfUse(): Promise<TermsOfUse> { | ||
return new Promise(() => {}) | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/stories/shared-mock-repositories/info/DataverseInfoMockRepository.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { DataverseVersion } from '@/info/domain/models/DataverseVersion' | ||
import { TermsOfUse } from '@/info/domain/models/TermsOfUse' | ||
import { DataverseInfoRepository } from '@/info/domain/repositories/DataverseInfoRepository' | ||
import { DataverseVersionMother } from '@tests/component/info/models/DataverseVersionMother' | ||
import { TermsOfUseMother } from '@tests/component/info/models/TermsOfUseMother' | ||
|
||
export class DataverseInfoMockRepository implements DataverseInfoRepository { | ||
getVersion(): Promise<DataverseVersion> { | ||
return new Promise((resolve) => { | ||
setTimeout(() => { | ||
resolve(DataverseVersionMother.create()) | ||
}, 1_000) | ||
}) | ||
} | ||
|
||
getTermsOfUse(): Promise<TermsOfUse> { | ||
return new Promise((resolve) => { | ||
setTimeout(() => { | ||
resolve(TermsOfUseMother.create()) | ||
}, 1_000) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import type { StoryObj, Meta } from '@storybook/react' | ||
import { WithLayout } from '../WithLayout' | ||
import { WithI18next } from '../WithI18next' | ||
import { SignUp } from '@/sections/sign-up/SignUp' | ||
import { DataverseInfoMockRepository } from '../shared-mock-repositories/info/DataverseInfoMockRepository' | ||
import { DataverseInfoMockLoadingRepository } from '../shared-mock-repositories/info/DataverseInfoMocLoadingkRepository' | ||
import { WithOIDCAuthContext } from '../WithOIDCAuthContext' | ||
|
||
// TODO:ME - After implementing register use case in js-dataverse, we should mock the register function here also. | ||
|
||
const meta: Meta<typeof SignUp> = { | ||
title: 'Pages/Sign Up', | ||
component: SignUp, | ||
decorators: [WithI18next, WithLayout, WithOIDCAuthContext], | ||
parameters: { | ||
// Sets the delay for all stories. | ||
chromatic: { delay: 15000, pauseAnimationAtEnd: true } | ||
} | ||
} | ||
export default meta | ||
type Story = StoryObj<typeof SignUp> | ||
|
||
export const ValidTokenWithNotLinkedAccount: Story = { | ||
render: () => ( | ||
<SignUp | ||
dataverseInfoRepository={new DataverseInfoMockRepository()} | ||
hasValidTokenButNotLinkedAccount | ||
/> | ||
) | ||
} | ||
|
||
export const Loading: Story = { | ||
render: () => ( | ||
<SignUp | ||
dataverseInfoRepository={new DataverseInfoMockLoadingRepository()} | ||
hasValidTokenButNotLinkedAccount | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
export class AuthContextMother { | ||
static createToken() { | ||
return 'some.fake.token' | ||
} | ||
|
||
static createTokenData() { | ||
return { | ||
exp: 1732803352, | ||
iat: 1732803052, | ||
auth_time: 1732799407, | ||
jti: 'some-fake-jti-number', | ||
iss: 'http://localhost:8000/realms/test', | ||
aud: 'account', | ||
sub: 'some-fake-sub-number', | ||
typ: 'Bearer', | ||
azp: 'test', | ||
session_state: 'some-fake-session-state-number', | ||
acr: '0', | ||
realm_access: { | ||
roles: ['default-roles-test', 'offline_access', 'uma_authorization'] | ||
}, | ||
resource_access: { | ||
account: { | ||
roles: ['manage-account', 'manage-account-links', 'view-profile'] | ||
} | ||
}, | ||
scope: 'openid profile email', | ||
sid: 'some-fake-sid-number', | ||
email_verified: true, | ||
name: 'Dataverse User', | ||
preferred_username: 'user', | ||
given_name: 'Dataverse', | ||
family_name: 'User', | ||
email: '[email protected]' | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { faker } from '@faker-js/faker' | ||
import isChromatic from 'chromatic/isChromatic' | ||
import { TermsOfUse } from '@/info/domain/models/TermsOfUse' | ||
|
||
export class TermsOfUseMother { | ||
static create(): TermsOfUse { | ||
return isChromatic() ? 'https://some-terms-of-use-url.com' : faker.lorem.paragraphs(8) | ||
} | ||
|
||
static createEmpty(): TermsOfUse { | ||
return 'There are no API Terms of Use for this Dataverse installation.' | ||
} | ||
} |