Skip to content

Commit 7c317a0

Browse files
CopilotulischulteCopilot
authored
Fix journal view to display updated application names after registration changes (#4554)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: ulischulte <[email protected]> Co-authored-by: ulrichschulte <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 3bcb515 commit 7c317a0

File tree

2 files changed

+131
-2
lines changed

2 files changed

+131
-2
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
import { screen } from '@testing-library/vue';
2+
import { HttpResponse, http } from 'msw';
3+
import { beforeEach, describe, expect, it } from 'vitest';
4+
5+
import JournalView from './index.vue';
6+
7+
import { server } from '@/mocks/server';
8+
import { render } from '@/test-utils';
9+
10+
class InstanceEvent {
11+
constructor({ instance, version, type, timestamp, ...payload }) {
12+
this.instance = instance;
13+
this.version = version;
14+
this.type = type;
15+
this.timestamp = new Date(timestamp);
16+
this.payload = payload;
17+
}
18+
19+
get key() {
20+
return `${this.instance}-${this.version}`;
21+
}
22+
}
23+
24+
InstanceEvent.REGISTERED = 'REGISTERED';
25+
InstanceEvent.REGISTRATION_UPDATED = 'REGISTRATION_UPDATED';
26+
27+
describe('Journal View', () => {
28+
beforeEach(() => {
29+
server.use(
30+
http.get('/instances/events', () => {
31+
return HttpResponse.json([{ event: '' }]);
32+
}),
33+
);
34+
});
35+
36+
it('should update instance names when registration is updated', () => {
37+
const events = [
38+
new InstanceEvent({
39+
instance: 'instance-1',
40+
version: 1,
41+
type: 'REGISTERED',
42+
timestamp: '2023-01-01T10:00:00Z',
43+
registration: { name: 'OLD APP NAME' },
44+
}),
45+
new InstanceEvent({
46+
instance: 'instance-1',
47+
version: 2,
48+
type: 'REGISTRATION_UPDATED',
49+
timestamp: '2023-01-01T11:00:00Z',
50+
registration: { name: 'NEW APP NAME' },
51+
}),
52+
];
53+
54+
render(JournalView, {
55+
data() {
56+
return {
57+
events: events,
58+
};
59+
},
60+
global: {
61+
mocks: {
62+
$t: (key) => key,
63+
$route: { query: {} },
64+
$router: {
65+
replace: () => {},
66+
},
67+
},
68+
},
69+
});
70+
71+
const allByNewText = screen.getAllByText('NEW APP NAME');
72+
73+
expect(allByNewText).toBeDefined();
74+
});
75+
76+
it('should handle both REGISTERED and REGISTRATION_UPDATED events', () => {
77+
const events = [
78+
new InstanceEvent({
79+
instance: 'instance-1',
80+
version: 1,
81+
type: 'REGISTERED',
82+
timestamp: '2023-01-01T10:00:00Z',
83+
registration: { name: 'App One' },
84+
}),
85+
new InstanceEvent({
86+
instance: 'instance-2',
87+
version: 1,
88+
type: 'REGISTERED',
89+
timestamp: '2023-01-01T10:05:00Z',
90+
registration: { name: 'App Two' },
91+
}),
92+
new InstanceEvent({
93+
instance: 'instance-2',
94+
version: 2,
95+
type: 'REGISTRATION_UPDATED',
96+
timestamp: '2023-01-01T11:00:00Z',
97+
registration: { name: 'App Two Updated' },
98+
}),
99+
];
100+
101+
render(JournalView, {
102+
data() {
103+
return {
104+
events: events,
105+
};
106+
},
107+
global: {
108+
mocks: {
109+
$t: (key) => key,
110+
$route: { query: {} },
111+
$router: { replace: () => {} },
112+
},
113+
},
114+
});
115+
116+
const appOneText = screen.getAllByText('App One');
117+
118+
expect(appOneText).toBeDefined();
119+
120+
const appTwoText = screen.getAllByText('App Two Updated');
121+
122+
expect(appTwoText).toBeDefined();
123+
});
124+
});

spring-boot-admin-server-ui/src/main/frontend/views/journal/index.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,13 @@ export default {
188188
computed: {
189189
instanceNames() {
190190
return this.events
191-
.filter((event) => event.type === InstanceEvent.REGISTERED)
192-
.reduce((names, event) => {
191+
.filter(
192+
(event) =>
193+
event.type === InstanceEvent.REGISTERED ||
194+
event.type === InstanceEvent.REGISTRATION_UPDATED,
195+
)
196+
.sort((a, b) => b.timestamp - a.timestamp)
197+
.reduceRight((names, event) => {
193198
names[event.instance] = event.payload.registration.name;
194199
return names;
195200
}, {});

0 commit comments

Comments
 (0)