-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1072 from InseeFr/1071-enregistrement-de-la-taill…
…e-dune-distribution 1071 enregistrement de la taille dune distribution
- Loading branch information
Showing
8 changed files
with
208 additions
and
94 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
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
48 changes: 48 additions & 0 deletions
48
src/packages/modules-datasets/distributions/edit/byte-size-input.spec.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,48 @@ | ||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
import { describe, expect, it, vi } from 'vitest'; | ||
import { D1 } from '../../../deprecated-locales'; | ||
import { Distribution } from '../../../model/Dataset'; | ||
import { ByteSizeInput } from './byte-size-input'; | ||
|
||
describe('ByteSizeInput', () => { | ||
const mockDistribution = { byteSize: '1024', id: '1' } as Distribution; | ||
const mockOnChange = vi.fn(); | ||
|
||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
it('should render the label and input with correct initial value', () => { | ||
render(<ByteSizeInput value={mockDistribution} onChange={mockOnChange} />); | ||
|
||
expect(screen.getByLabelText(D1.tailleTitle)).not.toBeNull(); | ||
expect(screen.getByDisplayValue(mockDistribution.byteSize)).not.toBeNull(); | ||
}); | ||
|
||
it('should call onChange with updated byteSize when input changes', () => { | ||
render(<ByteSizeInput value={mockDistribution} onChange={mockOnChange} />); | ||
|
||
const input = screen.getByLabelText(D1.tailleTitle); | ||
fireEvent.change(input, { target: { value: '2048' } }); | ||
|
||
expect(mockOnChange).toHaveBeenCalledWith({ | ||
...mockDistribution, | ||
byteSize: '2048', | ||
}); | ||
}); | ||
|
||
it('should update input value when value prop changes', () => { | ||
const { rerender } = render( | ||
<ByteSizeInput value={mockDistribution} onChange={mockOnChange} />, | ||
); | ||
|
||
expect(screen.getByDisplayValue('1024')).not.toBeNull(); | ||
|
||
const updatedDistribution = { ...mockDistribution, byteSize: '4096' }; | ||
rerender( | ||
<ByteSizeInput value={updatedDistribution} onChange={mockOnChange} />, | ||
); | ||
|
||
expect(screen.getByDisplayValue('4096')).not.toBeNull(); | ||
}); | ||
}); |
27 changes: 27 additions & 0 deletions
27
src/packages/modules-datasets/distributions/edit/byte-size-input.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,27 @@ | ||
import { NumberInput } from '../../../components'; | ||
import { D1 } from '../../../deprecated-locales'; | ||
import { Distribution } from '../../../model/Dataset'; | ||
|
||
export const ByteSizeInput = ({ | ||
value, | ||
onChange, | ||
}: Readonly<{ | ||
value: Distribution; | ||
onChange: (distribution: Distribution) => void; | ||
}>) => { | ||
return ( | ||
<div className="col-md-12 form-group"> | ||
<label htmlFor="taille">{D1.tailleTitle}</label> | ||
<NumberInput | ||
id="taille" | ||
value={value.byteSize} | ||
onChange={(e) => | ||
onChange({ | ||
...value, | ||
byteSize: e.target.value, | ||
}) | ||
} | ||
/> | ||
</div> | ||
); | ||
}; |
33 changes: 33 additions & 0 deletions
33
src/packages/modules-datasets/distributions/view/view-main-block.spec.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,33 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import { describe, expect, it, Mock, vi } from 'vitest'; | ||
import D from '../../../deprecated-locales/build-dictionary'; | ||
import { Distribution } from '../../../model/Dataset'; | ||
import { useSecondLang } from '../../../utils/hooks/second-lang'; | ||
import { ViewMainBlock } from './view-main-block'; | ||
|
||
vi.mock('../../../utils/hooks/second-lang', () => ({ | ||
useSecondLang: vi.fn(), | ||
})); | ||
|
||
describe('ViewMainBlock', () => { | ||
const mockDistribution = { | ||
created: '2023-01-01', | ||
updated: '2023-02-01', | ||
format: 'PDF', | ||
byteSize: '15MB', | ||
url: 'http://example.com', | ||
descriptionLg1: 'Description content', | ||
} as Distribution; | ||
|
||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
(useSecondLang as Mock).mockReturnValue([false]); | ||
}); | ||
|
||
it('should render creation, modification, format, size, and URL information', () => { | ||
render(<ViewMainBlock distribution={mockDistribution} />); | ||
|
||
expect(screen.getByText(D.tailleTitle, { exact: false })).not.toBeNull(); | ||
expect(screen.getByText(/15MB/, { exact: false })).not.toBeNull(); | ||
}); | ||
}); |
70 changes: 70 additions & 0 deletions
70
src/packages/modules-datasets/distributions/view/view-main-block.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,70 @@ | ||
import { PublicationFemale, Row } from '../../../components'; | ||
import { Note } from '../../../components/note'; | ||
import D, { D1, D2 } from '../../../deprecated-locales/build-dictionary'; | ||
import { Distribution } from '../../../model/Dataset'; | ||
import { stringToDate } from '../../../utils/date-utils'; | ||
import { useSecondLang } from '../../../utils/hooks/second-lang'; | ||
import { renderMarkdownElement } from '../../../utils/html-utils'; | ||
|
||
export const ViewMainBlock = ({ | ||
distribution, | ||
}: Readonly<{ distribution: Distribution }>) => { | ||
const [secondLang] = useSecondLang(); | ||
|
||
return ( | ||
<> | ||
<Row> | ||
<Note | ||
text={ | ||
<ul> | ||
<li> | ||
{D.createdDateTitle} : {stringToDate(distribution.created)}{' '} | ||
</li> | ||
<li> | ||
{D.modifiedDateTitle} : {stringToDate(distribution.updated)}{' '} | ||
</li> | ||
<li> | ||
{D.distributionStatus} : | ||
<PublicationFemale object={distribution} /> | ||
</li> | ||
<li> | ||
{D.formatTitle} : {distribution.format}{' '} | ||
</li> | ||
<li> | ||
{D.tailleTitle} : {distribution.byteSize}{' '} | ||
</li> | ||
<li> | ||
{D.downloadUrlTitle} :{' '} | ||
<a | ||
target="_blank" | ||
rel="noreferrer noopener" | ||
href={distribution.url} | ||
> | ||
{distribution.url}{' '} | ||
</a> | ||
</li> | ||
</ul> | ||
} | ||
title={D1.globalInformationsTitle} | ||
alone={true} | ||
/> | ||
</Row> | ||
<Row> | ||
<Note | ||
text={renderMarkdownElement(distribution.descriptionLg1)} | ||
title={D1.descriptionTitle} | ||
alone={!secondLang} | ||
allowEmpty={true} | ||
/> | ||
{secondLang && ( | ||
<Note | ||
text={renderMarkdownElement(distribution.descriptionLg1)} | ||
title={D2.descriptionTitle} | ||
alone={false} | ||
allowEmpty={true} | ||
/> | ||
)} | ||
</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