|
| 1 | +/* eslint-env mocha */ |
| 2 | + |
| 3 | +const assert = require("assert"); |
| 4 | +// const sinon = require("sinon"); |
| 5 | + |
| 6 | +// tested module |
| 7 | +const themingParametersDataUri = require("../../../lib/themingParameters/dataUri"); |
| 8 | + |
| 9 | +describe("themingParameters/dataUri", function() { |
| 10 | + it("should not add theming parameters when library name is missing", function() { |
| 11 | + const result = {}; |
| 12 | + const options = {}; |
| 13 | + const returnedResult = themingParametersDataUri.addInlineParameters({result, options}); |
| 14 | + |
| 15 | + assert.equal(returnedResult, result, "result object reference should be returned"); |
| 16 | + assert.deepEqual(result, {}, "result object should not be modified"); |
| 17 | + }); |
| 18 | + |
| 19 | + it("should add theming parameters to css", function() { |
| 20 | + const result = { |
| 21 | + css: "/* css */", |
| 22 | + variables: {foo: "bar"} |
| 23 | + }; |
| 24 | + const options = { |
| 25 | + library: { |
| 26 | + name: "sap.ui.test" |
| 27 | + } |
| 28 | + }; |
| 29 | + const returnedResult = themingParametersDataUri.addInlineParameters({result, options}); |
| 30 | + |
| 31 | + assert.equal(returnedResult, result, "result object reference should be returned"); |
| 32 | + assert.deepEqual(result, { |
| 33 | + variables: {foo: "bar"}, |
| 34 | + css: `/* css */ |
| 35 | +/* Inline theming parameters */ |
| 36 | +#sap-ui-theme-sap\\.ui\\.test{background-image:url('data:text/plain;utf-8,%7B%22foo%22%3A%22bar%22%7D')} |
| 37 | +` |
| 38 | + }, "result.css should be enhanced"); |
| 39 | + }); |
| 40 | + |
| 41 | + it("should encode variables to be included as data-uri", function() { |
| 42 | + const result = { |
| 43 | + css: "/* css */", |
| 44 | + variables: { |
| 45 | + foo: "50%", |
| 46 | + bar: "'\"'" |
| 47 | + } |
| 48 | + }; |
| 49 | + const options = { |
| 50 | + library: { |
| 51 | + name: "sap.ui.test" |
| 52 | + } |
| 53 | + }; |
| 54 | + const returnedResult = themingParametersDataUri.addInlineParameters({result, options}); |
| 55 | + |
| 56 | + assert.equal(returnedResult, result, "result object reference should be returned"); |
| 57 | + assert.deepEqual(result, { |
| 58 | + variables: { |
| 59 | + foo: "50%", |
| 60 | + bar: "'\"'" |
| 61 | + }, |
| 62 | + css: `/* css */ |
| 63 | +/* Inline theming parameters */ |
| 64 | +#sap-ui-theme-sap\\.ui\\.test{background-image:url('\ |
| 65 | +data:text/plain;utf-8,%7B%22foo%22%3A%2250%25%22%2C%22bar%22%3A%22%27%5C%22%27%22%7D')} |
| 66 | +` |
| 67 | + }, "result.css should be enhanced"); |
| 68 | + }); |
| 69 | + |
| 70 | + it("should add theming parameters to cssRtl when options.rtl=true", function() { |
| 71 | + const result = { |
| 72 | + css: "/* css */", |
| 73 | + cssRtl: "/* cssRtl */", |
| 74 | + variables: {foo: "bar"} |
| 75 | + }; |
| 76 | + const options = { |
| 77 | + library: { |
| 78 | + name: "sap.ui.test" |
| 79 | + }, |
| 80 | + rtl: true |
| 81 | + }; |
| 82 | + const returnedResult = themingParametersDataUri.addInlineParameters({result, options}); |
| 83 | + |
| 84 | + assert.equal(returnedResult, result, "result object reference should be returned"); |
| 85 | + assert.deepEqual(result, { |
| 86 | + variables: {foo: "bar"}, |
| 87 | + css: `/* css */ |
| 88 | +/* Inline theming parameters */ |
| 89 | +#sap-ui-theme-sap\\.ui\\.test{background-image:url('data:text/plain;utf-8,%7B%22foo%22%3A%22bar%22%7D')} |
| 90 | +`, |
| 91 | + cssRtl: `/* cssRtl */ |
| 92 | +/* Inline theming parameters */ |
| 93 | +#sap-ui-theme-sap\\.ui\\.test{background-image:url('data:text/plain;utf-8,%7B%22foo%22%3A%22bar%22%7D')} |
| 94 | +` |
| 95 | + }, "result.css should be enhanced"); |
| 96 | + }); |
| 97 | + |
| 98 | + it("should add theming parameters to cssVariables when options.cssVariables=true", function() { |
| 99 | + const result = { |
| 100 | + css: "/* css */", |
| 101 | + cssVariables: "/* cssVariables */", |
| 102 | + variables: {foo: "bar"} |
| 103 | + }; |
| 104 | + const options = { |
| 105 | + library: { |
| 106 | + name: "sap.ui.test" |
| 107 | + }, |
| 108 | + cssVariables: true |
| 109 | + }; |
| 110 | + const returnedResult = themingParametersDataUri.addInlineParameters({result, options}); |
| 111 | + |
| 112 | + assert.equal(returnedResult, result, "result object reference should be returned"); |
| 113 | + assert.deepEqual(result, { |
| 114 | + variables: {foo: "bar"}, |
| 115 | + css: `/* css */ |
| 116 | +/* Inline theming parameters */ |
| 117 | +#sap-ui-theme-sap\\.ui\\.test{background-image:url('data:text/plain;utf-8,%7B%22foo%22%3A%22bar%22%7D')} |
| 118 | +`, |
| 119 | + cssVariables: `/* cssVariables */ |
| 120 | +/* Inline theming parameters */ |
| 121 | +#sap-ui-theme-sap\\.ui\\.test{background-image:url('data:text/plain;utf-8,%7B%22foo%22%3A%22bar%22%7D')} |
| 122 | +` |
| 123 | + }, "result.css should be enhanced"); |
| 124 | + }); |
| 125 | + |
| 126 | + it("should add theming parameters to cssRtl / cssVariables when options.rtl/cssVariables=true", function() { |
| 127 | + const result = { |
| 128 | + css: "/* css */", |
| 129 | + cssRtl: "/* cssRtl */", |
| 130 | + cssVariables: "/* cssVariables */", |
| 131 | + variables: {foo: "bar"} |
| 132 | + }; |
| 133 | + const options = { |
| 134 | + library: { |
| 135 | + name: "sap.ui.test" |
| 136 | + }, |
| 137 | + rtl: true, |
| 138 | + cssVariables: true |
| 139 | + }; |
| 140 | + const returnedResult = themingParametersDataUri.addInlineParameters({result, options}); |
| 141 | + |
| 142 | + assert.equal(returnedResult, result, "result object reference should be returned"); |
| 143 | + assert.deepEqual(result, { |
| 144 | + variables: {foo: "bar"}, |
| 145 | + css: `/* css */ |
| 146 | +/* Inline theming parameters */ |
| 147 | +#sap-ui-theme-sap\\.ui\\.test{background-image:url('data:text/plain;utf-8,%7B%22foo%22%3A%22bar%22%7D')} |
| 148 | +`, |
| 149 | + cssRtl: `/* cssRtl */ |
| 150 | +/* Inline theming parameters */ |
| 151 | +#sap-ui-theme-sap\\.ui\\.test{background-image:url('data:text/plain;utf-8,%7B%22foo%22%3A%22bar%22%7D')} |
| 152 | +`, |
| 153 | + cssVariables: `/* cssVariables */ |
| 154 | +/* Inline theming parameters */ |
| 155 | +#sap-ui-theme-sap\\.ui\\.test{background-image:url('data:text/plain;utf-8,%7B%22foo%22%3A%22bar%22%7D')} |
| 156 | +` |
| 157 | + }, "result.css should be enhanced"); |
| 158 | + }); |
| 159 | +}); |
0 commit comments