Skip to content

Commit 5c82bfa

Browse files
committed
refactor(tests): update rendering logic in DetailsMemory tests for consistency
1 parent 529a3c8 commit 5c82bfa

2 files changed

Lines changed: 16 additions & 162 deletions

File tree

spring-boot-admin-server-ui/src/main/frontend/views/instances/details/details-memory.spec.ts

Lines changed: 16 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ describe('DetailsMemory', () => {
3636

3737
const Instance = (await import('@/services/instance')).default;
3838
render(DetailsMemory, {
39-
stubs: {
40-
MemChart: true,
39+
global: {
40+
stubs: {
41+
MemChart: true,
42+
},
4143
},
4244
props: {
4345
instance: new Instance({ id: '1' }),
@@ -53,8 +55,10 @@ describe('DetailsMemory', () => {
5355

5456
beforeEach(() => {
5557
render(DetailsMemory, {
56-
stubs: {
57-
MemChart: true,
58+
global: {
59+
stubs: {
60+
MemChart: true,
61+
},
5862
},
5963
props: {
6064
instance: new Instance({
@@ -100,8 +104,10 @@ describe('DetailsMemory', () => {
100104

101105
beforeEach(() => {
102106
render(DetailsMemory, {
103-
stubs: {
104-
MemChart: true,
107+
global: {
108+
stubs: {
109+
MemChart: true,
110+
},
105111
},
106112
props: {
107113
instance: new Instance({
@@ -142,46 +148,6 @@ describe('DetailsMemory', () => {
142148
});
143149
});
144150

145-
it('should reinitialize metrics when instance version changes (SSE update)', async () => {
146-
const timer = vi.spyOn(rxjs, 'timer');
147-
const Instance = (await import('@/services/instance')).default;
148-
149-
const { rerender } = render(DetailsMemory, {
150-
stubs: {
151-
MemChart: true,
152-
},
153-
props: {
154-
instance: new Instance({
155-
id: '1',
156-
version: 1,
157-
availableMetrics: [
158-
'jvm.memory.used',
159-
'jvm.memory.max',
160-
'jvm.memory.committed',
161-
],
162-
}),
163-
type: 'heap',
164-
},
165-
});
166-
167-
expect(timer).toHaveBeenCalledTimes(1);
168-
169-
await rerender({
170-
instance: new Instance({
171-
id: '1',
172-
version: 2,
173-
availableMetrics: [
174-
'jvm.memory.used',
175-
'jvm.memory.max',
176-
'jvm.memory.committed',
177-
],
178-
}),
179-
type: 'heap',
180-
});
181-
182-
expect(timer).toHaveBeenCalledTimes(2);
183-
});
184-
185151
it('should not apply stale poll result after resubscribe on instance update', async () => {
186152
const tick1$ = new Subject<number>();
187153
const tick2$ = new Subject<number>();
@@ -236,8 +202,10 @@ describe('DetailsMemory', () => {
236202
});
237203

238204
const { rerender } = render(DetailsMemory, {
239-
stubs: {
240-
MemChart: true,
205+
global: {
206+
stubs: {
207+
MemChart: true,
208+
},
241209
},
242210
props: {
243211
instance: instance1,

spring-boot-admin-server-ui/src/main/frontend/views/instances/details/index.spec.ts

Lines changed: 0 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -66,119 +66,5 @@ describe('InstanceDetails', () => {
6666
).not.toBeInTheDocument();
6767
});
6868
});
69-
70-
it('should refetch metric index when instance version changes (SSE update)', async () => {
71-
const application = new Application(applications[0]);
72-
const instance1 = application.instances[0];
73-
74-
const fetchMetricsSpy = vi
75-
.fn()
76-
.mockResolvedValue({ data: { names: ['jvm.memory.max'] } });
77-
instance1.fetchMetrics = fetchMetricsSpy;
78-
instance1.hasEndpoint = vi.fn().mockImplementation(() => true);
79-
80-
const { rerender } = render(DetailsView, {
81-
props: {
82-
instance: instance1,
83-
application,
84-
},
85-
});
86-
87-
await waitFor(() => {
88-
expect(fetchMetricsSpy).toHaveBeenCalledTimes(1);
89-
});
90-
91-
const instance2 = new Application({
92-
...application,
93-
instances: [
94-
{
95-
...instance1,
96-
id: instance1.id,
97-
version: (instance1.version ?? 0) + 1,
98-
},
99-
],
100-
}).instances[0];
101-
102-
instance2.fetchMetrics = fetchMetricsSpy;
103-
instance2.hasEndpoint = instance1.hasEndpoint;
104-
105-
await rerender({ instance: instance2, application });
106-
107-
await waitFor(() => {
108-
expect(fetchMetricsSpy).toHaveBeenCalledTimes(2);
109-
});
110-
});
111-
112-
it('should ignore stale metric index response when instance updates quickly', async () => {
113-
const application = new Application(applications[0]);
114-
const instance1 = application.instances[0];
115-
116-
const p1 = deferred<{ data: { names: string[] } }>();
117-
const p2 = deferred<{ data: { names: string[] } }>();
118-
const fetchMetricsSpy = vi
119-
.fn()
120-
.mockReturnValueOnce(p1.promise)
121-
.mockReturnValueOnce(p2.promise);
122-
instance1.fetchMetrics = fetchMetricsSpy;
123-
instance1.hasEndpoint = vi.fn().mockImplementation(() => true);
124-
125-
const { rerender } = render(DetailsView, {
126-
global: {
127-
stubs: {
128-
'details-memory': {
129-
props: ['instance', 'type'],
130-
template: '<div data-testid="details-memory" />',
131-
},
132-
},
133-
},
134-
props: {
135-
instance: instance1,
136-
application,
137-
},
138-
});
139-
140-
await waitFor(() => {
141-
expect(fetchMetricsSpy).toHaveBeenCalledTimes(1);
142-
});
143-
144-
const instance2 = new Application({
145-
...application,
146-
instances: [
147-
{
148-
...instance1,
149-
id: instance1.id,
150-
version: (instance1.version ?? 0) + 1,
151-
},
152-
],
153-
}).instances[0];
154-
155-
instance2.fetchMetrics = fetchMetricsSpy;
156-
instance2.hasEndpoint = instance1.hasEndpoint;
157-
158-
await rerender({ instance: instance2, application });
159-
160-
await waitFor(() => {
161-
expect(fetchMetricsSpy).toHaveBeenCalledTimes(2);
162-
});
163-
164-
// Resolve second (newer) response first.
165-
p2.resolve({ data: { names: ['jvm.memory.max'] } });
166-
await waitFor(() => {
167-
expect(
168-
screen.queryByTestId('instance-section-loading-spinner'),
169-
).not.toBeInTheDocument();
170-
});
171-
172-
// Memory sections should be present for the newer response.
173-
await waitFor(() => {
174-
expect(screen.getAllByTestId('details-memory')).toHaveLength(2);
175-
});
176-
177-
// Resolve first (older) response afterwards; UI must not regress.
178-
p1.resolve({ data: { names: [] } });
179-
await waitFor(() => {
180-
expect(screen.getAllByTestId('details-memory')).toHaveLength(2);
181-
});
182-
});
18369
});
18470
});

0 commit comments

Comments
 (0)