Skip to content

Commit ad944f1

Browse files
Christiancquirosj
authored andcommitted
Making tests pass the messageStore initial state
1 parent b160456 commit ad944f1

File tree

1 file changed

+67
-40
lines changed

1 file changed

+67
-40
lines changed

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

Lines changed: 67 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { render, describe, test, screen, expect, within } from "@component-test-utils";
22
import sut from "../messages2/SagaDiagram.vue";
3-
import Message, { SagaInfo } from "@/resources/Message";
43
import { SagaHistory } from "@/resources/SagaHistory";
54
import makeRouter from "@/router";
65
import { createTestingPinia } from "@pinia/testing";
6+
import { MessageStore } from "@/stores/MessageStore";
77

88
//Defines a domain-specific language (DSL) for interacting with the system under test (sut)
99
interface componentDSL {
@@ -25,10 +25,22 @@ interface componentDSLAssertions {
2525
describe("Feature: Message not involved in Saga", () => {
2626
describe("Rule: When the selected message has not participated in a Saga, display a legend indicating it.​", () => {
2727
test("EXAMPLE: A message that has not participated in a saga is selected", () => {
28-
const message = {} as Message;
29-
message.invoked_sagas = [];
28+
const messageStore = {} as MessageStore;
29+
messageStore.state = {} as MessageStore["state"];
30+
messageStore.state.data = {} as MessageStore["state"]["data"];
31+
messageStore.state.data.invoked_saga = {
32+
has_saga: false,
33+
saga_id: undefined,
34+
saga_type: undefined,
35+
};
3036

31-
const componentDriver = rendercomponent({ message: message });
37+
// No need to manually set up the store - it will be empty by default
38+
const componentDriver = rendercomponent({
39+
initialState: {
40+
MessageStore: messageStore,
41+
sagaHistory: undefined, // Lets pass undefined to simulate no saga data available
42+
},
43+
});
3244

3345
componentDriver.assert.NoSagaDataAvailableMessageIsShownWithMessage(/no saga data/i);
3446
});
@@ -38,15 +50,21 @@ describe("Feature: Message not involved in Saga", () => {
3850
describe("Feature: Detecting no Audited Saga Data Available", () => {
3951
describe("Rule: When a message participates in a Saga, but the Saga data is unavailable, display a legend indicating that the Saga audit plugin is needed to visualize the saga.", () => {
4052
test("EXAMPLE: A message that was participated in a Saga without the Saga audit plugin being active gets selected", () => {
41-
const message = {} as Message;
42-
const invokedSaga = {} as SagaInfo;
43-
invokedSaga.saga_id = "saga_id";
44-
message.invoked_sagas = [invokedSaga];
53+
const messageStore = {} as MessageStore;
54+
messageStore.state = {} as MessageStore["state"];
55+
messageStore.state.data = {} as MessageStore["state"]["data"];
56+
messageStore.state.data.invoked_saga = {
57+
has_saga: true,
58+
saga_id: "saga-id-123",
59+
saga_type: "Shipping.ShipOrderWorkflow",
60+
};
4561

4662
// No need to manually set up the store - it will be empty by default
4763
const componentDriver = rendercomponent({
48-
message: message,
49-
// No initial state needed - we want an empty saga history
64+
initialState: {
65+
MessageStore: messageStore,
66+
sagaHistory: undefined, // Lets pass undefined to simulate no saga data available
67+
},
5068
});
5169

5270
componentDriver.assert.SagaPlugInNeededIsShownWithTheMessages({
@@ -61,21 +79,24 @@ describe("Feature: Navigation and Contextual Information", () => {
6179
describe("Rule: Provide clear navigational elements to move between the message flow diagram and the saga view.", () => {
6280
test("EXAMPLE: A message record with id '123' and with a saga Id '88878' gets selected", () => {
6381
//A "← Back to Messages" link allows users to easily navigate back to the flow diagram.
64-
const message = {} as Message;
65-
const invokedSaga = {} as SagaInfo;
66-
invokedSaga.saga_id = "88878";
67-
message.invoked_sagas = [invokedSaga];
68-
6982
const storedMessageRecordId = "123";
7083
const message_id = "456";
7184

72-
message.id = storedMessageRecordId;
73-
message.message_id = message_id;
85+
const messageStore = {} as MessageStore;
86+
messageStore.state = {} as MessageStore["state"];
87+
messageStore.state.data = {} as MessageStore["state"]["data"];
88+
messageStore.state.data.message_id = message_id;
89+
messageStore.state.data.id = storedMessageRecordId;
90+
messageStore.state.data.invoked_saga = {
91+
has_saga: true,
92+
saga_id: "saga-id-123",
93+
saga_type: "Shipping.ShipOrderWorkflow",
94+
};
7495

7596
// Set initial state with sample saga history
7697
const componentDriver = rendercomponent({
77-
message: message,
7898
initialState: {
99+
MessageStore: messageStore,
79100
sagaHistory: { sagaHistory: sampleSagaHistory },
80101
},
81102
});
@@ -86,16 +107,19 @@ describe("Feature: Navigation and Contextual Information", () => {
86107

87108
describe("Rule: Clearly indicate contextual information like Saga ID and Saga Type.", () => {
88109
test("EXAMPLE: A message with a Saga Id '123' and a Saga Type 'ServiceControl.SmokeTest.AuditingSaga' gets selected", () => {
89-
const message = {} as Message;
90-
const invokedSaga = {} as SagaInfo;
91-
invokedSaga.saga_id = "123";
92-
invokedSaga.saga_type = "ServiceControl.SmokeTest.AuditingSaga";
93-
message.invoked_sagas = [invokedSaga];
110+
const messageStore = {} as MessageStore;
111+
messageStore.state = {} as MessageStore["state"];
112+
messageStore.state.data = {} as MessageStore["state"]["data"];
113+
messageStore.state.data.invoked_saga = {
114+
has_saga: true,
115+
saga_id: "123",
116+
saga_type: "ServiceControl.SmokeTest.AuditingSaga",
117+
};
94118

95119
// Set initial state with sample saga history
96120
const componentDriver = rendercomponent({
97-
message: message,
98121
initialState: {
122+
MessageStore: messageStore,
99123
sagaHistory: { sagaHistory: sampleSagaHistory },
100124
},
101125
});
@@ -120,11 +144,14 @@ describe("Feature: 3 Visual Representation of Saga Timeline", () => {
120144

121145
//arragement
122146
//sampleSagaHistory already not sorted TODO: Make this more clear so the reader of this test doesn't have to go arround and figure out the preconditions
123-
const message = {} as Message;
124-
const invokedSaga = {} as SagaInfo;
125-
invokedSaga.saga_id = "123";
126-
invokedSaga.saga_type = "ServiceControl.SmokeTest.AuditingSaga";
127-
message.invoked_sagas = [invokedSaga];
147+
const messageStore = {} as MessageStore;
148+
messageStore.state = {} as MessageStore["state"];
149+
messageStore.state.data = {} as MessageStore["state"]["data"];
150+
messageStore.state.data.invoked_saga = {
151+
has_saga: true,
152+
saga_id: "123",
153+
saga_type: "ServiceControl.SmokeTest.AuditingSaga",
154+
};
128155

129156
// Set the environment to a fixed timezone
130157
// JSDOM, used by Vitest, defaults to UTC timezone
@@ -152,8 +179,8 @@ describe("Feature: 3 Visual Representation of Saga Timeline", () => {
152179

153180
// Set up the store with sample saga history
154181
const componentDriver = rendercomponent({
155-
message: message,
156182
initialState: {
183+
MessageStore: messageStore,
157184
sagaHistory: { sagaHistory: sampleSagaHistory },
158185
},
159186
});
@@ -183,11 +210,14 @@ describe("Feature: 3 Visual Representation of Saga Timeline", () => {
183210

184211
//arragement
185212
//sampleSagaHistory already not sorted TODO: Make this more clear so the reader of this test doesn't have to go arround and figure out the preconditions
186-
const message = {} as Message;
187-
const invokedSaga = {} as SagaInfo;
188-
invokedSaga.saga_id = "123";
189-
invokedSaga.saga_type = "ServiceControl.SmokeTest.AuditingSaga";
190-
message.invoked_sagas = [invokedSaga];
213+
const messageStore = {} as MessageStore;
214+
messageStore.state = {} as MessageStore["state"];
215+
messageStore.state.data = {} as MessageStore["state"]["data"];
216+
messageStore.state.data.invoked_saga = {
217+
has_saga: true,
218+
saga_id: "123",
219+
saga_type: "ServiceControl.SmokeTest.AuditingSaga",
220+
};
191221

192222
// Set the environment to a fixed timezone
193223
// JSDOM, used by Vitest, defaults to PST timezone
@@ -215,8 +245,8 @@ describe("Feature: 3 Visual Representation of Saga Timeline", () => {
215245

216246
// Set up the store with sample saga history
217247
const componentDriver = rendercomponent({
218-
message: message,
219248
initialState: {
249+
MessageStore: messageStore,
220250
sagaHistory: { sagaHistory: sampleSagaHistory },
221251
},
222252
});
@@ -241,14 +271,11 @@ describe("Feature: 3 Visual Representation of Saga Timeline", () => {
241271
});
242272
});
243273

244-
function rendercomponent({ message, initialState = {} }: { message: Message; initialState?: { sagaHistory?: { sagaHistory: SagaHistory } } }): componentDSL {
274+
function rendercomponent({ initialState = {} }: { initialState?: { MessageStore?: MessageStore; sagaHistory?: { sagaHistory: SagaHistory } } }): componentDSL {
245275
const router = makeRouter();
246276

247277
// Render with createTestingPinia
248278
render(sut, {
249-
props: {
250-
message,
251-
},
252279
global: {
253280
plugins: [
254281
router,

0 commit comments

Comments
 (0)