piral-breadcrumbs 1.3.3-beta.6190 → 1.3.3-beta.6204

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "piral-breadcrumbs",
3
- "version": "1.3.3-beta.6190",
3
+ "version": "1.3.3-beta.6204",
4
4
  "description": "Plugin for creating a breadcrumb manager in Piral.",
5
5
  "keywords": [
6
6
  "piral",
@@ -63,9 +63,9 @@
63
63
  "devDependencies": {
64
64
  "@types/react": "^18.0.0",
65
65
  "@types/react-router": "^5.1.8",
66
- "piral-core": "1.3.3-beta.6190",
66
+ "piral-core": "1.3.3-beta.6204",
67
67
  "react": "^18.0.0",
68
68
  "react-router": "^5.2.0"
69
69
  },
70
- "gitHead": "dc3358f0e08b06acea2056b612f268334a8c49c8"
70
+ "gitHead": "8a1fa7b847b0e146a5bdb8e0497c436fffe4fd4d"
71
71
  }
@@ -1,6 +1,10 @@
1
+ /**
2
+ * @vitest-environment jsdom
3
+ */
1
4
  import * as React from 'react';
2
5
  import create from 'zustand';
3
- import { render } from '@testing-library/react';
6
+ import { describe, it, expect, vitest, afterEach } from 'vitest';
7
+ import { render, cleanup } from '@testing-library/react';
4
8
  import { StateContext } from 'piral-core';
5
9
  import { Breadcrumbs } from './Breadcrumbs';
6
10
  import { useRouteMatch } from 'react-router';
@@ -11,13 +15,13 @@ MockBcContainer.displayName = 'MockBcContainer';
11
15
  const MockBcItem: React.FC<any> = ({ children }) => <div role="dialog">{children}</div>;
12
16
  MockBcItem.displayName = 'MockBcTile';
13
17
 
14
- jest.mock('react-router', () => ({
18
+ vitest.mock('react-router', () => ({
15
19
  useLocation() {
16
20
  return {
17
21
  pathname: '/example',
18
22
  };
19
23
  },
20
- useRouteMatch: jest.fn(() => ({})),
24
+ useRouteMatch: vitest.fn(() => ({})),
21
25
  }));
22
26
 
23
27
  function createMockContainer(breadcrumbs = {}) {
@@ -32,9 +36,9 @@ function createMockContainer(breadcrumbs = {}) {
32
36
  }));
33
37
  return {
34
38
  context: {
35
- on: jest.fn(),
36
- off: jest.fn(),
37
- emit: jest.fn(),
39
+ on: vitest.fn(),
40
+ off: vitest.fn(),
41
+ emit: vitest.fn(),
38
42
  defineActions() {},
39
43
  state,
40
44
  readState(read) {
@@ -49,6 +53,10 @@ function createMockContainer(breadcrumbs = {}) {
49
53
  }
50
54
 
51
55
  describe('Piral-Breadcrumb Container component', () => {
56
+ afterEach(() => {
57
+ cleanup();
58
+ });
59
+
52
60
  it('breadcrumbs empty', () => {
53
61
  const { context } = createMockContainer();
54
62
  const node = render(
@@ -1,8 +1,31 @@
1
+ /**
2
+ * @vitest-environment jsdom
3
+ */
1
4
  import create from 'zustand';
2
- import { createListener } from 'piral-base';
3
- import { createActions } from 'piral-core';
5
+ import { describe, it, expect, vitest } from 'vitest';
4
6
  import { registerBreadcrumbs, unregisterBreadcrumbs } from './actions';
5
7
 
8
+ function createListener() {
9
+ return {
10
+ on: vitest.fn(),
11
+ off: vitest.fn(),
12
+ emit: vitest.fn(),
13
+ };
14
+ }
15
+
16
+ function createActions(state, listener) {
17
+ return {
18
+ ...listener,
19
+ state: state.getState(),
20
+ readState(select) {
21
+ return select(state.getState());
22
+ },
23
+ dispatch(change) {
24
+ state.setState(change(state.getState()));
25
+ },
26
+ };
27
+ }
28
+
6
29
  describe('Breadcrumbs Actions Module', () => {
7
30
  it('registerBreadcrumb and unregisterBreadcrumb', () => {
8
31
  const state: any = create(() => ({
@@ -12,7 +35,7 @@ describe('Breadcrumbs Actions Module', () => {
12
35
  breadcrumbs: {},
13
36
  },
14
37
  }));
15
- const ctx = createActions(state, createListener({}));
38
+ const ctx = createActions(state, createListener());
16
39
  registerBreadcrumbs(ctx, {
17
40
  foo: 10 as any,
18
41
  });
@@ -1,4 +1,8 @@
1
+ /**
2
+ * @vitest-environment jsdom
3
+ */
1
4
  import create from 'zustand';
5
+ import { describe, it, expect, vitest } from 'vitest';
2
6
  import { createBreadcrumbsApi } from './create';
3
7
 
4
8
  function createMockContainer() {
@@ -9,9 +13,9 @@ function createMockContainer() {
9
13
  }));
10
14
  return {
11
15
  context: {
12
- on: jest.fn(),
13
- off: jest.fn(),
14
- emit: jest.fn(),
16
+ on: vitest.fn(),
17
+ off: vitest.fn(),
18
+ emit: vitest.fn(),
15
19
  defineActions() {},
16
20
  state,
17
21
  dispatch(update) {
@@ -38,8 +42,8 @@ const moduleMetadata = {
38
42
  describe('Create Breadcrumb API Extensions', () => {
39
43
  it('createBreadcrumbsApi can register and unregister a breadcrumb', () => {
40
44
  const container = createMockContainer();
41
- container.context.registerBreadcrumbs = jest.fn();
42
- container.context.unregisterBreadcrumbs = jest.fn();
45
+ container.context.registerBreadcrumbs = vitest.fn();
46
+ container.context.unregisterBreadcrumbs = vitest.fn();
43
47
  const api = createApi(container);
44
48
  api.registerBreadcrumb('my-bc', {
45
49
  title: 'My breadcrumb',
@@ -55,8 +59,8 @@ describe('Create Breadcrumb API Extensions', () => {
55
59
 
56
60
  it('createBreadcrumbsApi can dispose a registered breadcrumb', () => {
57
61
  const container = createMockContainer();
58
- container.context.registerBreadcrumbs = jest.fn();
59
- container.context.unregisterBreadcrumbs = jest.fn();
62
+ container.context.registerBreadcrumbs = vitest.fn();
63
+ container.context.unregisterBreadcrumbs = vitest.fn();
60
64
  const api = createApi(container);
61
65
  const dispose = api.registerBreadcrumb('my-bc', {
62
66
  title: 'My breadcrumb',
@@ -72,8 +76,8 @@ describe('Create Breadcrumb API Extensions', () => {
72
76
 
73
77
  it('createBreadcrumbsApi can dispose a registered anonymous breadcrumb', () => {
74
78
  const container = createMockContainer();
75
- container.context.registerBreadcrumbs = jest.fn();
76
- container.context.unregisterBreadcrumbs = jest.fn();
79
+ container.context.registerBreadcrumbs = vitest.fn();
80
+ container.context.unregisterBreadcrumbs = vitest.fn();
77
81
  const api = createApi(container);
78
82
  const dispose = api.registerBreadcrumb({
79
83
  title: 'My breadcrumb',
@@ -89,8 +93,8 @@ describe('Create Breadcrumb API Extensions', () => {
89
93
 
90
94
  it('createBreadcrumsApi can use dynamic function as breadcrumb title', () => {
91
95
  const container = createMockContainer();
92
- container.context.registerBreadcrumbs = jest.fn();
93
- container.context.unregisterBreadcrumbs = jest.fn();
96
+ container.context.registerBreadcrumbs = vitest.fn();
97
+ container.context.unregisterBreadcrumbs = vitest.fn();
94
98
  const api = createApi(container);
95
99
  const dispose = api.registerBreadcrumb({
96
100
  title: ({ path }) => path,
@@ -1,8 +1,12 @@
1
+ /**
2
+ * @vitest-environment jsdom
3
+ */
1
4
  import * as React from 'react';
2
- import { render } from '@testing-library/react';
5
+ import { describe, it, expect, vitest, afterEach } from 'vitest';
6
+ import { render, cleanup } from '@testing-library/react';
3
7
  import { DefaultBreadcrumbsContainer } from './default';
4
8
 
5
- jest.mock('piral-core', () => ({
9
+ vitest.mock('piral-core', () => ({
6
10
  useGlobalState(select: any) {
7
11
  return select(state);
8
12
  },
@@ -26,6 +30,11 @@ jest.mock('piral-core', () => ({
26
30
  },
27
31
  }));
28
32
 
33
+ vitest.mock('react', async () => ({
34
+ ...(await vitest.importActual('react') as any),
35
+ useMemo: (cb) => cb(),
36
+ }));
37
+
29
38
  const state = {
30
39
  registry: {
31
40
  tiles: {},
@@ -33,8 +42,6 @@ const state = {
33
42
  },
34
43
  };
35
44
 
36
- (React as any).useMemo = (cb) => cb();
37
-
38
45
  const StubBreadcrumbsContainer: React.FC = () => <ul />;
39
46
  StubBreadcrumbsContainer.displayName = 'StubBreadcrumbsContainer';
40
47
 
@@ -42,6 +49,10 @@ const StubBreadcrumbItem: React.FC = () => <li />;
42
49
  StubBreadcrumbItem.displayName = 'BreadcrumbItem';
43
50
 
44
51
  describe('Default Breadcrumbs Component', () => {
52
+ afterEach(() => {
53
+ cleanup();
54
+ });
55
+
45
56
  it('renders the react fragment in the default case', () => {
46
57
  (state.registry.tiles as any).a = {
47
58
  component: StubBreadcrumbItem,