@object-ui/plugin-dashboard 2.0.0 → 3.0.0
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/.turbo/turbo-build.log +5 -5
- package/CHANGELOG.md +20 -0
- package/dist/index.js +2122 -2042
- package/dist/index.umd.cjs +4 -4
- package/dist/src/DashboardGridLayout.d.ts +2 -0
- package/dist/src/DashboardGridLayout.d.ts.map +1 -1
- package/dist/src/DashboardRenderer.d.ts +6 -3
- package/dist/src/DashboardRenderer.d.ts.map +1 -1
- package/dist/src/DashboardRenderer.stories.d.ts +24 -0
- package/dist/src/DashboardRenderer.stories.d.ts.map +1 -0
- package/dist/src/index.d.ts +1 -5
- package/dist/src/index.d.ts.map +1 -1
- package/package.json +10 -10
- package/src/DashboardGridLayout.tsx +59 -6
- package/src/DashboardRenderer.stories.tsx +173 -0
- package/src/DashboardRenderer.tsx +161 -99
- package/src/__tests__/DashboardRenderer.autoRefresh.test.tsx +124 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ObjectUI
|
|
3
|
+
* Copyright (c) 2024-present ObjectStack Inc.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
10
|
+
import { render, screen, fireEvent, act } from '@testing-library/react';
|
|
11
|
+
import { DashboardRenderer } from '../DashboardRenderer';
|
|
12
|
+
import type { DashboardSchema } from '@object-ui/types';
|
|
13
|
+
|
|
14
|
+
describe('DashboardRenderer auto-refresh', () => {
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
vi.useFakeTimers();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
afterEach(() => {
|
|
20
|
+
vi.useRealTimers();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const mockSchema: DashboardSchema = {
|
|
24
|
+
type: 'dashboard',
|
|
25
|
+
name: 'test_dashboard',
|
|
26
|
+
title: 'Test Dashboard',
|
|
27
|
+
widgets: [],
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
it('should not render refresh button when onRefresh is not provided', () => {
|
|
31
|
+
render(<DashboardRenderer schema={mockSchema} />);
|
|
32
|
+
expect(screen.queryByLabelText('Refresh dashboard')).not.toBeInTheDocument();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('should render refresh button when onRefresh is provided', () => {
|
|
36
|
+
const onRefresh = vi.fn();
|
|
37
|
+
render(<DashboardRenderer schema={mockSchema} onRefresh={onRefresh} />);
|
|
38
|
+
expect(screen.getByLabelText('Refresh dashboard')).toBeInTheDocument();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('should call onRefresh when refresh button is clicked', () => {
|
|
42
|
+
const onRefresh = vi.fn();
|
|
43
|
+
render(<DashboardRenderer schema={mockSchema} onRefresh={onRefresh} />);
|
|
44
|
+
|
|
45
|
+
const button = screen.getByLabelText('Refresh dashboard');
|
|
46
|
+
fireEvent.click(button);
|
|
47
|
+
|
|
48
|
+
expect(onRefresh).toHaveBeenCalledTimes(1);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('should auto-refresh at the configured interval', () => {
|
|
52
|
+
const onRefresh = vi.fn();
|
|
53
|
+
const schemaWithRefresh: DashboardSchema = {
|
|
54
|
+
...mockSchema,
|
|
55
|
+
refreshInterval: 30, // 30 seconds
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
render(<DashboardRenderer schema={schemaWithRefresh} onRefresh={onRefresh} />);
|
|
59
|
+
|
|
60
|
+
expect(onRefresh).not.toHaveBeenCalled();
|
|
61
|
+
|
|
62
|
+
// Advance past one interval
|
|
63
|
+
act(() => {
|
|
64
|
+
vi.advanceTimersByTime(30_000);
|
|
65
|
+
});
|
|
66
|
+
expect(onRefresh).toHaveBeenCalledTimes(1);
|
|
67
|
+
|
|
68
|
+
// Advance past another interval
|
|
69
|
+
act(() => {
|
|
70
|
+
vi.advanceTimersByTime(30_000);
|
|
71
|
+
});
|
|
72
|
+
expect(onRefresh).toHaveBeenCalledTimes(2);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('should not auto-refresh when refreshInterval is 0', () => {
|
|
76
|
+
const onRefresh = vi.fn();
|
|
77
|
+
const schemaWithZeroInterval: DashboardSchema = {
|
|
78
|
+
...mockSchema,
|
|
79
|
+
refreshInterval: 0,
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
render(<DashboardRenderer schema={schemaWithZeroInterval} onRefresh={onRefresh} />);
|
|
83
|
+
|
|
84
|
+
act(() => {
|
|
85
|
+
vi.advanceTimersByTime(60_000);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
expect(onRefresh).not.toHaveBeenCalled();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('should not auto-refresh when onRefresh is not provided', () => {
|
|
92
|
+
const schemaWithRefresh: DashboardSchema = {
|
|
93
|
+
...mockSchema,
|
|
94
|
+
refreshInterval: 10,
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// Should not throw
|
|
98
|
+
render(<DashboardRenderer schema={schemaWithRefresh} />);
|
|
99
|
+
|
|
100
|
+
act(() => {
|
|
101
|
+
vi.advanceTimersByTime(30_000);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('should clean up interval on unmount', () => {
|
|
106
|
+
const onRefresh = vi.fn();
|
|
107
|
+
const schemaWithRefresh: DashboardSchema = {
|
|
108
|
+
...mockSchema,
|
|
109
|
+
refreshInterval: 5,
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const { unmount } = render(
|
|
113
|
+
<DashboardRenderer schema={schemaWithRefresh} onRefresh={onRefresh} />
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
unmount();
|
|
117
|
+
|
|
118
|
+
act(() => {
|
|
119
|
+
vi.advanceTimersByTime(30_000);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
expect(onRefresh).not.toHaveBeenCalled();
|
|
123
|
+
});
|
|
124
|
+
});
|