Skip to content

Commit 1f24741

Browse files
maxreichmannd3xter666
authored andcommitted
test: Refactor fixtures for Core API
1 parent 15d6092 commit 1f24741

File tree

4 files changed

+57
-85
lines changed

4 files changed

+57
-85
lines changed

test/fixtures/autofix/coreApi/DeprecatedCoreApi.fixed.js

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,19 @@ sap.ui.define(["sap/ui/core/Core",
2121
IntervalTrigger.addListener(function() {console.log();});
2222
Core.attachIntervalTimer(function() {console.log();}, {});
2323

24-
Localization.attachChange(function() {console.log();});
25-
Core.attachLocalizationChanged(function() {console.log();}, {});
26-
27-
Theming.attachApplied(function() {console.log();});
28-
Core.attachThemeChanged(function() {console.log();}, {});
29-
3024
Control.getControlsByFieldGroupId("id");
3125
Control.getControlsByFieldGroupId(["id", "id2"]);
3226

3327
Element.getElementById("id");
3428

3529
Component.create({name: "componentName", url: "find/my/comp/here", id: "id", settings: {"settingsKey": "..."}});
36-
Component.create({name: "componentName", url: "find/my/comp/here", id: "id", settings: {"settingsKey": "..."}, component: {}});
30+
Core.createComponent({name: "componentName", url: "find/my/comp/here", id: "id", settings: {"settingsKey": "..."}, component: {}}); // Not autofixable
31+
Core.createComponent("componentName", "find/my/comp/here", "id", {"settingsKey": "..."}); // First argument is a string (not autofixable)
3732

3833
IntervalTrigger.removeListener(function() {console.log();});
3934
Core.detachIntervalTimer(function() {console.log();}, {});
4035

41-
Localization.detachChange(function() {console.log();});
42-
Core.detachLocalizationChanged(function() {console.log();}, {});
43-
44-
Theming.detachApplied(function() {console.log();});
45-
Core.detachThemeChanged(function() {console.log();}, {});
46-
47-
Component.get("componentId");
36+
Component.getComponentById("componentId");
4837

4938
Element.getElementById("controlId");
5039

@@ -56,30 +45,34 @@ sap.ui.define(["sap/ui/core/Core",
5645
EventBus.getInstance();
5746

5847
Lib.getResourceBundleFor("sap.ui.core", "en_US");
48+
Core.getLibraryResourceBundle("sap.ui.core", "en_US", "true");
5949

6050
StaticArea.getDomRef();
6151

62-
Template.byId("templateId");
63-
64-
Core.initLibrary({
65-
name: "sap.ui.core",
52+
Lib.init({
6653
version: "1.0.0",
54+
name: "sap.ui.core",
6755
dependencies: ["sap.ui.core"],
68-
noLibraryCSS: true,
6956
types: ["type1", "type2"],
7057
interfaces: ["interface1", "interface2"],
71-
elements: ["element1", "element2"],
7258
controls: ["control1", "control2"],
59+
elements: ["element1", "element2"],
60+
noLibraryCSS: true,
7361
extensions: {
7462
someExtension: {}
7563
}
7664
});
7765

7866
Device.browser.mobile;
7967

80-
StaticArea.contains(oDomRef);
68+
StaticArea.getDomRef() === oDomRef;
8169

70+
Lib.load({name: "sap.ui.core"});
71+
Lib.load({name: "sap.ui.core"});
8272
Lib.load({name: "sap.ui.core", url: "find/my/lib/here"});
73+
Core.loadLibrary("sap.ui.core", {async: false, url: "find/my/lib/here"});
74+
Core.loadLibrary("sap.ui.core", {url: "find/my/lib/here"});
75+
Core.loadLibrary("sap.ui.core", "find/my/lib/here");
8376

8477
Theming.notifyContentDensityChanged();
8578
});

test/fixtures/autofix/coreApi/DeprecatedCoreApi.js

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,18 @@ sap.ui.define(["sap/ui/core/Core",], function(Core) {
99
Core.attachIntervalTimer(function() {console.log();});
1010
Core.attachIntervalTimer(function() {}, {}); // Should not be autofixed if there is a 2nd argument
1111

12-
Core.attachLocalizationChanged(function() {console.log();});
13-
Core.attachLocalizationChanged(function() {console.log();}, {}); // Should not be autofixed if there is a 2nd argument
14-
15-
Core.attachThemeChanged(function() {console.log();});
16-
Core.attachThemeChanged(function() {console.log();}, {}); // Should not be autofixed if there is a 2nd argument
17-
1812
Core.byFieldGroupId("id");
1913
Core.byFieldGroupId(["id", "id2"]);
2014

2115
Core.byId("id");
2216

23-
Core.createComponent("componentName", "find/my/comp/here", "id", {"settingsKey": "..."}); // First argument is a string
24-
Core.createComponent({name: "componentName", url: "find/my/comp/here", id: "id", settings: {"settingsKey": "..."}, component: {}}); // First argument is an object
17+
Core.createComponent({name: "componentName", url: "find/my/comp/here", id: "id", settings: {"settingsKey": "..."}, component: {}, async: true}); // First argument must be an object and inside async:true to be autofixable
18+
Core.createComponent({name: "componentName", url: "find/my/comp/here", id: "id", settings: {"settingsKey": "..."}, component: {}}); // Not autofixable
19+
Core.createComponent("componentName", "find/my/comp/here", "id", {"settingsKey": "..."}); // First argument is a string (not autofixable)
2520

2621
Core.detachIntervalTimer(function() {console.log();});
2722
Core.detachIntervalTimer(function() {console.log();}, {}); // Should not be autofixed if there is a 2nd argument
2823

29-
Core.detachLocalizationChanged(function() {console.log();});
30-
Core.detachLocalizationChanged(function() {console.log();}, {}); // Should not be autofixed if there is a 2nd argument
31-
32-
Core.detachThemeChanged(function() {console.log();});
33-
Core.detachThemeChanged(function() {console.log();}, {}); // Should not be autofixed if there is a 2nd argument
34-
3524
Core.getComponent("componentId");
3625

3726
Core.getControl("controlId");
@@ -42,21 +31,20 @@ sap.ui.define(["sap/ui/core/Core",], function(Core) {
4231

4332
Core.getEventBus();
4433

45-
Core.getLibraryResourceBundle("sap.ui.core", "en_US", "true");
34+
Core.getLibraryResourceBundle("sap.ui.core", "en_US");
35+
Core.getLibraryResourceBundle("sap.ui.core", "en_US", "true"); // bAsync is true (not autofixable)
4636

4737
Core.getStaticAreaRef();
4838

49-
Core.getTemplate("templateId");
50-
5139
Core.initLibrary({
52-
name: "sap.ui.core",
5340
version: "1.0.0",
41+
name: "sap.ui.core",
5442
dependencies: ["sap.ui.core"],
55-
noLibraryCSS: true,
5643
types: ["type1", "type2"],
5744
interfaces: ["interface1", "interface2"],
58-
elements: ["element1", "element2"],
5945
controls: ["control1", "control2"],
46+
elements: ["element1", "element2"],
47+
noLibraryCSS: true,
6048
extensions: {
6149
someExtension: {}
6250
}
@@ -66,7 +54,12 @@ sap.ui.define(["sap/ui/core/Core",], function(Core) {
6654

6755
Core.isStaticAreaRef(oDomRef);
6856

69-
Core.loadLibrary("sap.ui.core", "find/my/lib/here");
57+
Core.loadLibrary("sap.ui.core");
58+
Core.loadLibrary("sap.ui.core", true);
59+
Core.loadLibrary("sap.ui.core", {async: true, url: "find/my/lib/here"});
60+
Core.loadLibrary("sap.ui.core", {async: false, url: "find/my/lib/here"}); // async:false (not autofixable)
61+
Core.loadLibrary("sap.ui.core", {url: "find/my/lib/here"}); // async omitted (not autofixable)
62+
Core.loadLibrary("sap.ui.core", "find/my/lib/here"); // async omitted (not autofixable)
7063

7164
Core.notifyContentDensityChanged();
7265

test/fixtures/autofix/coreApi/DeprecatedCoreApiWithoutImport.fixed.js

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,19 @@ sap.ui.define(["sap/ui/core/Core",
2121
IntervalTrigger.addListener(function() {console.log();});
2222
Core.attachIntervalTimer(function() {console.log();}, {});
2323

24-
Localization.attachChange(function() {console.log();});
25-
Core.attachLocalizationChanged(function() {console.log();}, {});
26-
27-
Theming.attachApplied(function() {console.log();});
28-
Core.attachThemeChanged(function() {console.log();}, {});
29-
3024
Control.getControlsByFieldGroupId("id");
3125
Control.getControlsByFieldGroupId(["id", "id2"]);
3226

3327
Element.getElementById("id");
3428

3529
Component.create({name: "componentName", url: "find/my/comp/here", id: "id", settings: {"settingsKey": "..."}});
36-
Component.create({name: "componentName", url: "find/my/comp/here", id: "id", settings: {"settingsKey": "..."}, component: {}});
30+
Core.createComponent({name: "componentName", url: "find/my/comp/here", id: "id", settings: {"settingsKey": "..."}, component: {}}); // Not autofixable
31+
Core.createComponent("componentName", "find/my/comp/here", "id", {"settingsKey": "..."}); // First argument is a string (not autofixable)
3732

3833
IntervalTrigger.removeListener(function() {console.log();});
3934
Core.detachIntervalTimer(function() {console.log();}, {});
4035

41-
Localization.detachChange(function() {console.log();});
42-
Core.detachLocalizationChanged(function() {console.log();}, {});
43-
44-
Theming.detachApplied(function() {console.log();});
45-
Core.detachThemeChanged(function() {console.log();}, {});
46-
47-
Component.get("componentId");
36+
Component.getComponentById("componentId");
4837

4938
Element.getElementById("controlId");
5039

@@ -56,30 +45,34 @@ sap.ui.define(["sap/ui/core/Core",
5645
EventBus.getInstance();
5746

5847
Lib.getResourceBundleFor("sap.ui.core", "en_US");
48+
Core.getLibraryResourceBundle("sap.ui.core", "en_US", "true");
5949

6050
StaticArea.getDomRef();
6151

62-
Template.byId("templateId");
63-
64-
Core.initLibrary({
65-
name: "sap.ui.core",
52+
Lib.init({
6653
version: "1.0.0",
54+
name: "sap.ui.core",
6755
dependencies: ["sap.ui.core"],
68-
noLibraryCSS: true,
6956
types: ["type1", "type2"],
7057
interfaces: ["interface1", "interface2"],
71-
elements: ["element1", "element2"],
7258
controls: ["control1", "control2"],
59+
elements: ["element1", "element2"],
60+
noLibraryCSS: true,
7361
extensions: {
7462
someExtension: {}
7563
}
7664
});
7765

7866
Device.browser.mobile;
7967

80-
StaticArea.contains(oDomRef);
68+
StaticArea.getDomRef() === oDomRef;
8169

70+
Lib.load({name: "sap.ui.core"});
71+
Lib.load({name: "sap.ui.core"});
8272
Lib.load({name: "sap.ui.core", url: "find/my/lib/here"});
73+
Core.loadLibrary("sap.ui.core", {async: false, url: "find/my/lib/here"});
74+
Core.loadLibrary("sap.ui.core", {url: "find/my/lib/here"});
75+
Core.loadLibrary("sap.ui.core", "find/my/lib/here");
8376

8477
Theming.notifyContentDensityChanged();
8578
});

test/fixtures/autofix/coreApi/DeprecatedCoreApiWithoutImport.js

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,18 @@ sap.ui.define([], function() {
99
sap.ui.getCore().attachIntervalTimer(function() {console.log();});
1010
sap.ui.getCore().attachIntervalTimer(function() {}, {}); // Should not be autofixed if there is a 2nd argument
1111

12-
sap.ui.getCore().attachLocalizationChanged(function() {console.log();});
13-
sap.ui.getCore().attachLocalizationChanged(function() {console.log();}, {}); // Should not be autofixed if there is a 2nd argument
14-
15-
sap.ui.getCore().attachThemeChanged(function() {console.log();});
16-
sap.ui.getCore().attachThemeChanged(function() {console.log();}, {}); // Should not be autofixed if there is a 2nd argument
17-
1812
sap.ui.getCore().byFieldGroupId("id");
1913
sap.ui.getCore().byFieldGroupId(["id", "id2"]);
2014

2115
sap.ui.getCore().byId("id");
2216

23-
sap.ui.getCore().createComponent("componentName", "find/my/comp/here", "id", {"settingsKey": "..."}); // First argument is a string
24-
sap.ui.getCore().createComponent({name: "componentName", url: "find/my/comp/here", id: "id", settings: {"settingsKey": "..."}, component: {}}); // First argument is an object
17+
sap.ui.getCore().createComponent({name: "componentName", url: "find/my/comp/here", id: "id", settings: {"settingsKey": "..."}, component: {}, async: true}); // First argument must be an object and inside async:true to be autofixable
18+
sap.ui.getCore().createComponent({name: "componentName", url: "find/my/comp/here", id: "id", settings: {"settingsKey": "..."}, component: {}}); // Not autofixable
19+
sap.ui.getCore().createComponent("componentName", "find/my/comp/here", "id", {"settingsKey": "..."}); // First argument is a string (not autofixable)
2520

2621
sap.ui.getCore().detachIntervalTimer(function() {console.log();});
2722
sap.ui.getCore().detachIntervalTimer(function() {console.log();}, {}); // Should not be autofixed if there is a 2nd argument
2823

29-
sap.ui.getCore().detachLocalizationChanged(function() {console.log();});
30-
sap.ui.getCore().detachLocalizationChanged(function() {console.log();}, {}); // Should not be autofixed if there is a 2nd argument
31-
32-
sap.ui.getCore().detachThemeChanged(function() {console.log();});
33-
sap.ui.getCore().detachThemeChanged(function() {console.log();}, {}); // Should not be autofixed if there is a 2nd argument
34-
3524
sap.ui.getCore().getComponent("componentId");
3625

3726
sap.ui.getCore().getControl("controlId");
@@ -42,21 +31,20 @@ sap.ui.define([], function() {
4231

4332
sap.ui.getCore().getEventBus();
4433

45-
sap.ui.getCore().getLibraryResourceBundle("sap.ui.core", "en_US", "true");
34+
sap.ui.getCore().getLibraryResourceBundle("sap.ui.core", "en_US");
35+
sap.ui.getCore().getLibraryResourceBundle("sap.ui.core", "en_US", "true"); // bAsync is true (not autofixable)
4636

4737
sap.ui.getCore().getStaticAreaRef();
4838

49-
sap.ui.getCore().getTemplate("templateId");
50-
5139
sap.ui.getCore().initLibrary({
52-
name: "sap.ui.core",
5340
version: "1.0.0",
41+
name: "sap.ui.core",
5442
dependencies: ["sap.ui.core"],
55-
noLibraryCSS: true,
5643
types: ["type1", "type2"],
5744
interfaces: ["interface1", "interface2"],
58-
elements: ["element1", "element2"],
5945
controls: ["control1", "control2"],
46+
elements: ["element1", "element2"],
47+
noLibraryCSS: true,
6048
extensions: {
6149
someExtension: {}
6250
}
@@ -66,8 +54,13 @@ sap.ui.define([], function() {
6654

6755
sap.ui.getCore().isStaticAreaRef(oDomRef);
6856

69-
sap.ui.getCore().loadLibrary("sap.ui.core", "find/my/lib/here");
57+
sap.ui.getCore().loadLibrary("sap.ui.core");
58+
sap.ui.getCore().loadLibrary("sap.ui.core", true);
59+
sap.ui.getCore().loadLibrary("sap.ui.core", {async: true, url: "find/my/lib/here"});
60+
sap.ui.getCore().loadLibrary("sap.ui.core", {async: false, url: "find/my/lib/here"}); // async:false (not autofixable)
61+
sap.ui.getCore().loadLibrary("sap.ui.core", {url: "find/my/lib/here"}); // async omitted (not autofixable)
62+
sap.ui.getCore().loadLibrary("sap.ui.core", "find/my/lib/here"); // async omitted (not autofixable)
7063

7164
sap.ui.getCore().notifyContentDensityChanged();
72-
});
7365

66+
});

0 commit comments

Comments
 (0)