@verdaccio/ui-components 4.0.0-next-8.3 → 4.0.0-next-8.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/build/components/CopyClipboard/CopyToClipBoard.js +2 -2
  3. package/build/components/HeaderInfoDialog/HeaderInfoDialog.js +2 -2
  4. package/build/components/Heading/Heading.js +2 -2
  5. package/build/components/Help/Help.js +1 -1
  6. package/build/components/Icons/SvgIcon.js +2 -2
  7. package/build/components/Label/Label.js +2 -2
  8. package/build/components/LinkExternal/LinkExternal.js +2 -2
  9. package/build/components/NoItems/NoItems.js +2 -2
  10. package/build/components/Package/styles.js +13 -13
  11. package/build/components/Readme/Readme.spec.js +4 -2
  12. package/build/components/Readme/Readme.spec.js.map +1 -1
  13. package/build/components/Readme/utils.js +1 -1
  14. package/build/components/Search/SearchItem.js +2 -2
  15. package/build/components/SideBarTitle/SideBarTitle.js +9 -8
  16. package/build/components/TextField/TextField.js +2 -2
  17. package/build/components/Versions/HistoryList.js +6 -1
  18. package/build/components/Versions/__partials__/unsorted-versions.json +37 -0
  19. package/build/sections/Header/HeaderSettingsDialog.js +2 -2
  20. package/build/sections/SideBar/Sidebar.js +6 -6
  21. package/build/src/AppTest/App.stories.d.ts +1 -1
  22. package/build/src/components/Author/Author.stories.d.ts +1 -1
  23. package/build/src/components/Engines/Engines.stories.d.ts +1 -1
  24. package/build/src/components/SideBarTitle/SideBarTitle.d.ts +1 -1
  25. package/build/src/components/SideBarTitle/SideBarTitle.stories.d.ts +1 -0
  26. package/build/src/store/api.d.ts +3 -0
  27. package/build/src/utils/token-generate.d.ts +4 -0
  28. package/build/store/api.js +1 -1
  29. package/build/store/models/routes.js +1 -1
  30. package/build/utils/token-generate.js +33 -0
  31. package/package.json +32 -28
  32. package/src/AppTest/App.stories.tsx +1 -1
  33. package/src/components/Author/Author.stories.tsx +1 -1
  34. package/src/components/Engines/Engines.stories.tsx +12 -12
  35. package/src/components/Help/Help.tsx +1 -1
  36. package/src/components/Package/styles.ts +1 -2
  37. package/src/components/Readme/Readme.spec.tsx +2 -2
  38. package/src/components/Readme/utils.ts +2 -2
  39. package/src/components/SideBarTitle/SideBarTitle.stories.tsx +17 -4
  40. package/src/components/SideBarTitle/SideBarTitle.tsx +5 -3
  41. package/src/components/Versions/HistoryList.tsx +10 -2
  42. package/src/components/Versions/Versions.test.tsx +11 -0
  43. package/src/components/Versions/__partials__/unsorted-versions.json +37 -0
  44. package/src/sections/SideBar/Sidebar.tsx +10 -7
  45. package/src/store/api.test.ts +4 -2
  46. package/src/store/api.ts +1 -1
  47. package/src/store/models/login.test.ts +25 -19
  48. package/src/utils/token.test.ts +2 -3
  49. package/vitest.config.mjs +1 -0
  50. package/vitest/api/glob-sidebar.json +0 -12520
  51. package/vitest/api/got-sidebar.json +0 -23346
  52. package/vitest/api/home-packages.json +0 -40
  53. package/vitest/api/jquery-readme.js +0 -3
  54. package/vitest/api/jquery-sidebar.json +0 -5908
  55. package/vitest/api/search-verdaccio.json +0 -1192
  56. package/vitest/api/storybook-readme.js +0 -3
  57. package/vitest/api/storybook-sidebar.json +0 -53782
  58. package/vitest/api/storybook-v.json +0 -53782
  59. package/vitest/identity.js +0 -29
  60. package/vitest/react-markdown.tsx +0 -7
  61. package/vitest/server-handlers.ts +0 -82
  62. package/vitest/server.ts +0 -6
  63. package/vitest/setup-env.ts +0 -33
  64. package/vitest/setup.ts +0 -40
  65. package/vitest/unit/empty-string.ts +0 -1
  66. package/vitest/unit/empty.ts +0 -1
  67. package/vitest/vitestSerializer.ts +0 -31
  68. /package/{vitest/unit/components/__mocks__/token.ts → src/utils/token-generate.ts} +0 -0
@@ -17,7 +17,7 @@ export const Commonjs: Story = {
17
17
  render: () => (
18
18
  <SideBarTittle
19
19
  isLatest={false}
20
- moduleType="commonjs"
20
+ moduleTypes={['commonjs']}
21
21
  packageName="jquery"
22
22
  time="2012-12-31T06:54:14.275Z"
23
23
  version="1.0.0"
@@ -30,7 +30,7 @@ export const ES6: Story = {
30
30
  render: () => (
31
31
  <SideBarTittle
32
32
  isLatest={true}
33
- moduleType="module"
33
+ moduleTypes={['module']}
34
34
  packageName="react"
35
35
  time="2012-12-31T06:54:14.275Z"
36
36
  version="14.0.0"
@@ -38,13 +38,26 @@ export const ES6: Story = {
38
38
  ),
39
39
  };
40
40
 
41
+ export const CommonjsAndES6: Story = {
42
+ name: 'CommonJS and ES6 package',
43
+ render: () => (
44
+ <SideBarTittle
45
+ isLatest={true}
46
+ moduleTypes={['commonjs', 'module']}
47
+ packageName="jquery"
48
+ time="2012-12-31T06:54:14.275Z"
49
+ version="1.0.0"
50
+ />
51
+ ),
52
+ };
53
+
41
54
  export const Description: Story = {
42
55
  name: 'With description',
43
56
  render: () => (
44
57
  <SideBarTittle
45
58
  description="Storybook's CLI - easiest method of adding storybook to your projects"
46
59
  isLatest={true}
47
- moduleType="module"
60
+ moduleTypes={['module']}
48
61
  packageName="storybook"
49
62
  time="2012-12-31T06:54:14.275Z"
50
63
  version="14.0.0"
@@ -59,7 +72,7 @@ export const WithTypes: Story = {
59
72
  description="Storybook's CLI - easiest method of adding storybook to your projects"
60
73
  hasTypes={true}
61
74
  isLatest={true}
62
- moduleType="module"
75
+ moduleTypes={['module']}
63
76
  packageName="storybook"
64
77
  time="2012-12-31T06:54:14.275Z"
65
78
  version="14.0.0"
@@ -16,7 +16,7 @@ interface Props {
16
16
  version: string;
17
17
  isLatest: boolean;
18
18
  hasTypes?: boolean;
19
- moduleType: ModuleType | void;
19
+ moduleTypes: ModuleType[];
20
20
  time: string;
21
21
  }
22
22
 
@@ -48,7 +48,7 @@ const DetailSidebarTitle: React.FC<Props> = ({
48
48
  version,
49
49
  isLatest,
50
50
  hasTypes,
51
- moduleType,
51
+ moduleTypes,
52
52
  time,
53
53
  }) => {
54
54
  const { t } = useTranslation();
@@ -63,7 +63,9 @@ const DetailSidebarTitle: React.FC<Props> = ({
63
63
  <TypeScript />
64
64
  </Icon>
65
65
  )}
66
- <ModuleJS module={moduleType} />
66
+ {moduleTypes.map((module, index) => (
67
+ <ModuleJS key={index} module={module} />
68
+ ))}
67
69
  </>
68
70
  </TitleWrapper>
69
71
  </StyledHeading>
@@ -39,7 +39,11 @@ const VersionsHistoryList: React.FC<Props> = ({ versions, packageName, time }) =
39
39
  return (
40
40
  <List dense={true}>
41
41
  {Object.keys(listVersions)
42
- .reverse()
42
+ .sort((a, b) => {
43
+ const timeA = time[a] ? new Date(time[a]).getTime() : 0;
44
+ const timeB = time[b] ? new Date(time[b]).getTime() : 0;
45
+ return timeB - timeA;
46
+ })
43
47
  .map((version) => (
44
48
  <ListItem
45
49
  className="version-item"
@@ -48,7 +52,11 @@ const VersionsHistoryList: React.FC<Props> = ({ versions, packageName, time }) =
48
52
  sx={{ pr: 0 }}
49
53
  >
50
54
  <Link to={`${Route.DETAIL}${packageName}/v/${version}`} variant="outline">
51
- <ListItemText disableTypography={false} primary={version}></ListItemText>
55
+ <ListItemText
56
+ data-testid={`version-list-link`}
57
+ disableTypography={false}
58
+ primary={version}
59
+ />
52
60
  </Link>
53
61
  {typeof versions[version]?.deprecated === 'string' ? (
54
62
  <Chip
@@ -7,6 +7,7 @@ import { fireEvent, render, screen } from '../../test/test-react-testing-library
7
7
  import Versions, { Props } from './Versions';
8
8
  import data from './__partials__/data.json';
9
9
  import dataDeprecated from './__partials__/deprecated-versions.json';
10
+ import dataUnsorted from './__partials__/unsorted-versions.json';
10
11
 
11
12
  const VersionsComponent: React.FC<Props> = (props) => (
12
13
  <MemoryRouter>
@@ -68,5 +69,15 @@ describe('<Version /> component', () => {
68
69
  expect(screen.getByText('0.0.1')).toBeInTheDocument();
69
70
  });
70
71
 
72
+ test('should render versions sorted by timestamp in descending order', () => {
73
+ render(<VersionsComponent packageMeta={dataUnsorted} packageName={'dummy'} />);
74
+
75
+ const versionElements = screen.getAllByTestId('version-list-link');
76
+ const versions = versionElements.map((el) => el.textContent);
77
+
78
+ // Expected order based on timestamps in unsorted-versions.json:
79
+ expect(versions).toEqual(['1.0.1', '1.0.0', '0.1.1', '0.1.0']);
80
+ });
81
+
71
82
  test.todo('should click on version link');
72
83
  });
@@ -0,0 +1,37 @@
1
+ {
2
+ "versions": {
3
+ "1.0.0": {
4
+ "name": "dummy",
5
+ "version": "1.0.0"
6
+ },
7
+ "0.1.0": {
8
+ "name": "dummy",
9
+ "version": "0.1.0"
10
+ },
11
+ "0.1.1": {
12
+ "name": "dummy",
13
+ "version": "0.1.1"
14
+ },
15
+ "1.0.1": {
16
+ "name": "dummy",
17
+ "version": "1.0.1"
18
+ }
19
+ },
20
+ "time": {
21
+ "created": "2012-02-19T21:35:53.514Z",
22
+ "modified": "2024-11-21T06:32:43.761Z",
23
+ "1.0.0": "2025-01-10T14:55:23.763Z",
24
+ "0.1.0": "2012-02-19T21:35:54.455Z",
25
+ "0.1.1": "2012-02-20T06:12:03.403Z",
26
+ "1.0.1": "2025-01-10T15:11:36.318Z"
27
+ },
28
+ "users": {},
29
+ "dist-tags": {
30
+ "latest": "1.0.1"
31
+ },
32
+ "_id": "dummy",
33
+ "latest": {
34
+ "name": "dummy",
35
+ "version": "1.0.1"
36
+ }
37
+ }
@@ -13,15 +13,18 @@ import Repository from '../../components/Repository';
13
13
  import SideBarTitle from '../../components/SideBarTitle';
14
14
  import { useConfig } from '../../providers';
15
15
  import { useVersion } from '../../providers';
16
- import { PackageMetaInterface } from '../../types/packageMeta';
16
+ import { ModuleType, PackageMetaInterface } from '../../types/packageMeta';
17
+
18
+ const getModuleTypes = (manifest: PackageMetaInterface) => {
19
+ if (!manifest.latest) return [];
20
+
21
+ const moduleTypes: ModuleType[] = [manifest.latest.type || 'commonjs'];
17
22
 
18
- const getModuleType = (manifest: PackageMetaInterface) => {
19
23
  if (manifest.latest.main) {
20
- return 'commonjs';
21
- } else if (manifest.latest.type) {
22
- return manifest.latest.type;
24
+ moduleTypes.push('commonjs');
23
25
  }
24
- return;
26
+
27
+ return Array.from(new Set(moduleTypes));
25
28
  };
26
29
 
27
30
  const DetailSidebar: React.FC = () => {
@@ -40,7 +43,7 @@ const DetailSidebar: React.FC = () => {
40
43
  description={packageMeta.latest?.description}
41
44
  hasTypes={typeof packageMeta.latest?.types === 'string'}
42
45
  isLatest={typeof packageVersion === 'undefined'}
43
- moduleType={getModuleType(packageMeta)}
46
+ moduleTypes={getModuleTypes(packageMeta)}
44
47
  packageName={packageName}
45
48
  time={time}
46
49
  version={version}
@@ -1,6 +1,6 @@
1
1
  import { vi } from 'vitest';
2
2
 
3
- import api, { handleResponseType } from './api';
3
+ import api, { CustomError, handleResponseType } from './api';
4
4
 
5
5
  describe('api', () => {
6
6
  describe('handleResponseType', () => {
@@ -142,7 +142,9 @@ describe('api', () => {
142
142
  })
143
143
  );
144
144
 
145
- await expect(api.request('/resource')).rejects.toThrow(new Error('Unknown error'));
145
+ const error = new CustomError('Unknown error');
146
+ error.code = 500;
147
+ await expect(api.request('/resource')).rejects.toThrow(error);
146
148
  });
147
149
 
148
150
  test('when api returns an error 5.x.x', async () => {
package/src/store/api.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import storage from './storage';
2
2
 
3
- class CustomError extends Error {
3
+ export class CustomError extends Error {
4
4
  // @ts-ignore
5
5
  code: number;
6
6
  }
@@ -1,20 +1,24 @@
1
1
  import { vi } from 'vitest';
2
2
 
3
- // import { generateTokenWithTimeRange } from '../../../jest/unit/components/__mocks__/token';
3
+ import { generateTokenWithTimeRange } from '../../utils/token-generate';
4
4
 
5
5
  describe('getDefaultUserState', (): void => {
6
6
  const username = 'xyz';
7
7
 
8
8
  beforeEach(() => {
9
9
  vi.resetModules();
10
+ vi.resetAllMocks();
10
11
  });
11
12
 
12
13
  test('should return state with empty user', async () => {
13
14
  const token = 'token-xx-xx-xx';
14
- vi.doMock('../storage', async (importOriginal) => ({
15
- ...(await importOriginal<typeof import('../storage')>()),
16
- getItem: (key: string) => (key === 'token' ? token : username),
15
+
16
+ vi.doMock('../storage', () => ({
17
+ default: {
18
+ getItem: (key: string) => (key === 'token' ? token : username),
19
+ },
17
20
  }));
21
+
18
22
  const Login = await import('./login');
19
23
  const { getDefaultUserState } = Login;
20
24
  const result = {
@@ -24,19 +28,21 @@ describe('getDefaultUserState', (): void => {
24
28
  expect(getDefaultUserState()).toEqual(result);
25
29
  });
26
30
 
27
- // test('should return state with user from storage', async () => {
28
- // const token = generateTokenWithTimeRange(24);
29
- //
30
- // vi.doMock('../storage', async (importOriginal) => ({
31
- // ...(await importOriginal<typeof import('../storage')>()),
32
- // getItem: (key: string) => (key === 'token' ? token : username),
33
- // }));
34
- // const Login = await import('./login');
35
- // const { getDefaultUserState } = Login;
36
- // const result = {
37
- // token,
38
- // username,
39
- // };
40
- // expect(getDefaultUserState()).toEqual(result);
41
- // });
31
+ test('should return state with user from storage', async () => {
32
+ const token = generateTokenWithTimeRange(24);
33
+
34
+ vi.doMock('../storage', () => ({
35
+ default: {
36
+ getItem: (key: string) => (key === 'token' ? token : username),
37
+ },
38
+ }));
39
+
40
+ const Login = await import('./login');
41
+ const { getDefaultUserState } = Login;
42
+ const result = {
43
+ token,
44
+ username,
45
+ };
46
+ expect(getDefaultUserState()).toEqual(result);
47
+ });
42
48
  });
@@ -1,13 +1,12 @@
1
1
  import { vi } from 'vitest';
2
2
 
3
- /* eslint-disable jest/no-mocks-import */
3
+ import { isTokenExpire } from './token';
4
4
  import {
5
5
  generateInvalidToken,
6
6
  generateTokenWithExpirationAsString,
7
7
  generateTokenWithOutExpiration,
8
8
  generateTokenWithTimeRange,
9
- } from '../../vitest/unit/components/__mocks__/token';
10
- import { isTokenExpire } from './token';
9
+ } from './token-generate';
11
10
 
12
11
  /* eslint-disable no-console */
13
12
  console.error = vi.fn();
package/vitest.config.mjs CHANGED
@@ -22,6 +22,7 @@ export default defineConfig({
22
22
  '\\.(jpg)$': './vitest/unit/empty.ts',
23
23
  '\\.(md)$': './vitest/unit/empty-string.ts',
24
24
  },
25
+ testTimeout: 15000,
25
26
  },
26
27
  plugins: [
27
28
  react({