Skip to content

Commit fc7f124

Browse files
committed
test: css validation unit tests
1 parent 05fe456 commit fc7f124

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

test/test-css.worker.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ describe(`web worker CSS Language tests`, async function () {
8282
* - "fontFaceProperties": Ensures necessary properties are included in @font-face declarations.
8383
* - "hexColorLength": Enforces consistency in hex color definitions.
8484
* - "argumentsInColorFunction": Validates arguments within color functions.
85-
* - "ieHack": Warns about CSS hacks for older versions of Internet Explorer.
8685
* - "unknownVendorSpecificProperties": Flags vendor-specific properties that might not be universally recognized.
8786
* - "propertyIgnoredDueToDisplay": Notifies when CSS properties are ignored due to the `display` setting of an element.
8887
* - "important": Warns against the excessive use of `!important`.
@@ -97,11 +96,43 @@ describe(`web worker CSS Language tests`, async function () {
9796
* emptyRules: "warning"
9897
* unknownProperties: "warning"
9998
* ieHack: "warning"
99+
* propertyIgnoredDueToDisplay: "warning"
100100
* // leave default
101101
* importStatement: none
102102
* boxModel: none
103103
*/
104104

105+
it("should validate css propertyIgnoredDueToDisplay", async function () {
106+
const cssValidationData = await (await fetch("test-files/cssValidationData.json")).json();
107+
messageFromWorker = null;
108+
const text = `.element {
109+
display: inline-block;
110+
float: right;
111+
}`;
112+
worker.postMessage({
113+
command: `validateCSS`, text, cssMode: "CSS", filePath: "file:///c.css", lintSettings: {
114+
propertyIgnoredDueToDisplay: "warning"
115+
}
116+
});
117+
let output = await waitForWorkerMessage(`validateCSS`, 1000);
118+
const symbols = output.diag;
119+
expect(symbols).to.deep.equal(cssValidationData["propertyIgnoredDueToDisplay"]);
120+
});
121+
122+
it("should validate css propertyIgnoredDueToDisplay by default", async function () {
123+
const cssValidationData = await (await fetch("test-files/cssValidationData.json")).json();
124+
messageFromWorker = null;
125+
const text = `.element {
126+
display: inline-block;
127+
float: right;
128+
}`;
129+
worker.postMessage({
130+
command: `validateCSS`, text, cssMode: "CSS", filePath: "file:///c.css"});
131+
let output = await waitForWorkerMessage(`validateCSS`, 1000);
132+
const symbols = output.diag;
133+
expect(symbols).to.deep.equal(cssValidationData["propertyIgnoredDueToDisplay"]);
134+
});
135+
105136
it("should validate css ieHack", async function () {
106137
const cssValidationData = await (await fetch("test-files/cssValidationData.json")).json();
107138
messageFromWorker = null;

test/test-files/cssValidationData.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,5 +155,21 @@
155155
"character": 18
156156
}
157157
}
158+
}],
159+
"propertyIgnoredDueToDisplay": [{
160+
"code": "propertyIgnoredDueToDisplay",
161+
"source": "css",
162+
"message": "inline-block is ignored due to the float. If 'float' has a value other than 'none', the box is floated and 'display' is treated as 'block'",
163+
"severity": 2,
164+
"range": {
165+
"start": {
166+
"line": 2,
167+
"character": 12
168+
},
169+
"end": {
170+
"line": 2,
171+
"character": 24
172+
}
173+
}
158174
}]
159175
}

0 commit comments

Comments
 (0)