-
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.
feat: get terms of use repository convention
- Loading branch information
Showing
12 changed files
with
184 additions
and
30 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 @@ | ||
export type TermsOfUse = string | null |
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import { DataverseVersion } from '../models/DataverseVersion' | ||
import { TermsOfUse } from '../models/TermsOfUse' | ||
|
||
export interface DataverseInfoRepository { | ||
getVersion(): Promise<DataverseVersion> | ||
getTermsOfUse: () => Promise<TermsOfUse> | ||
} |
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,10 @@ | ||
import { type TermsOfUse } from '../../../info/domain/models/TermsOfUse' | ||
import { DataverseInfoRepository } from '../repositories/DataverseInfoRepository' | ||
|
||
export function getTermsOfUse( | ||
dataverseInfoRepository: DataverseInfoRepository | ||
): Promise<TermsOfUse> { | ||
return dataverseInfoRepository.getTermsOfUse().catch((error) => { | ||
throw error | ||
}) | ||
} |
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
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
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
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
46 changes: 46 additions & 0 deletions
46
src/sections/sign-up/valid-token-not-linked-account-form/FormFieldsSkeleton.tsx
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,46 @@ | ||
import Skeleton, { SkeletonTheme } from 'react-loading-skeleton' | ||
import { Col, Row, Stack } from '@iqss/dataverse-design-system' | ||
|
||
export const FormFieldsSkeleton = () => ( | ||
<SkeletonTheme> | ||
<section data-testid="form-fields-skeleton"> | ||
<LabelAndFieldSkeleton withHelperText /> | ||
<LabelAndFieldSkeleton /> | ||
<LabelAndFieldSkeleton /> | ||
<LabelAndFieldSkeleton /> | ||
<LabelAndFieldSkeleton /> | ||
<LabelAndFieldSkeleton /> | ||
<LabelAndFieldSkeleton termsOfUse /> | ||
|
||
<Stack direction="horizontal" className="pt-3"> | ||
<Skeleton width={120} height={38} /> | ||
<Skeleton width={80} height={38} /> | ||
</Stack> | ||
</section> | ||
</SkeletonTheme> | ||
) | ||
|
||
interface LabelAndFieldSkeletonProps { | ||
withHelperText?: boolean | ||
termsOfUse?: boolean | ||
} | ||
|
||
const LabelAndFieldSkeleton = ({ withHelperText, termsOfUse }: LabelAndFieldSkeletonProps) => ( | ||
<Row style={{ marginBottom: 16 }}> | ||
<Col md={3} className="text-end"> | ||
<Skeleton width={120} /> | ||
</Col> | ||
<Col md={6}> | ||
<Stack gap={2}> | ||
{withHelperText && <Skeleton width="100%" height={26} />} | ||
<Skeleton width="100%" height={termsOfUse ? 60 : 38} /> | ||
{termsOfUse && ( | ||
<Stack direction="horizontal" gap={2}> | ||
<Skeleton width={16} height={16} /> | ||
<Skeleton width={300} height={16} /> | ||
</Stack> | ||
)} | ||
</Stack> | ||
</Col> | ||
</Row> | ||
) |
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
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
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
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,62 @@ | ||
import { act, renderHook } from '@testing-library/react' | ||
import { useGetTermsOfUse } from '@/shared/hooks/useGetTermsOfUse' | ||
import { DataverseInfoRepository } from '@/info/domain/repositories/DataverseInfoRepository' | ||
import { TermsOfUseMother } from '@tests/component/info/models/TermsOfUseMother' | ||
|
||
const dataverseInfoRepository: DataverseInfoRepository = {} as DataverseInfoRepository | ||
const termsOfUseMock = TermsOfUseMother.create() | ||
|
||
describe('useGetTermsOfUse', () => { | ||
it('should return terms of use correctly', async () => { | ||
dataverseInfoRepository.getTermsOfUse = cy.stub().resolves(termsOfUseMock) | ||
|
||
const { result } = renderHook(() => useGetTermsOfUse(dataverseInfoRepository)) | ||
|
||
await act(() => { | ||
expect(result.current.isLoading).to.deep.equal(true) | ||
return expect(result.current.termsOfUse).to.deep.equal(null) | ||
}) | ||
|
||
await act(() => { | ||
expect(result.current.isLoading).to.deep.equal(false) | ||
|
||
return expect(result.current.termsOfUse).to.deep.equal(termsOfUseMock) | ||
}) | ||
}) | ||
|
||
describe('Error handling', () => { | ||
it('should return correct error message when there is an error type catched', async () => { | ||
dataverseInfoRepository.getTermsOfUse = cy.stub().rejects(new Error('Error message')) | ||
|
||
const { result } = renderHook(() => useGetTermsOfUse(dataverseInfoRepository)) | ||
|
||
await act(() => { | ||
expect(result.current.isLoading).to.deep.equal(true) | ||
return expect(result.current.error).to.deep.equal(null) | ||
}) | ||
|
||
await act(() => { | ||
expect(result.current.isLoading).to.deep.equal(false) | ||
return expect(result.current.error).to.deep.equal('Error message') | ||
}) | ||
}) | ||
|
||
it('should return correct error message when there is not an error type catched', async () => { | ||
dataverseInfoRepository.getTermsOfUse = cy.stub().rejects('Error message') | ||
|
||
const { result } = renderHook(() => useGetTermsOfUse(dataverseInfoRepository)) | ||
|
||
await act(() => { | ||
expect(result.current.isLoading).to.deep.equal(true) | ||
return expect(result.current.error).to.deep.equal(null) | ||
}) | ||
|
||
await act(() => { | ||
expect(result.current.isLoading).to.deep.equal(false) | ||
return expect(result.current.error).to.deep.equal( | ||
'Something went wrong getting the use of terms. Try again later.' | ||
) | ||
}) | ||
}) | ||
}) | ||
}) |