|
| 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, beforeAll, afterAll, beforeEach, awaitsForDone, awaits, awaitsFor, path, jsPromise */ |
| 23 | + |
| 24 | +define(function (require, exports, module) { |
| 25 | + |
| 26 | + |
| 27 | + var SpecRunnerUtils = require("spec/SpecRunnerUtils"); |
| 28 | + |
| 29 | + describe("integration:ColorPreview in gutter", function () { |
| 30 | + const testRootSpec = "/spec/CSSColorPreview-test-files/"; |
| 31 | + const GUTTER_NAME = "CodeMirror-colorGutter", |
| 32 | + SINGLE_COLOR_PREVIEW_CLASS = "ico-cssColorPreview", |
| 33 | + MULTI_COLOR_PREVIEW_CLASS = "ico-multiple-cssColorPreview", |
| 34 | + DUMMY_GUTTER_CLASS = "CodeMirror-colorGutter-none"; |
| 35 | + let testProjectFolder, |
| 36 | + testWindow, |
| 37 | + EditorManager, |
| 38 | + __PR; // __PR can be debugged using debug menu> phoenix code diag tools> test builder |
| 39 | + |
| 40 | + beforeAll(async function () { |
| 41 | + testWindow = await SpecRunnerUtils.createTestWindowAndRun(); |
| 42 | + // Load module instances from brackets.test |
| 43 | + testProjectFolder = await SpecRunnerUtils.getTempTestDirectory(testRootSpec); |
| 44 | + await SpecRunnerUtils.loadProjectInTestWindow(testProjectFolder); |
| 45 | + __PR = testWindow.__PR; |
| 46 | + EditorManager = testWindow.EditorManager; |
| 47 | + }, 30000); |
| 48 | + |
| 49 | + afterAll(async function () { |
| 50 | + await __PR.closeAll(); |
| 51 | + testWindow = null; |
| 52 | + __PR = null; |
| 53 | + EditorManager = null; |
| 54 | + await SpecRunnerUtils.closeTestWindow(); |
| 55 | + }, 30000); |
| 56 | + |
| 57 | + it("should color gutter not appear in cpp files", async function () { |
| 58 | + const fileName = "a.cpp"; |
| 59 | + await __PR.writeTextFile(fileName, "#include <iostream>", true); |
| 60 | + await __PR.openFile(fileName); |
| 61 | + const editor = EditorManager.getActiveEditor(); |
| 62 | + __PR.validateEqual(editor.isGutterActive(GUTTER_NAME), false); |
| 63 | + await __PR.closeFile(); |
| 64 | + }); |
| 65 | + |
| 66 | + function testHTMLFile(fileName) { |
| 67 | + it(`should color gutter appear as expected ${fileName}`, async function () { |
| 68 | + const htmlText = await __PR.readTextFile("base.html"); |
| 69 | + await __PR.writeTextFile(fileName, htmlText, true); |
| 70 | + await __PR.openFile(fileName); |
| 71 | + const editor = EditorManager.getActiveEditor(); |
| 72 | + __PR.validateEqual(editor.isGutterActive(GUTTER_NAME), true); |
| 73 | + |
| 74 | + // the line with cursor if there is no color should have a dummy color gutter |
| 75 | + __PR.setCursors(["1:1"]); |
| 76 | + let gutterMarker = editor.getGutterMarker(0, GUTTER_NAME); |
| 77 | + __PR.validateEqual(gutterMarker.classList.contains(DUMMY_GUTTER_CLASS), true); |
| 78 | + |
| 79 | + // should have no color boxes as expected |
| 80 | + const colorBoxesInLines = [8, 11, 12, 13, 14, 15]; |
| 81 | + const singleColorBoxesInLines = [8, 11]; |
| 82 | + const multiColorBoxesInLines = [12, 13, 14, 15]; |
| 83 | + for (let line = 1; line < editor.lineCount(); line++) { |
| 84 | + gutterMarker = editor.getGutterMarker(line, GUTTER_NAME); |
| 85 | + if (!colorBoxesInLines.includes(line)) { |
| 86 | + // there should be no color box here |
| 87 | + __PR.validateEqual(!!gutterMarker, false); |
| 88 | + } else if(singleColorBoxesInLines.includes(line)) { |
| 89 | + __PR.validateEqual(gutterMarker.classList.contains(SINGLE_COLOR_PREVIEW_CLASS), true); |
| 90 | + } else if(multiColorBoxesInLines.includes(line)) { |
| 91 | + __PR.validateEqual(gutterMarker.classList.contains(MULTI_COLOR_PREVIEW_CLASS), true); |
| 92 | + } |
| 93 | + } |
| 94 | + await __PR.closeFile(); |
| 95 | + |
| 96 | + }); |
| 97 | + } |
| 98 | + |
| 99 | + const htmlFiles = ["a.html", "a.htm", "a.xhtml", "a.php", "a.jsp"]; |
| 100 | + for(let htmlFile of htmlFiles){ |
| 101 | + testHTMLFile(htmlFile); |
| 102 | + } |
| 103 | + }); |
| 104 | +}); |
0 commit comments