|
| 1 | +// import { expect } from "chai"; |
| 2 | +// import { forEach, map } from "lodash"; |
| 3 | +// import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types"; |
| 4 | +// import { generateModel } from "@ui5-language-assistant/test-utils"; |
| 5 | +// import { generate } from "@ui5-language-assistant/semantic-model"; |
| 6 | +// import { XMLAttribute, XMLElement } from "@xml-tools/ast"; |
| 7 | +// import { iconSuggestions } from "../../../src/providers/attributeValue/icon"; |
| 8 | +// import { UI5XMLViewCompletion } from "../../../api"; |
| 9 | +// import { testSuggestionsScenario } from "../../utils"; |
| 10 | + |
| 11 | +// describe("The ui5-language-assistant xml-views-completion", () => { |
| 12 | +// let ui5SemanticModel: UI5SemanticModel; |
| 13 | +// before(async function () { |
| 14 | +// ui5SemanticModel = await generateModel({ |
| 15 | +// framework: "SAPUI5", |
| 16 | +// version: "1.71.49", |
| 17 | +// modelGenerator: generate, |
| 18 | +// }); |
| 19 | +// }); |
| 20 | + |
| 21 | +// context("icon values", () => { |
| 22 | +// context("applicable scenarios", () => { |
| 23 | +// it("will suggest icon values with no prefix provided", () => { |
| 24 | +// const xmlSnippet = ` |
| 25 | +// <mvc:View |
| 26 | +// xmlns:mvc="sap.ui.core.mvc" |
| 27 | +// xmlns="sap.m"> |
| 28 | +// <Button icon = "⇶"> |
| 29 | +// </Button> |
| 30 | +// </mvc:View>`; |
| 31 | + |
| 32 | +// testSuggestionsScenario({ |
| 33 | +// model: ui5SemanticModel, |
| 34 | +// xmlText: xmlSnippet, |
| 35 | +// providers: { |
| 36 | +// attributeValue: [iconSuggestions], |
| 37 | +// }, |
| 38 | +// assertion: (suggestions) => { |
| 39 | +// const suggestedValues = map(suggestions, (_) => _.ui5Node.name); |
| 40 | +// expect(suggestedValues).to.deep.equalInAnyOrder([ |
| 41 | +// "All", |
| 42 | +// "Inner", |
| 43 | +// "None", |
| 44 | +// ]); |
| 45 | +// expectIconValuesSuggestions(suggestions, "List"); |
| 46 | +// }, |
| 47 | +// }); |
| 48 | +// }); |
| 49 | + |
| 50 | +// it("will suggest icon values filtered by prefix", () => { |
| 51 | +// const xmlSnippet = ` |
| 52 | +// <mvc:View |
| 53 | +// xmlns:mvc="sap.ui.core.mvc" |
| 54 | +// xmlns="sap.m"> |
| 55 | +// <Button icon = "⇶"> |
| 56 | +// </Button> |
| 57 | +// </mvc:View>`; |
| 58 | + |
| 59 | +// testSuggestionsScenario({ |
| 60 | +// model: ui5SemanticModel, |
| 61 | +// xmlText: xmlSnippet, |
| 62 | +// providers: { |
| 63 | +// attributeValue: [iconSuggestions], |
| 64 | +// }, |
| 65 | +// assertion: (suggestions) => { |
| 66 | +// const suggestedValues = map(suggestions, (_) => _.ui5Node.name); |
| 67 | +// expect(suggestedValues).to.deep.equalInAnyOrder(["Inner", "None"]); |
| 68 | +// expectIconValuesSuggestions(suggestions, "List"); |
| 69 | +// }, |
| 70 | +// }); |
| 71 | +// }); |
| 72 | + |
| 73 | +// it("Will not suggest any icon values if none match the prefix", () => { |
| 74 | +// const xmlSnippet = ` |
| 75 | +// <mvc:View |
| 76 | +// xmlns:mvc="sap.ui.core.mvc" |
| 77 | +// xmlns="sap.m"> |
| 78 | +// <Button icon = "⇶"> |
| 79 | +// </Button> |
| 80 | +// </mvc:View>`; |
| 81 | + |
| 82 | +// testSuggestionsScenario({ |
| 83 | +// model: ui5SemanticModel, |
| 84 | +// xmlText: xmlSnippet, |
| 85 | +// providers: { |
| 86 | +// attributeValue: [iconSuggestions], |
| 87 | +// }, |
| 88 | +// assertion: (suggestions) => { |
| 89 | +// expect(suggestions).to.be.empty; |
| 90 | +// }, |
| 91 | +// }); |
| 92 | +// }); |
| 93 | +// }); |
| 94 | + |
| 95 | +// context("none applicable scenarios", () => { |
| 96 | +// it("will not provide any suggestions when the property is not of icon type", () => { |
| 97 | +// const xmlSnippet = ` |
| 98 | +// <mvc:View |
| 99 | +// xmlns:mvc="sap.ui.core.mvc" |
| 100 | +// xmlns="sap.m"> |
| 101 | +// <List icon = "⇶"> |
| 102 | +// </List> |
| 103 | +// </mvc:View>`; |
| 104 | + |
| 105 | +// testSuggestionsScenario({ |
| 106 | +// model: ui5SemanticModel, |
| 107 | +// xmlText: xmlSnippet, |
| 108 | +// providers: { |
| 109 | +// attributeValue: [iconSuggestions], |
| 110 | +// }, |
| 111 | +// assertion: (suggestions) => { |
| 112 | +// expect(suggestions).to.be.empty; |
| 113 | +// }, |
| 114 | +// }); |
| 115 | +// }); |
| 116 | + |
| 117 | +// it("will not provide any suggestions when it is not an attribute value completion", () => { |
| 118 | +// const xmlSnippet = ` |
| 119 | +// <mvc:View |
| 120 | +// xmlns:mvc="sap.ui.core.mvc" |
| 121 | +// xmlns="sap.m"> |
| 122 | +// <Button ⇶> |
| 123 | +// </Button> |
| 124 | +// </mvc:View>`; |
| 125 | + |
| 126 | +// testSuggestionsScenario({ |
| 127 | +// model: ui5SemanticModel, |
| 128 | +// xmlText: xmlSnippet, |
| 129 | +// providers: { |
| 130 | +// attributeValue: [iconSuggestions], |
| 131 | +// }, |
| 132 | +// assertion: (suggestions) => { |
| 133 | +// expect(suggestions).to.be.empty; |
| 134 | +// }, |
| 135 | +// }); |
| 136 | +// }); |
| 137 | + |
| 138 | +// it("will not provide any suggestions when the property type is undefined", () => { |
| 139 | +// const xmlSnippet = ` |
| 140 | +// <mvc:View |
| 141 | +// xmlns:mvc="sap.ui.core.mvc" |
| 142 | +// xmlns="sap.m"> |
| 143 | +// <App homeIcon = "⇶"> |
| 144 | +// </App> |
| 145 | +// </mvc:View>`; |
| 146 | + |
| 147 | +// testSuggestionsScenario({ |
| 148 | +// model: ui5SemanticModel, |
| 149 | +// xmlText: xmlSnippet, |
| 150 | +// providers: { |
| 151 | +// attributeValue: [iconSuggestions], |
| 152 | +// }, |
| 153 | +// assertion: (suggestions) => { |
| 154 | +// expect(suggestions).to.be.empty; |
| 155 | +// }, |
| 156 | +// }); |
| 157 | +// }); |
| 158 | + |
| 159 | +// it("will not provide any suggestions when not inside a UI5 Class", () => { |
| 160 | +// const xmlSnippet = ` |
| 161 | +// <mvc:View |
| 162 | +// xmlns:mvc="sap.ui.core.mvc" |
| 163 | +// xmlns="sap.m"> |
| 164 | +// <Bamba icon = "⇶"> |
| 165 | +// </Bamba> |
| 166 | +// </mvc:View>`; |
| 167 | + |
| 168 | +// testSuggestionsScenario({ |
| 169 | +// model: ui5SemanticModel, |
| 170 | +// xmlText: xmlSnippet, |
| 171 | +// providers: { |
| 172 | +// attributeValue: [iconSuggestions], |
| 173 | +// }, |
| 174 | +// assertion: (suggestions) => { |
| 175 | +// expect(ui5SemanticModel.classes["sap.ui.core.mvc.Bamba"]).to.be |
| 176 | +// .undefined; |
| 177 | +// expect(suggestions).to.be.empty; |
| 178 | +// }, |
| 179 | +// }); |
| 180 | +// }); |
| 181 | + |
| 182 | +// it("Will not suggest any enum values if there is no matching UI5 property", () => { |
| 183 | +// const xmlSnippet = ` |
| 184 | +// <mvc:View |
| 185 | +// xmlns:mvc="sap.ui.core.mvc" |
| 186 | +// xmlns="sap.m"> |
| 187 | +// <Button UNKNOWN = "⇶"> |
| 188 | +// </Button> |
| 189 | +// </mvc:View>`; |
| 190 | + |
| 191 | +// testSuggestionsScenario({ |
| 192 | +// model: ui5SemanticModel, |
| 193 | +// xmlText: xmlSnippet, |
| 194 | +// providers: { |
| 195 | +// attributeValue: [iconSuggestions], |
| 196 | +// }, |
| 197 | +// assertion: (suggestions) => { |
| 198 | +// expect(suggestions).to.be.empty; |
| 199 | +// }, |
| 200 | +// }); |
| 201 | +// }); |
| 202 | +// }); |
| 203 | +// }); |
| 204 | +// }); |
| 205 | + |
| 206 | +// function expectIconValuesSuggestions( |
| 207 | +// suggestions: UI5XMLViewCompletion[], |
| 208 | +// expectedParentTag: string |
| 209 | +// ): void { |
| 210 | +// forEach(suggestions, (_) => { |
| 211 | +// expect(_.type).to.equal(`UI5IconInXMLAttributeValue`); |
| 212 | +// expect((_.astNode as XMLAttribute).key).to.equal("showSeparators"); |
| 213 | +// expect((_.astNode.parent as XMLElement).name).to.equal(expectedParentTag); |
| 214 | +// }); |
| 215 | +// } |
0 commit comments