Skip to content

Commit 2864dcb

Browse files
Merge pull request #2475 from Particular/fix-component-tests
Refactor SagaDiagram and tests to use new toLocalDateTimeString utility
2 parents 7d74c2a + fe02728 commit 2864dcb

File tree

3 files changed

+63
-31
lines changed

3 files changed

+63
-31
lines changed

src/Frontend/src/components/messages/SagaDiagram.spec.ts

Lines changed: 57 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface componentDSL {
1414

1515
//Defines a domain-specific language (DSL) for checking assertions against the system under test (sut)
1616
interface componentDSLAssertions {
17-
thereAreTheFollowingSagaChangesInThisOrder(sagaUpdates: { expectedRenderedLocalTime: string }[]): void;
17+
thereAreTheFollowingSagaChangesInThisOrder(sagaUpdates: { expectedTime: Date }[]): void;
1818
displayedSagaGuidIs(sagaId: string): void;
1919
displayedSagaNameIs(humanizedSagaName: string): void;
2020
linkIsShown(arg0: { withText: string; withHref: string }): void;
@@ -136,14 +136,24 @@ describe("Feature: 3 Visual Representation of Saga Timeline", () => {
136136
// but set them again explicitly here
137137
//so that the reader of this test can see the preconditions at play
138138
//and understand the test better without having to jump around
139-
sampleSagaHistory.changes[0].start_time = new Date("2025-03-28T03:04:08.3819211Z"); // A
140-
sampleSagaHistory.changes[0].finish_time = new Date("2025-03-28T03:04:08.3836Z"); // A1
141-
sampleSagaHistory.changes[1].start_time = new Date("2025-03-28T03:04:07.5416262Z"); // B
142-
sampleSagaHistory.changes[1].finish_time = new Date("2025-03-28T03:04:07.5509712Z"); //B1
143-
sampleSagaHistory.changes[2].start_time = new Date("2025-03-28T03:04:06.3088353Z"); //C
144-
sampleSagaHistory.changes[2].finish_time = new Date("2025-03-28T03:04:06.3218175Z"); //C1
145-
sampleSagaHistory.changes[3].start_time = new Date("2025-03-28T03:04:05.3332078Z"); //D
146-
sampleSagaHistory.changes[3].finish_time = new Date("2025-03-28T03:04:05.3799483Z"); //D1
139+
140+
const startTimeA = new Date("2025-03-28T03:04:08.000Z");
141+
const finishTimeA1 = new Date("2025-03-28T03:04:08.000Z");
142+
const startTimeB = new Date("2025-03-28T03:04:07.000Z");
143+
const finishTimeB1 = new Date("2025-03-28T03:04:07.000Z");
144+
const startTimeC = new Date("2025-03-28T03:04:06.000Z");
145+
const finishTimeC1 = new Date("2025-03-28T03:04:06.000Z");
146+
const startTimeD = new Date("2025-03-28T03:04:05.000Z");
147+
const finishTimeD1 = new Date("2025-03-28T03:04:05.000Z");
148+
149+
sampleSagaHistory.changes[0].start_time = startTimeA;
150+
sampleSagaHistory.changes[0].finish_time = finishTimeA1;
151+
sampleSagaHistory.changes[1].start_time = startTimeB;
152+
sampleSagaHistory.changes[1].finish_time = finishTimeB1;
153+
sampleSagaHistory.changes[2].start_time = startTimeC;
154+
sampleSagaHistory.changes[2].finish_time = finishTimeC1;
155+
sampleSagaHistory.changes[3].start_time = startTimeD;
156+
sampleSagaHistory.changes[3].finish_time = finishTimeD1;
147157
sampleSagaHistory.changes[3].status = "new";
148158

149159
//B(1), C(2), A(0), D(3)
@@ -158,19 +168,18 @@ describe("Feature: 3 Visual Representation of Saga Timeline", () => {
158168
});
159169

160170
//assert
161-
162171
componentDriver.assert.thereAreTheFollowingSagaChangesInThisOrder([
163172
{
164-
expectedRenderedLocalTime: "3/28/2025 3:04:05 AM",
173+
expectedTime: startTimeD,
165174
},
166175
{
167-
expectedRenderedLocalTime: "3/28/2025 3:04:06 AM",
176+
expectedTime: startTimeC,
168177
},
169178
{
170-
expectedRenderedLocalTime: "3/28/2025 3:04:07 AM",
179+
expectedTime: startTimeB,
171180
},
172181
{
173-
expectedRenderedLocalTime: "3/28/2025 3:04:08 AM",
182+
expectedTime: startTimeA,
174183
},
175184
]);
176185
});
@@ -202,14 +211,23 @@ describe("Feature: 3 Visual Representation of Saga Timeline", () => {
202211
// but set them again explicitly here
203212
//so that the reader of this test can see the preconditions at play
204213
//and understand the test better without having to jump around
205-
sampleSagaHistory.changes[0].start_time = new Date("2025-03-28T03:04:08.3819211Z"); // A
206-
sampleSagaHistory.changes[0].finish_time = new Date("2025-03-28T03:04:08.3836Z"); // A1
207-
sampleSagaHistory.changes[1].start_time = new Date("2025-03-28T03:04:07.5416262Z"); // B
208-
sampleSagaHistory.changes[1].finish_time = new Date("2025-03-28T03:04:07.5509712Z"); //B1
209-
sampleSagaHistory.changes[2].start_time = new Date("2025-03-28T03:04:06.3088353Z"); //C
210-
sampleSagaHistory.changes[2].finish_time = new Date("2025-03-28T03:04:06.3218175Z"); //C1
211-
sampleSagaHistory.changes[3].start_time = new Date("2025-03-28T03:04:05.3332078Z"); //D
212-
sampleSagaHistory.changes[3].finish_time = new Date("2025-03-28T03:04:05.3799483Z"); //D1
214+
const startTimeA = new Date("2025-03-28T03:04:08.000Z");
215+
const finishTimeA1 = new Date("2025-03-28T03:04:08.000Z");
216+
const startTimeB = new Date("2025-03-28T03:04:07.000Z");
217+
const finishTimeB1 = new Date("2025-03-28T03:04:07.000Z");
218+
const startTimeC = new Date("2025-03-28T03:04:06.000Z");
219+
const finishTimeC1 = new Date("2025-03-28T03:04:06.000Z");
220+
const startTimeD = new Date("2025-03-28T03:04:05.000Z");
221+
const finishTimeD1 = new Date("2025-03-28T03:04:05.000Z");
222+
223+
sampleSagaHistory.changes[0].start_time = startTimeA;
224+
sampleSagaHistory.changes[0].finish_time = finishTimeA1;
225+
sampleSagaHistory.changes[1].start_time = startTimeB;
226+
sampleSagaHistory.changes[1].finish_time = finishTimeB1;
227+
sampleSagaHistory.changes[2].start_time = startTimeC;
228+
sampleSagaHistory.changes[2].finish_time = finishTimeC1;
229+
sampleSagaHistory.changes[3].start_time = startTimeD;
230+
sampleSagaHistory.changes[3].finish_time = finishTimeD1;
213231
sampleSagaHistory.changes[3].status = "new";
214232

215233
// Set up the store with sample saga history
@@ -224,16 +242,16 @@ describe("Feature: 3 Visual Representation of Saga Timeline", () => {
224242

225243
componentDriver.assert.thereAreTheFollowingSagaChangesInThisOrder([
226244
{
227-
expectedRenderedLocalTime: "3/27/2025 8:04:05 PM",
245+
expectedTime: startTimeD,
228246
},
229247
{
230-
expectedRenderedLocalTime: "3/27/2025 8:04:06 PM",
248+
expectedTime: startTimeC,
231249
},
232250
{
233-
expectedRenderedLocalTime: "3/27/2025 8:04:07 PM",
251+
expectedTime: startTimeB,
234252
},
235253
{
236-
expectedRenderedLocalTime: "3/27/2025 8:04:08 PM",
254+
expectedTime: startTimeA,
237255
},
238256
]);
239257
});
@@ -317,21 +335,30 @@ function rendercomponent({ initialState = {} }: { initialState?: { MessageStore?
317335
expect(sagaGuid).toBeInTheDocument();
318336
expect(sagaGuid).toHaveTextContent(guid);
319337
},
320-
thereAreTheFollowingSagaChangesInThisOrder: function (sagaUpdates: { expectedRenderedLocalTime: string }[]): void {
338+
thereAreTheFollowingSagaChangesInThisOrder: function (sagaUpdates: { expectedTime: Date }[]): void {
321339
//Retrive the main parent component that contains the saga changes
322340
const sagaChangesContainer = screen.getByRole("table", { name: /saga-sequence-list/i });
323341

324342
const sagaUpdatesElements = within(sagaChangesContainer).queryAllByRole("row");
325-
//from within each sagaUpdatesElemtns get the values of an element with aria-label="time stamp"
343+
//from within each sagaUpdatesElements get the values of an element with aria-label="time stamp"
326344
//and check if the values are in the same order as the sagaUpdates array passed to this function
327345
const sagaUpdatesTimestamps = sagaUpdatesElements.map((item: HTMLElement) => within(item).getByLabelText("time stamp"));
328346

329347
//expect the number of found sagaUpdatesTimestamps to be the same as the number of sagaUpdates passed to this function
330348
expect(sagaUpdatesTimestamps).toHaveLength(sagaUpdates.length);
331349

332350
const sagaUpdatesTimestampsValues = sagaUpdatesTimestamps.map((item) => item.innerHTML);
333-
// //check if the values are in the same order as the sagaUpdates array passed to this function
334-
expect(sagaUpdatesTimestampsValues).toEqual(sagaUpdates.map((item) => item.expectedRenderedLocalTime));
351+
352+
// Parse the rendered timestamp strings back to Date objects for comparison
353+
const parsedDatesFromUI = sagaUpdatesTimestampsValues.map((timestampString) => {
354+
// Parse the retrieved timestamp string back to a Date
355+
return new Date(timestampString);
356+
});
357+
358+
const expectedDates = sagaUpdates.map((item) => item.expectedTime);
359+
360+
// Compare the dates directly
361+
expect(parsedDatesFromUI).toEqual(expectedDates);
335362
},
336363
},
337364
};

src/Frontend/src/components/messages/SagaDiagram.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import SagaPluginNeeded from "./SagaDiagram/SagaPluginNeeded.vue";
1313
import SagaHeader from "./SagaDiagram/SagaHeader.vue";
1414
import SagaUpdateNode from "./SagaDiagram/SagaUpdateNode.vue";
1515
import SagaCompletedNode from "./SagaDiagram/SagaCompletedNode.vue";
16+
import { toLocalDateTimeString } from "@/composables/formatUtils";
1617
1718
const sagaDiagramStore = useSagaDiagramStore();
1819
const { showMessageData, loading } = storeToRefs(sagaDiagramStore);
@@ -56,7 +57,7 @@ const vm = computed<SagaViewModel>(() => {
5657
SagaCompleted: !!completedUpdate,
5758
5859
// Display data
59-
FormattedCompletionTime: completionTime ? `${completionTime.toLocaleDateString()} ${completionTime.toLocaleTimeString()}` : "",
60+
FormattedCompletionTime: completionTime ? toLocalDateTimeString(completionTime) : "",
6061
SagaUpdates: parseSagaUpdates(sagaHistory, sagaDiagramStore.messagesData),
6162
ShowMessageData: showMessageData.value,
6263
};

src/Frontend/src/composables/formatUtils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ export function dotNetTimespanToMilliseconds(timespan: string) {
1717
const [hh, mm, ss] = timespan.split(":");
1818
return ((parseInt(hh) * 60 + parseInt(mm)) * 60 + parseFloat(ss)) * 1000;
1919
}
20+
21+
export function toLocalDateTimeString(date: Date) {
22+
return `${date.toLocaleDateString()} ${date.toLocaleTimeString()}`;
23+
}

0 commit comments

Comments
 (0)