Skip to content

Commit 000f372

Browse files
Refactor SagaDiagram and tests to use new toLocalDateTimeString utility
1 parent 5d7db79 commit 000f372

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import makeRouter from "@/router";
55
import { createTestingPinia } from "@pinia/testing";
66
import { MessageStore } from "@/stores/MessageStore";
77
import { MessageStatus } from "@/resources/Message";
8+
import { toLocalDateTimeString } from "@/composables/formatUtils";
89

910
//Defines a domain-specific language (DSL) for interacting with the system under test (sut)
1011
interface componentDSL {
@@ -158,19 +159,18 @@ describe("Feature: 3 Visual Representation of Saga Timeline", () => {
158159
});
159160

160161
//assert
161-
162162
componentDriver.assert.thereAreTheFollowingSagaChangesInThisOrder([
163163
{
164-
expectedRenderedLocalTime: "3/28/2025 3:04:05 AM",
164+
expectedRenderedLocalTime: toLocalDateTimeString(sampleSagaHistory.changes[3].start_time), // D
165165
},
166166
{
167-
expectedRenderedLocalTime: "3/28/2025 3:04:06 AM",
167+
expectedRenderedLocalTime: toLocalDateTimeString(sampleSagaHistory.changes[2].start_time), // C
168168
},
169169
{
170-
expectedRenderedLocalTime: "3/28/2025 3:04:07 AM",
170+
expectedRenderedLocalTime: toLocalDateTimeString(sampleSagaHistory.changes[1].start_time), // B
171171
},
172172
{
173-
expectedRenderedLocalTime: "3/28/2025 3:04:08 AM",
173+
expectedRenderedLocalTime: toLocalDateTimeString(sampleSagaHistory.changes[0].start_time), // A
174174
},
175175
]);
176176
});
@@ -224,16 +224,16 @@ describe("Feature: 3 Visual Representation of Saga Timeline", () => {
224224

225225
componentDriver.assert.thereAreTheFollowingSagaChangesInThisOrder([
226226
{
227-
expectedRenderedLocalTime: "3/27/2025 8:04:05 PM",
227+
expectedRenderedLocalTime: toLocalDateTimeString(sampleSagaHistory.changes[3].start_time), // D
228228
},
229229
{
230-
expectedRenderedLocalTime: "3/27/2025 8:04:06 PM",
230+
expectedRenderedLocalTime: toLocalDateTimeString(sampleSagaHistory.changes[2].start_time), // C
231231
},
232232
{
233-
expectedRenderedLocalTime: "3/27/2025 8:04:07 PM",
233+
expectedRenderedLocalTime: toLocalDateTimeString(sampleSagaHistory.changes[1].start_time), // B
234234
},
235235
{
236-
expectedRenderedLocalTime: "3/27/2025 8:04:08 PM",
236+
expectedRenderedLocalTime: toLocalDateTimeString(sampleSagaHistory.changes[0].start_time), // A
237237
},
238238
]);
239239
});
@@ -322,14 +322,15 @@ function rendercomponent({ initialState = {} }: { initialState?: { MessageStore?
322322
const sagaChangesContainer = screen.getByRole("table", { name: /saga-sequence-list/i });
323323

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

329329
//expect the number of found sagaUpdatesTimestamps to be the same as the number of sagaUpdates passed to this function
330330
expect(sagaUpdatesTimestamps).toHaveLength(sagaUpdates.length);
331331

332332
const sagaUpdatesTimestampsValues = sagaUpdatesTimestamps.map((item) => item.innerHTML);
333+
333334
// //check if the values are in the same order as the sagaUpdates array passed to this function
334335
expect(sagaUpdatesTimestampsValues).toEqual(sagaUpdates.map((item) => item.expectedRenderedLocalTime));
335336
},

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)