@sapui5/sap.fe.test 1.104.1 → 1.105.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/sap/fe/test/.library +1 -1
- package/src/sap/fe/test/CollaborationClient.js +1 -1
- package/src/sap/fe/test/FeMocks.js +1 -3
- package/src/sap/fe/test/FeMocks.ts +0 -4
- package/src/sap/fe/test/JestTemplatingHelper.js +99 -9
- package/src/sap/fe/test/JestTemplatingHelper.ts +82 -4
- package/src/sap/fe/test/ListReport.js +21 -0
- package/src/sap/fe/test/ObjectPage.js +8 -0
- package/src/sap/fe/test/UI5MockHelper.js +373 -326
- package/src/sap/fe/test/UI5MockHelper.ts +395 -258
- package/src/sap/fe/test/api/CollaborationAPI.js +1 -1
- package/src/sap/fe/test/api/FormActions.js +9 -0
- package/src/sap/fe/test/api/HeaderAssertions.js +16 -7
- package/src/sap/fe/test/internal/ConsoleErrorChecker.js +1 -1
- package/src/sap/fe/test/library.js +2 -2
|
@@ -1,344 +1,481 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
1
|
+
import type { WithMock } from "@sap-ux/jest-mock-ui5/dist/generic";
|
|
2
|
+
import { mock } from "@sap-ux/jest-mock-ui5/dist/generic";
|
|
3
|
+
import EditFlow from "sap/fe/core/controllerextensions/EditFlow";
|
|
4
|
+
import InternalEditFlow from "sap/fe/core/controllerextensions/InternalEditFlow";
|
|
5
|
+
import InternalRouting from "sap/fe/core/controllerextensions/InternalRouting";
|
|
6
|
+
import SideEffects from "sap/fe/core/controllerextensions/SideEffects";
|
|
7
|
+
import Event from "sap/ui/base/Event";
|
|
8
|
+
import Controller from "sap/ui/core/mvc/Controller";
|
|
9
|
+
import View from "sap/ui/core/mvc/View";
|
|
10
|
+
import CompositeBinding from "sap/ui/model/CompositeBinding";
|
|
11
|
+
import Context from "sap/ui/model/odata/v4/Context";
|
|
12
|
+
import ODataContextBinding from "sap/ui/model/odata/v4/ODataContextBinding";
|
|
13
|
+
import ODataListBinding from "sap/ui/model/odata/v4/ODataListBinding";
|
|
14
14
|
import ODataMetaModel from "sap/ui/model/odata/v4/ODataMetaModel";
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
|
|
18
|
-
export class MockContext implements Partial<Context> {
|
|
19
|
-
private isKeptAlive = false;
|
|
20
|
-
public constructor(private oValues?: any, private oBinding?: any) {}
|
|
15
|
+
import ODataModel from "sap/ui/model/odata/v4/ODataModel";
|
|
16
|
+
import ODataPropertyBinding from "sap/ui/model/odata/v4/ODataPropertyBinding";
|
|
21
17
|
|
|
22
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Utility type to mock a sap.ui.model.odata.v4.Context
|
|
20
|
+
*/
|
|
21
|
+
export type MockContext = WithMock<Context> & {
|
|
22
|
+
_isKeptAlive: boolean;
|
|
23
|
+
_contextData: any;
|
|
24
|
+
_oBinding: any;
|
|
25
|
+
_isInactive: boolean;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Factory function to create a new MockContext.
|
|
29
|
+
*
|
|
30
|
+
* @param oContextData A map of the different properties of the context. The value for the key '$path' will be returned by the 'getPath' method
|
|
31
|
+
* @param oBinding The binding of the context
|
|
32
|
+
* @param isInactive Is the context iniactive or not
|
|
33
|
+
* @returns A new MockContext
|
|
34
|
+
*/
|
|
35
|
+
export function createMockContext(oContextData?: any, oBinding?: any, isInactive?: boolean): MockContext {
|
|
36
|
+
// Ugly workaround to get a proper mock pbject, as Context isn't properly exported from UI5
|
|
37
|
+
const mocked = mock(Object.getPrototypeOf((Context as any).createNewContext(null, null, "/e"))) as MockContext;
|
|
38
|
+
mocked._isKeptAlive = false;
|
|
39
|
+
mocked._contextData = oContextData || {};
|
|
40
|
+
mocked._oBinding = oBinding;
|
|
41
|
+
mocked._isInactive = !!isInactive;
|
|
42
|
+
|
|
43
|
+
// Default behavior
|
|
44
|
+
mocked.mock.isA.mockImplementation((sClassName: string) => {
|
|
23
45
|
return sClassName === "sap.ui.model.odata.v4.Context";
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public getProperty = jest.fn((key: string) => {
|
|
27
|
-
return this.oValues[key];
|
|
28
46
|
});
|
|
29
|
-
|
|
30
|
-
return
|
|
47
|
+
mocked.mock.getProperty.mockImplementation((key: string) => {
|
|
48
|
+
return mocked._contextData[key];
|
|
49
|
+
});
|
|
50
|
+
mocked.mock.requestProperty.mockImplementation((key: string) => {
|
|
51
|
+
return Promise.resolve(mocked._contextData[key]);
|
|
31
52
|
});
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
53
|
+
mocked.mock.requestObject.mockImplementation((key: string) => {
|
|
54
|
+
return Promise.resolve(mocked._contextData[key]);
|
|
55
|
+
});
|
|
56
|
+
mocked.mock.setProperty.mockImplementation((key: string, value: any) => {
|
|
57
|
+
mocked._contextData[key] = value;
|
|
58
|
+
return mocked._contextData[key];
|
|
35
59
|
});
|
|
36
60
|
|
|
37
|
-
|
|
38
|
-
let result = path ?
|
|
61
|
+
mocked.mock.getObject.mockImplementation((path: string) => {
|
|
62
|
+
let result = path ? mocked._contextData[path] : mocked._contextData;
|
|
39
63
|
|
|
40
64
|
if (!result && path && path.indexOf("/") > -1) {
|
|
41
65
|
const parts = path.split("/");
|
|
42
66
|
result = parts.reduce((sum, part: any) => {
|
|
43
67
|
sum = part ? sum[part] : sum;
|
|
44
68
|
return sum;
|
|
45
|
-
},
|
|
69
|
+
}, mocked._contextData);
|
|
46
70
|
}
|
|
47
71
|
|
|
48
72
|
return result;
|
|
49
73
|
});
|
|
50
|
-
public getPath = jest.fn(() => {
|
|
51
|
-
return this.oValues["$path"];
|
|
52
|
-
});
|
|
53
74
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
75
|
+
mocked.mock.getPath.mockImplementation(() => mocked._contextData["$path"]);
|
|
76
|
+
mocked.mock.getBinding.mockImplementation(() => mocked._oBinding);
|
|
77
|
+
mocked.mock.getModel.mockImplementation(() => mocked._oBinding?.getModel());
|
|
78
|
+
mocked.mock.setKeepAlive.mockImplementation((bool: boolean, _fnOnBeforeDestroy?: any, _bRequestMessages?: boolean) => {
|
|
79
|
+
mocked._isKeptAlive = bool;
|
|
59
80
|
});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
public setKeepAlive = jest.fn((bool: boolean, _fnOnBeforeDestroy?: any, _bRequestMessages?: boolean) => {
|
|
63
|
-
this.isKeptAlive = bool;
|
|
64
|
-
});
|
|
65
|
-
public isKeepAlive = jest.fn(() => this.isKeptAlive);
|
|
66
|
-
public requestSideEffects = jest.fn();
|
|
67
|
-
public requestObject = jest.fn();
|
|
68
|
-
}
|
|
81
|
+
mocked.mock.isKeepAlive.mockImplementation(() => mocked._isKeptAlive);
|
|
82
|
+
mocked.mock.isInactive.mockImplementation(() => mocked._isInactive);
|
|
69
83
|
|
|
70
|
-
|
|
71
|
-
[key: string]: any;
|
|
72
|
-
public bindingContext = new MockContext({});
|
|
73
|
-
public getBinding = jest.fn();
|
|
74
|
-
public getBindingContext = jest.fn().mockReturnValue(this.bindingContext);
|
|
75
|
-
public getBindingInfo = jest.fn();
|
|
76
|
-
public data = jest.fn();
|
|
77
|
-
public getModel = jest.fn();
|
|
78
|
-
public getParent = jest.fn();
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export class MockControl extends MockUI5Element implements Partial<Control> {
|
|
82
|
-
public getBindingContext: jest.Mock<any, any> = jest.fn();
|
|
83
|
-
public getModel: jest.Mock<any, any> = jest.fn();
|
|
84
|
+
return mocked;
|
|
84
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* For compatibility reasons, we keep a new operator. Use the factory function createMockContext instead.
|
|
88
|
+
*/
|
|
89
|
+
export const MockContext: new (oValues?: any, oBinding?: any, isInactive?: boolean) => MockContext = createMockContext as any;
|
|
85
90
|
|
|
86
|
-
|
|
87
|
-
|
|
91
|
+
/**
|
|
92
|
+
* Utility type to mock a sap.ui.base.Event
|
|
93
|
+
*/
|
|
94
|
+
export type MockEvent = WithMock<Event> & {
|
|
95
|
+
_params: { [key: string]: any };
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Factory function to create a new MockEvent.
|
|
99
|
+
*
|
|
100
|
+
* @param params The parameters of the event
|
|
101
|
+
* @returns A new MockEvent
|
|
102
|
+
*/
|
|
103
|
+
export function createMockEvent(params?: { [key: string]: any }): MockEvent {
|
|
104
|
+
const mocked = mock(Event) as MockEvent;
|
|
105
|
+
mocked._params = params || {};
|
|
88
106
|
|
|
89
|
-
|
|
107
|
+
// Default behavior
|
|
108
|
+
mocked.mock.getParameter.mockImplementation((name) => mocked._params[name]);
|
|
90
109
|
|
|
91
|
-
|
|
110
|
+
return mocked;
|
|
92
111
|
}
|
|
93
|
-
|
|
94
112
|
/**
|
|
95
|
-
*
|
|
113
|
+
* For compatibility reasons, we keep a new operator. Use the factory function createMockEvent instead.
|
|
96
114
|
*/
|
|
97
|
-
export
|
|
98
|
-
private aMockContexts: MockContext[];
|
|
115
|
+
export const MockEvent: new (params?: { [key: string]: any }) => MockEvent = createMockEvent as any;
|
|
99
116
|
|
|
100
|
-
|
|
101
|
-
|
|
117
|
+
/**
|
|
118
|
+
* Utility type to mock a sap.ui.model.odata.v4.ODataListBinding
|
|
119
|
+
*/
|
|
120
|
+
export type MockListBinding = WithMock<ODataListBinding> & {
|
|
121
|
+
_aMockContexts: MockContext[];
|
|
122
|
+
_mockModel?: MockModel;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Utility method to set the model of the ListBinding
|
|
126
|
+
*/
|
|
127
|
+
setModel: (model: MockModel) => void;
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Factory function to create a new MockListBinding.
|
|
131
|
+
*
|
|
132
|
+
* @param aContextData An array of objects holding the different properties of the contexts referenced by the ListBinding
|
|
133
|
+
* @param oMockModel The model of the ListBinding
|
|
134
|
+
* @returns A new MockListBinding
|
|
135
|
+
*/
|
|
136
|
+
export function createMockListBinding(aContextData?: any[], oMockModel?: MockModel): MockListBinding {
|
|
137
|
+
const mocked = mock(ODataListBinding) as MockListBinding;
|
|
138
|
+
aContextData = aContextData || [];
|
|
139
|
+
mocked._aMockContexts = aContextData.map((contextData) => {
|
|
140
|
+
return createMockContext(contextData, mocked);
|
|
141
|
+
});
|
|
142
|
+
mocked._mockModel = oMockModel;
|
|
102
143
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
144
|
+
// Utility API
|
|
145
|
+
mocked.setModel = (model: MockModel) => {
|
|
146
|
+
mocked._mockModel = model;
|
|
147
|
+
};
|
|
107
148
|
|
|
108
|
-
|
|
149
|
+
// Default behavior
|
|
150
|
+
mocked.mock.isA.mockImplementation((sClassName: string) => {
|
|
109
151
|
return sClassName === "sap.ui.model.odata.v4.ODataListBinding";
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
public setModel(oModel: MockModel) {
|
|
113
|
-
this.mockModel = oModel;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// Mocked API
|
|
117
|
-
public setAggregation = jest.fn();
|
|
118
|
-
public filter = jest.fn();
|
|
119
|
-
public sort = jest.fn();
|
|
120
|
-
|
|
121
|
-
public getQueryOptionsFromParameters = jest.fn();
|
|
122
|
-
public getPath = jest.fn();
|
|
123
|
-
public isSuspended = jest.fn();
|
|
124
|
-
public resume = jest.fn();
|
|
125
|
-
public refresh = jest.fn();
|
|
126
|
-
public suspend = jest.fn();
|
|
127
|
-
|
|
128
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
129
|
-
public requestContexts = jest.fn((...args) => {
|
|
130
|
-
return Promise.resolve(this.aMockContexts as any as Context[]);
|
|
131
152
|
});
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
return this.aMockContexts as any as Context[];
|
|
153
|
+
mocked.mock.requestContexts.mockImplementation(() => {
|
|
154
|
+
return Promise.resolve(mocked._aMockContexts);
|
|
135
155
|
});
|
|
136
|
-
|
|
137
|
-
return
|
|
156
|
+
mocked.mock.getCurrentContexts.mockImplementation(() => {
|
|
157
|
+
return mocked._aMockContexts;
|
|
138
158
|
});
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
159
|
+
mocked.mock.getAllCurrentContexts.mockImplementation(() => {
|
|
160
|
+
return mocked._aMockContexts;
|
|
161
|
+
});
|
|
162
|
+
mocked.mock.getModel.mockImplementation(() => {
|
|
163
|
+
return mocked._mockModel;
|
|
164
|
+
});
|
|
165
|
+
mocked.mock.getUpdateGroupId.mockReturnValue("auto");
|
|
145
166
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
167
|
+
return mocked;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* For compatibility reasons, we keep a new operator. Use the factory function createMockListBinding instead.
|
|
171
|
+
*/
|
|
172
|
+
export const MockListBinding: new (aContexts?: any[], mockModel?: MockModel) => MockListBinding = createMockListBinding as any;
|
|
150
173
|
|
|
151
|
-
|
|
174
|
+
/**
|
|
175
|
+
* Utility type to mock a sap.ui.model.odata.v4.ODataPropertyBinding
|
|
176
|
+
*/
|
|
177
|
+
export type MockPropertyBinding = WithMock<ODataPropertyBinding> & {
|
|
178
|
+
_value?: any;
|
|
179
|
+
_path?: string;
|
|
180
|
+
_mockModel?: MockModel;
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
* Factory function to create a new MockPropertyBinding.
|
|
184
|
+
*
|
|
185
|
+
* @param value The value returnd by the PropertyBinding
|
|
186
|
+
* @param path The path of the PropertyBinding
|
|
187
|
+
* @param oMockModel The model of the PropertyBinding
|
|
188
|
+
* @returns A new MockPropertyBinding
|
|
189
|
+
*/
|
|
190
|
+
export function createMockPropertyBinding(value: any, path?: string, oMockModel?: MockModel): MockPropertyBinding {
|
|
191
|
+
const mocked = mock(ODataPropertyBinding) as MockPropertyBinding;
|
|
192
|
+
mocked._mockModel = oMockModel;
|
|
193
|
+
mocked._value = value;
|
|
194
|
+
mocked._path = path;
|
|
195
|
+
|
|
196
|
+
// Default behavior
|
|
197
|
+
mocked.mock.isA.mockImplementation((sClassName: string) => {
|
|
152
198
|
return sClassName === "sap/ui/model/odata/v4/ODataPropertyBinding";
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
public setModel(oModel: JSONModel) {
|
|
156
|
-
this.mockModel = oModel;
|
|
157
|
-
}
|
|
158
|
-
public getModel = jest.fn(() => {
|
|
159
|
-
return this.mockModel as any as ODataModel;
|
|
160
199
|
});
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
this.mockPath = path ? path : "";
|
|
164
|
-
}
|
|
165
|
-
public getPath = jest.fn(() => {
|
|
166
|
-
return this.mockPath;
|
|
200
|
+
mocked.mock.getModel.mockImplementation(() => {
|
|
201
|
+
return mocked._mockModel;
|
|
167
202
|
});
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
203
|
+
mocked.mock.getValue.mockImplementation(() => {
|
|
204
|
+
return mocked._value;
|
|
205
|
+
});
|
|
206
|
+
mocked.mock.getPath.mockImplementation(() => {
|
|
207
|
+
return mocked._path;
|
|
171
208
|
});
|
|
172
|
-
}
|
|
173
209
|
|
|
174
|
-
|
|
175
|
-
|
|
210
|
+
return mocked;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* For compatibility reasons, we keep a new operator. Use the factory function createMockPropertyBinding instead.
|
|
214
|
+
*/
|
|
215
|
+
export const MockPropertyBinding: new (value: any, oMockModel?: MockModel) => MockPropertyBinding = createMockPropertyBinding as any;
|
|
176
216
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
217
|
+
/**
|
|
218
|
+
* Utility type to mock a sap.ui.model.CompositeBinding
|
|
219
|
+
*/
|
|
220
|
+
export type MockCompositeBinding = WithMock<CompositeBinding> & {
|
|
221
|
+
_aBindings: MockPropertyBinding[];
|
|
222
|
+
};
|
|
223
|
+
/**
|
|
224
|
+
* Factory function to create a new MockCompositeBinding.
|
|
225
|
+
*
|
|
226
|
+
* @param aBindings The bindings of the CompositeBinding
|
|
227
|
+
* @returns A new MockCompositeBinding
|
|
228
|
+
*/
|
|
229
|
+
export function createMockCompositeBinding(aBindings: MockPropertyBinding[]): MockCompositeBinding {
|
|
230
|
+
const mocked = mock(CompositeBinding) as MockCompositeBinding;
|
|
231
|
+
mocked._aBindings = aBindings;
|
|
180
232
|
|
|
181
|
-
|
|
233
|
+
// Default behavior
|
|
234
|
+
mocked.mock.isA.mockImplementation((sClassName: string) => {
|
|
182
235
|
return sClassName === "sap.ui.model.CompositeBinding";
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
public getBindings = jest.fn(() => {
|
|
186
|
-
return this.aBindings;
|
|
187
236
|
});
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
237
|
+
mocked.mock.getBindings.mockImplementation(() => {
|
|
238
|
+
return mocked._aBindings;
|
|
239
|
+
});
|
|
240
|
+
mocked.mock.getValue.mockImplementation(() => {
|
|
241
|
+
return mocked._aBindings.map((binding) => binding.getValue());
|
|
191
242
|
});
|
|
192
|
-
}
|
|
193
243
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
244
|
+
return mocked;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* For compatibility reasons, we keep a new operator. Use the factory function createMockCompositeBinding instead.
|
|
248
|
+
*/
|
|
249
|
+
export const MockCompositeBinding: new (aBindings: MockPropertyBinding[]) => MockCompositeBinding = createMockCompositeBinding as any;
|
|
197
250
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
251
|
+
/**
|
|
252
|
+
* Utility type to mock a sap.ui.model.odata.v4.ODataContextBinding
|
|
253
|
+
*/
|
|
254
|
+
export type MockContextBinding = WithMock<ODataContextBinding> & {
|
|
255
|
+
oMockContext: MockContext;
|
|
256
|
+
isKeptAlive: boolean;
|
|
257
|
+
mockModel?: MockModel;
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Utility method to access the internal MockContext of the ContextBinding
|
|
261
|
+
*/
|
|
262
|
+
getInternalMockContext: () => MockContext;
|
|
263
|
+
/**
|
|
264
|
+
* Utility method to set the model of the ContextBinding
|
|
265
|
+
*/
|
|
266
|
+
setModel: (oModel: MockModel) => void;
|
|
267
|
+
};
|
|
268
|
+
/**
|
|
269
|
+
* Factory function to create a new MockContextBinding.
|
|
270
|
+
*
|
|
271
|
+
* @param oContext The context of the ContextBinding
|
|
272
|
+
* @param oMockModel The model of the ContextBinding
|
|
273
|
+
* @returns A new MockContextBinding
|
|
274
|
+
*/
|
|
275
|
+
export function createMockContextBinding(oContext?: any, oMockModel?: MockModel): MockContextBinding {
|
|
276
|
+
const mocked = mock(ODataContextBinding) as MockContextBinding;
|
|
277
|
+
mocked.mockModel = oMockModel;
|
|
278
|
+
mocked.oMockContext = createMockContext(oContext || {}, mocked);
|
|
279
|
+
|
|
280
|
+
// Utility API
|
|
281
|
+
mocked.getInternalMockContext = () => {
|
|
282
|
+
return mocked.oMockContext;
|
|
283
|
+
};
|
|
284
|
+
mocked.setModel = (oModel: MockModel) => {
|
|
285
|
+
mocked.mockModel = oModel;
|
|
286
|
+
};
|
|
201
287
|
|
|
202
|
-
|
|
288
|
+
// Default behavior
|
|
289
|
+
mocked.mock.isA.mockImplementation((sClassName: string) => {
|
|
203
290
|
return sClassName === "sap.ui.model.odata.v4.ODataContextBinding";
|
|
204
|
-
}
|
|
205
|
-
public getInternalMockContext(): MockContext {
|
|
206
|
-
return this.oMockContext;
|
|
207
|
-
}
|
|
208
|
-
public setModel(oModel: MockModel) {
|
|
209
|
-
this.mockModel = oModel;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
// Mocked API
|
|
213
|
-
public getBoundContext = jest.fn(() => {
|
|
214
|
-
return this.oMockContext as any as Context;
|
|
215
291
|
});
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
return this.mockModel as any as ODataModel;
|
|
292
|
+
mocked.mock.getBoundContext.mockImplementation(() => {
|
|
293
|
+
return mocked.oMockContext;
|
|
219
294
|
});
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
295
|
+
mocked.mock.getModel.mockImplementation(() => {
|
|
296
|
+
return mocked.mockModel;
|
|
297
|
+
});
|
|
298
|
+
mocked.mock.execute.mockResolvedValue(true);
|
|
224
299
|
|
|
300
|
+
return mocked;
|
|
301
|
+
}
|
|
225
302
|
/**
|
|
226
|
-
*
|
|
303
|
+
* For compatibility reasons, we keep a new operator. Use the factory function createMockContextBinding instead.
|
|
227
304
|
*/
|
|
228
|
-
export
|
|
229
|
-
private oMetaContext: MockContext;
|
|
230
|
-
requestValueListInfo!: jest.Mock<any, any>;
|
|
305
|
+
export const MockContextBinding: new (oContext?: any, oMockModel?: MockModel) => MockContextBinding = createMockContextBinding as any;
|
|
231
306
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
307
|
+
/**
|
|
308
|
+
* Utility type to mock a sap.ui.model.odata.v4.ODataMetaModel
|
|
309
|
+
*/
|
|
310
|
+
export type MockMetaModel = WithMock<ODataMetaModel> & {
|
|
311
|
+
oMetaContext: MockContext;
|
|
312
|
+
};
|
|
313
|
+
/**
|
|
314
|
+
* Factory function to create a new MockMetaModel.
|
|
315
|
+
*
|
|
316
|
+
* @param oMetaData A map of the different metadata properties of the MetaModel (path -> value).
|
|
317
|
+
* @returns A new MockMetaModel
|
|
318
|
+
*/
|
|
319
|
+
export function createMockMetaModel(oMetaData?: any): MockMetaModel {
|
|
320
|
+
const mocked = mock(ODataMetaModel) as MockMetaModel;
|
|
321
|
+
mocked.oMetaContext = createMockContext(oMetaData || {});
|
|
235
322
|
|
|
236
|
-
//
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
return new MockContext({ $path: sPath }) as any as Context;
|
|
323
|
+
// Default behavior
|
|
324
|
+
mocked.mock.getMetaContext.mockImplementation((sPath: string) => {
|
|
325
|
+
return createMockContext({ $path: sPath });
|
|
240
326
|
});
|
|
241
|
-
|
|
242
|
-
return
|
|
327
|
+
mocked.mock.getObject.mockImplementation((sPath: string) => {
|
|
328
|
+
return mocked.oMetaContext.getProperty(sPath);
|
|
243
329
|
});
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
return new MockContext({ $path: sPath }) as any as Context;
|
|
330
|
+
mocked.mock.createBindingContext.mockImplementation((sPath: string) => {
|
|
331
|
+
return createMockContext({ $path: sPath });
|
|
247
332
|
});
|
|
248
|
-
|
|
333
|
+
mocked.mock.getMetaPath.mockImplementation((sPath: string) => {
|
|
249
334
|
const metamodel = new ODataMetaModel();
|
|
250
335
|
return sPath ? metamodel.getMetaPath(sPath) : sPath;
|
|
251
336
|
});
|
|
252
|
-
public getContext = jest.fn();
|
|
253
|
-
}
|
|
254
337
|
|
|
338
|
+
return mocked;
|
|
339
|
+
}
|
|
255
340
|
/**
|
|
256
|
-
*
|
|
341
|
+
* For compatibility reasons, we keep a new operator. Use the factory function createMockMetaModel instead.
|
|
257
342
|
*/
|
|
343
|
+
export const MockMetaModel: new (oMetaData?: any) => MockMetaModel = createMockMetaModel as any;
|
|
258
344
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
345
|
+
/**
|
|
346
|
+
* Utility type to mock a sap.ui.model.odata.v4.ODataModel
|
|
347
|
+
*/
|
|
348
|
+
export type MockModel = WithMock<ODataModel> & {
|
|
349
|
+
oMetaModel?: MockMetaModel;
|
|
350
|
+
mockListBinding?: MockListBinding;
|
|
351
|
+
mockContextBinding?: MockContextBinding;
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Utility method to set the metamodel of the MockModel
|
|
355
|
+
*/
|
|
356
|
+
setMetaModel: (oMetaModel: MockMetaModel) => void;
|
|
357
|
+
};
|
|
358
|
+
/**
|
|
359
|
+
* Factory function to create a new MockModel.
|
|
360
|
+
*
|
|
361
|
+
* @param oMockListBinding A list binding that will be returned when calling bindList.
|
|
362
|
+
* @param oMockContextBinding A context binding that will be returned when calling bindContext.
|
|
363
|
+
* @returns A new MockModel
|
|
364
|
+
*/
|
|
365
|
+
export function createMockModel(oMockListBinding?: MockListBinding, oMockContextBinding?: MockContextBinding): MockModel {
|
|
366
|
+
const mocked = mock(ODataModel) as MockModel;
|
|
367
|
+
mocked.mockListBinding = oMockListBinding;
|
|
368
|
+
mocked.mockContextBinding = oMockContextBinding;
|
|
369
|
+
if (oMockListBinding) {
|
|
370
|
+
oMockListBinding.setModel(mocked);
|
|
274
371
|
}
|
|
275
|
-
|
|
276
|
-
|
|
372
|
+
if (oMockContextBinding) {
|
|
373
|
+
oMockContextBinding.setModel(mocked);
|
|
277
374
|
}
|
|
278
375
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
376
|
+
// Utility API
|
|
377
|
+
mocked.setMetaModel = (oMetaModel: MockMetaModel) => {
|
|
378
|
+
mocked.oMetaModel = oMetaModel;
|
|
379
|
+
};
|
|
282
380
|
|
|
283
|
-
//
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
return this.mockListBinding as any as ODataListBinding;
|
|
381
|
+
// Default behavior
|
|
382
|
+
mocked.mock.bindList.mockImplementation(() => {
|
|
383
|
+
return mocked.mockListBinding;
|
|
287
384
|
});
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
return this.mockContextBinding as any as ODataContextBinding;
|
|
385
|
+
mocked.mock.bindContext.mockImplementation(() => {
|
|
386
|
+
return mocked.mockContextBinding;
|
|
291
387
|
});
|
|
292
|
-
|
|
293
|
-
return
|
|
388
|
+
mocked.mock.getMetaModel.mockImplementation(() => {
|
|
389
|
+
return mocked.oMetaModel;
|
|
294
390
|
});
|
|
295
391
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
392
|
+
return mocked;
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* For compatibility reasons, we keep a new operator. Use the factory function createMockModel instead.
|
|
396
|
+
*/
|
|
397
|
+
export const MockModel: new (oMockListBinding?: MockListBinding, oMockContextBinding?: MockContextBinding) => MockModel =
|
|
398
|
+
createMockModel as any;
|
|
399
|
+
/**
|
|
400
|
+
* Factory function to create a new MockModel used with a listBinding.
|
|
401
|
+
*
|
|
402
|
+
* @param oMockListBinding A list binding that will be returned when calling bindList.
|
|
403
|
+
* @returns A new MockModel
|
|
404
|
+
*/
|
|
405
|
+
export function createMockModelFromListBinding(oMockListBinding: MockListBinding): MockModel {
|
|
406
|
+
return createMockModel(oMockListBinding);
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Factory function to create a new MockModel used with a contextBinding.
|
|
410
|
+
*
|
|
411
|
+
* @param oMockContextBinding A context binding that will be returned when calling bindContext.
|
|
412
|
+
* @returns A new MockModel
|
|
413
|
+
*/
|
|
414
|
+
export function createMockModelFromContextBinding(oMockContextBinding: MockContextBinding): MockModel {
|
|
415
|
+
return createMockModel(undefined, oMockContextBinding);
|
|
300
416
|
}
|
|
301
417
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
418
|
+
/**
|
|
419
|
+
* Utility type to mock a sap.ui.core.mvc.View
|
|
420
|
+
*/
|
|
421
|
+
export type MockView = WithMock<View>;
|
|
422
|
+
/**
|
|
423
|
+
* Factory function to create a new MockView.
|
|
424
|
+
*
|
|
425
|
+
* @returns A new MockView
|
|
426
|
+
*/
|
|
427
|
+
export function createMockView(): MockView {
|
|
428
|
+
const mocked = mock(View);
|
|
310
429
|
|
|
311
|
-
|
|
430
|
+
// Default behavior
|
|
431
|
+
mocked.mock.isA.mockImplementation((sClassName: string) => {
|
|
312
432
|
return sClassName === "sap.ui.core.mvc.View";
|
|
313
|
-
}
|
|
433
|
+
});
|
|
314
434
|
|
|
315
|
-
|
|
435
|
+
return mocked;
|
|
316
436
|
}
|
|
437
|
+
/**
|
|
438
|
+
* For compatibility reasons, we keep a new operator. Use the factory function createMockView instead.
|
|
439
|
+
*/
|
|
440
|
+
export const MockView: new () => MockView = createMockView as any;
|
|
317
441
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
442
|
+
/**
|
|
443
|
+
* Utility type to mock a sap.fe.core.PageController
|
|
444
|
+
*/
|
|
445
|
+
export type MockController = WithMock<Controller> & {
|
|
446
|
+
_routing: WithMock<InternalRouting>;
|
|
447
|
+
_editFlow: WithMock<InternalEditFlow>;
|
|
448
|
+
_sideEffects: WithMock<SideEffects>;
|
|
449
|
+
editFlow: WithMock<EditFlow>;
|
|
450
|
+
};
|
|
451
|
+
/**
|
|
452
|
+
* Factory function to create a new MockController.
|
|
453
|
+
*
|
|
454
|
+
* @returns A new MockController
|
|
455
|
+
*/
|
|
456
|
+
export function createMockController(): MockController {
|
|
457
|
+
const mocked = mock(Controller) as MockController;
|
|
458
|
+
mocked._routing = mock(InternalRouting);
|
|
459
|
+
mocked._editFlow = mock(InternalEditFlow);
|
|
460
|
+
mocked._sideEffects = mock(SideEffects);
|
|
461
|
+
mocked.editFlow = mock(EditFlow);
|
|
462
|
+
|
|
463
|
+
// Default Behavior
|
|
464
|
+
mocked.mock.getView.mockReturnValue(createMockView());
|
|
465
|
+
mocked.mock.isA.mockReturnValue(false);
|
|
466
|
+
|
|
467
|
+
return mocked;
|
|
334
468
|
}
|
|
469
|
+
/**
|
|
470
|
+
* For compatibility reasons, we keep a new operator. Use the factory function mockController instead.
|
|
471
|
+
*/
|
|
472
|
+
export const MockController: new () => MockController = createMockController as any;
|
|
335
473
|
|
|
336
474
|
export interface MVCMock {
|
|
337
475
|
model: MockModel;
|
|
338
476
|
view: MockView;
|
|
339
477
|
controller: MockController;
|
|
340
478
|
}
|
|
341
|
-
|
|
342
479
|
/**
|
|
343
480
|
* Generate model, view and controller mocks that refer to each other.
|
|
344
481
|
*
|
|
@@ -346,13 +483,13 @@ export interface MVCMock {
|
|
|
346
483
|
* @returns Mocked model, view and controller instances
|
|
347
484
|
*/
|
|
348
485
|
export function mockMVC(existing?: Partial<MVCMock>): MVCMock {
|
|
349
|
-
const model = existing?.model ||
|
|
350
|
-
const view = existing?.view ||
|
|
351
|
-
const controller = existing?.controller ||
|
|
486
|
+
const model = existing?.model || createMockModel();
|
|
487
|
+
const view = existing?.view || createMockView();
|
|
488
|
+
const controller = existing?.controller || createMockController();
|
|
352
489
|
|
|
353
|
-
view.getController.mockReturnValue(controller);
|
|
354
|
-
view.getModel.mockReturnValue(model);
|
|
355
|
-
controller.getView.mockReturnValue(view);
|
|
490
|
+
view.mock.getController.mockReturnValue(controller);
|
|
491
|
+
view.mock.getModel.mockReturnValue(model);
|
|
492
|
+
controller.mock.getView.mockReturnValue(view);
|
|
356
493
|
|
|
357
494
|
return { model, view, controller };
|
|
358
495
|
}
|