piral-dashboard 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-dashboard",
3
- "version": "1.3.3-beta.6190",
3
+ "version": "1.3.3-beta.6204",
4
4
  "description": "Plugin for creating a centralized dashboard in Piral.",
5
5
  "keywords": [
6
6
  "piral",
@@ -63,8 +63,8 @@
63
63
  "devDependencies": {
64
64
  "@types/react": "^18.0.0",
65
65
  "@types/react-router-dom": "^5.1.6",
66
- "piral-core": "1.3.3-beta.6190",
66
+ "piral-core": "1.3.3-beta.6204",
67
67
  "react": "^18.0.0"
68
68
  },
69
- "gitHead": "dc3358f0e08b06acea2056b612f268334a8c49c8"
69
+ "gitHead": "8a1fa7b847b0e146a5bdb8e0497c436fffe4fd4d"
70
70
  }
@@ -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 { Dashboard } from './Dashboard';
6
10
 
@@ -21,9 +25,9 @@ function createMockContainer(tiles = {}) {
21
25
  }));
22
26
  return {
23
27
  context: {
24
- on: jest.fn(),
25
- off: jest.fn(),
26
- emit: jest.fn(),
28
+ on: vitest.fn(),
29
+ off: vitest.fn(),
30
+ emit: vitest.fn(),
27
31
  defineActions() {},
28
32
  state,
29
33
  readState(read) {
@@ -38,6 +42,10 @@ function createMockContainer(tiles = {}) {
38
42
  }
39
43
 
40
44
  describe('Piral-Dashboard Dashboard component', () => {
45
+ afterEach(() => {
46
+ cleanup();
47
+ });
48
+
41
49
  it('uses container for a connected dashboard', () => {
42
50
  const fake: any = {};
43
51
  const { context } = createMockContainer();
@@ -1,8 +1,28 @@
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 { registerTile, unregisterTile } 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
+ dispatch(change) {
21
+ state.setState(change(state.getState()));
22
+ },
23
+ };
24
+ }
25
+
6
26
  describe('Dashboard Actions Module', () => {
7
27
  it('registerTile and unregisterTile', () => {
8
28
  const state: any = create(() => ({
@@ -12,7 +32,7 @@ describe('Dashboard Actions Module', () => {
12
32
  tiles: {},
13
33
  },
14
34
  }));
15
- const ctx = createActions(state, createListener({}));
35
+ const ctx = createActions(state, createListener());
16
36
  registerTile(ctx, 'foo', 10);
17
37
  expect((state.getState())).toEqual({
18
38
  foo: 5,
@@ -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 { createElement, FC } from 'react';
3
7
  import { createDashboardApi } from './create';
4
8
 
@@ -13,9 +17,9 @@ function createMockContainer() {
13
17
  }));
14
18
  return {
15
19
  context: {
16
- on: jest.fn(),
17
- off: jest.fn(),
18
- emit: jest.fn(),
20
+ on: vitest.fn(),
21
+ off: vitest.fn(),
22
+ emit: vitest.fn(),
19
23
  defineActions() {},
20
24
  converters: {},
21
25
  readState() {
@@ -46,8 +50,8 @@ const moduleMetadata = {
46
50
  describe('Create Dashboard API Extensions', () => {
47
51
  it('createDashboardApi can register and unregister a tile', () => {
48
52
  const container = createMockContainer();
49
- container.context.registerTile = jest.fn();
50
- container.context.unregisterTile = jest.fn();
53
+ container.context.registerTile = vitest.fn();
54
+ container.context.unregisterTile = vitest.fn();
51
55
  const api = createApi(container);
52
56
  api.registerTile('my-tile', StubComponent);
53
57
  expect(container.context.registerTile).toHaveBeenCalledTimes(1);
@@ -59,8 +63,8 @@ describe('Create Dashboard API Extensions', () => {
59
63
 
60
64
  it('createDashboardApi can dispose a registered tile', () => {
61
65
  const container = createMockContainer();
62
- container.context.registerTile = jest.fn();
63
- container.context.unregisterTile = jest.fn();
66
+ container.context.registerTile = vitest.fn();
67
+ container.context.unregisterTile = vitest.fn();
64
68
  const api = createApi(container);
65
69
  const dispose = api.registerTile('my-tile', StubComponent);
66
70
  expect(container.context.registerTile).toHaveBeenCalledTimes(1);
@@ -72,8 +76,8 @@ describe('Create Dashboard API Extensions', () => {
72
76
 
73
77
  it('createDashboardApi can dispose an anonymous tile', () => {
74
78
  const container = createMockContainer();
75
- container.context.registerTile = jest.fn();
76
- container.context.unregisterTile = jest.fn();
79
+ container.context.registerTile = vitest.fn();
80
+ container.context.unregisterTile = vitest.fn();
77
81
  const api = createApi(container);
78
82
  const dispose = api.registerTile(StubComponent);
79
83
  expect(container.context.registerTile).toHaveBeenCalledTimes(1);
@@ -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 { DefaultContainer } 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 StubDashboard: React.FC = () => <div role="dashboard" />;
39
46
  StubDashboard.displayName = 'StubDashboard';
40
47
 
@@ -42,6 +49,10 @@ const StubTile: React.FC = () => <div role="tile" />;
42
49
  StubTile.displayName = 'StubTile';
43
50
 
44
51
  describe('Default Dashboard 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: StubTile,