|
| 1 | +/* |
| 2 | + * GNU AGPL-3.0 License |
| 3 | + * |
| 4 | + * Copyright (c) 2021 - present core.ai . All rights reserved. |
| 5 | + * Original work Copyright (c) 2013 - 2021 Adobe Systems Incorporated. All rights reserved. |
| 6 | + * |
| 7 | + * This program is free software: you can redistribute it and/or modify it |
| 8 | + * under the terms of the GNU Affero General Public License as published by |
| 9 | + * the Free Software Foundation, either version 3 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
| 13 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License |
| 15 | + * for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU Affero General Public License |
| 18 | + * along with this program. If not, see https://opensource.org/licenses/AGPL-3.0. |
| 19 | + * |
| 20 | + */ |
| 21 | + |
| 22 | +/*global describe, it, expect, beforeEach, awaitsFor, awaitsForDone, afterAll */ |
| 23 | + |
| 24 | +define(function (require, exports, module) { |
| 25 | + |
| 26 | + |
| 27 | + const SpecRunnerUtils = require("spec/SpecRunnerUtils"); |
| 28 | + |
| 29 | + describe("integration:CSS Code Hints Language Service", function () { |
| 30 | + let testFolder = SpecRunnerUtils.getTestPath("/spec/LanguageTools-test-files/css-language-service"); |
| 31 | + |
| 32 | + // load from testWindow |
| 33 | + let testWindow, |
| 34 | + brackets, |
| 35 | + EditorManager, |
| 36 | + QuickView, |
| 37 | + editor, |
| 38 | + testFile = "css-lint-errors.css"; |
| 39 | + |
| 40 | + beforeEach(async function () { |
| 41 | + // Create a new window that will be shared by ALL tests in this spec. |
| 42 | + if (!testWindow) { |
| 43 | + testWindow = await SpecRunnerUtils.createTestWindowAndRun(); |
| 44 | + |
| 45 | + await SpecRunnerUtils.loadProjectInTestWindow(testFolder); |
| 46 | + } |
| 47 | + |
| 48 | + // Load module instances from brackets.test |
| 49 | + brackets = testWindow.brackets; |
| 50 | + EditorManager = brackets.test.EditorManager; |
| 51 | + QuickView = brackets.test.QuickViewManager; |
| 52 | + |
| 53 | + await awaitsForDone(SpecRunnerUtils.openProjectFiles([testFile]), "open test file: " + testFile); |
| 54 | + |
| 55 | + editor = EditorManager.getCurrentFullEditor(); |
| 56 | + }, 30000); |
| 57 | + |
| 58 | + afterAll(async function () { |
| 59 | + testWindow = null; |
| 60 | + brackets = null; |
| 61 | + EditorManager = null; |
| 62 | + QuickView = null; |
| 63 | + await SpecRunnerUtils.closeTestWindow(); |
| 64 | + }, 30000); |
| 65 | + |
| 66 | + async function getPopoverAtPos(lineNum, columnNum) { |
| 67 | + editor = EditorManager.getCurrentFullEditor(); |
| 68 | + let cm = editor._codeMirror, |
| 69 | + pos = { line: lineNum, ch: columnNum }, |
| 70 | + token; |
| 71 | + |
| 72 | + editor.setCursorPos(pos); |
| 73 | + token = cm.getTokenAt(pos, true); |
| 74 | + |
| 75 | + return QuickView._queryPreviewProviders(editor, pos, token); |
| 76 | + } |
| 77 | + |
| 78 | + async function expectNoCSSLintQuickViewAtPos(line, ch) { |
| 79 | + let popoverInfo = await getPopoverAtPos(line, ch); |
| 80 | + if(popoverInfo){ |
| 81 | + expect(popoverInfo.content.find(".code-inspection-item").length).toBe(0); |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + async function checkCSSWarningAtPos(expectedWarning, line, ch) { |
| 86 | + await awaitsFor(async ()=>{ |
| 87 | + return await getPopoverAtPos(line, ch); |
| 88 | + }, "popover to be present"); |
| 89 | + let popoverInfo = await getPopoverAtPos(line, ch); |
| 90 | + expect(popoverInfo.content.find(".code-inspection-item").text().trim()).toBe(expectedWarning); |
| 91 | + } |
| 92 | + |
| 93 | + describe("CSS warnings quick view", function () { |
| 94 | + it("Should show warning", async function () { |
| 95 | + await checkCSSWarningAtPos("Do not use empty rulesets (emptyRules)", 2, 0); |
| 96 | + }); |
| 97 | + |
| 98 | + it("Should show no warning for imports", async function () { |
| 99 | + await expectNoCSSLintQuickViewAtPos(1, 1); |
| 100 | + }); |
| 101 | + |
| 102 | + it("Should show duplicate properties warning", async function () { |
| 103 | + await checkCSSWarningAtPos("Do not use duplicate style definitions (duplicateProperties)", |
| 104 | + 5, 8); |
| 105 | + await checkCSSWarningAtPos("Do not use duplicate style definitions (duplicateProperties)", |
| 106 | + 6, 8); |
| 107 | + }); |
| 108 | + |
| 109 | + it("Should show duplicate properties warning", async function () { |
| 110 | + await checkCSSWarningAtPos("No unit for zero needed (zeroUnits)", |
| 111 | + 10, 11); |
| 112 | + }); |
| 113 | + |
| 114 | + it("Should show no warning for box model", async function () { |
| 115 | + // dont use width and height when using padding |
| 116 | + await expectNoCSSLintQuickViewAtPos(14, 8); |
| 117 | + await expectNoCSSLintQuickViewAtPos(15, 8); |
| 118 | + await expectNoCSSLintQuickViewAtPos(16, 8); |
| 119 | + }); |
| 120 | + |
| 121 | + it("Should show unknown properties warning", async function () { |
| 122 | + await checkCSSWarningAtPos("Unknown property: 'doesntExist' (unknownProperties)", |
| 123 | + 20, 8); |
| 124 | + }); |
| 125 | + |
| 126 | + it("Should show ie hack warning", async function () { |
| 127 | + await checkCSSWarningAtPos("IE hacks are only necessary when supporting IE7 and older (ieHack)", |
| 128 | + 25, 8); |
| 129 | + }); |
| 130 | + |
| 131 | + it("Should show ignored due to display warning", async function () { |
| 132 | + await checkCSSWarningAtPos("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' (propertyIgnoredDueToDisplay)", |
| 133 | + 30, 8); |
| 134 | + }); |
| 135 | + |
| 136 | + it("Should show no warning on !important", async function () { |
| 137 | + await expectNoCSSLintQuickViewAtPos(34, 8); |
| 138 | + await expectNoCSSLintQuickViewAtPos(35, 8); |
| 139 | + }); |
| 140 | + |
| 141 | + it("Should show font-face warning", async function () { |
| 142 | + await checkCSSWarningAtPos("@font-face rule must define 'src' and 'font-family' properties (fontFaceProperties)", |
| 143 | + 38, 8); |
| 144 | + await checkCSSWarningAtPos("@font-face rule must define 'src' and 'font-family' properties (fontFaceProperties)", |
| 145 | + 39, 8); |
| 146 | + }); |
| 147 | + }); |
| 148 | + |
| 149 | + }); |
| 150 | +}); |
0 commit comments