mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-04-01 02:42:23 -05:00
parent
4b16136a05
commit
69f2e66b92
4 changed files with 63 additions and 2 deletions
5
.changeset/bright-bobcats-ring.md
Normal file
5
.changeset/bright-bobcats-ring.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@verdaccio/ui-components': patch
|
||||
---
|
||||
|
||||
fix(ui): sort versions
|
|
@ -39,7 +39,11 @@ const VersionsHistoryList: React.FC<Props> = ({ versions, packageName, time }) =
|
|||
return (
|
||||
<List dense={true}>
|
||||
{Object.keys(listVersions)
|
||||
.reverse()
|
||||
.sort((a, b) => {
|
||||
const timeA = time[a] ? new Date(time[a]).getTime() : 0;
|
||||
const timeB = time[b] ? new Date(time[b]).getTime() : 0;
|
||||
return timeB - timeA;
|
||||
})
|
||||
.map((version) => (
|
||||
<ListItem
|
||||
className="version-item"
|
||||
|
@ -48,7 +52,11 @@ const VersionsHistoryList: React.FC<Props> = ({ versions, packageName, time }) =
|
|||
sx={{ pr: 0 }}
|
||||
>
|
||||
<Link to={`${Route.DETAIL}${packageName}/v/${version}`} variant="outline">
|
||||
<ListItemText disableTypography={false} primary={version}></ListItemText>
|
||||
<ListItemText
|
||||
data-testid={`version-list-link`}
|
||||
disableTypography={false}
|
||||
primary={version}
|
||||
/>
|
||||
</Link>
|
||||
{typeof versions[version]?.deprecated === 'string' ? (
|
||||
<Chip
|
||||
|
|
|
@ -7,6 +7,7 @@ import { fireEvent, render, screen } from '../../test/test-react-testing-library
|
|||
import Versions, { Props } from './Versions';
|
||||
import data from './__partials__/data.json';
|
||||
import dataDeprecated from './__partials__/deprecated-versions.json';
|
||||
import dataUnsorted from './__partials__/unsorted-versions.json';
|
||||
|
||||
const VersionsComponent: React.FC<Props> = (props) => (
|
||||
<MemoryRouter>
|
||||
|
@ -68,5 +69,15 @@ describe('<Version /> component', () => {
|
|||
expect(screen.getByText('0.0.1')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('should render versions sorted by timestamp in descending order', () => {
|
||||
render(<VersionsComponent packageMeta={dataUnsorted} packageName={'dummy'} />);
|
||||
|
||||
const versionElements = screen.getAllByTestId('version-list-link');
|
||||
const versions = versionElements.map((el) => el.textContent);
|
||||
|
||||
// Expected order based on timestamps in unsorted-versions.json:
|
||||
expect(versions).toEqual(['1.0.1', '1.0.0', '0.1.1', '0.1.0']);
|
||||
});
|
||||
|
||||
test.todo('should click on version link');
|
||||
});
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
{
|
||||
"versions": {
|
||||
"1.0.0": {
|
||||
"name": "dummy",
|
||||
"version": "1.0.0"
|
||||
},
|
||||
"0.1.0": {
|
||||
"name": "dummy",
|
||||
"version": "0.1.0"
|
||||
},
|
||||
"0.1.1": {
|
||||
"name": "dummy",
|
||||
"version": "0.1.1"
|
||||
},
|
||||
"1.0.1": {
|
||||
"name": "dummy",
|
||||
"version": "1.0.1"
|
||||
}
|
||||
},
|
||||
"time": {
|
||||
"created": "2012-02-19T21:35:53.514Z",
|
||||
"modified": "2024-11-21T06:32:43.761Z",
|
||||
"1.0.0": "2025-01-10T14:55:23.763Z",
|
||||
"0.1.0": "2012-02-19T21:35:54.455Z",
|
||||
"0.1.1": "2012-02-20T06:12:03.403Z",
|
||||
"1.0.1": "2025-01-10T15:11:36.318Z"
|
||||
},
|
||||
"users": {},
|
||||
"dist-tags": {
|
||||
"latest": "1.0.1"
|
||||
},
|
||||
"_id": "dummy",
|
||||
"latest": {
|
||||
"name": "dummy",
|
||||
"version": "1.0.1"
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue