|
| 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, beforeEach, it, expect, beforeAll, afterAll */ |
| 23 | + |
| 24 | +define(function (require, exports, module) { |
| 25 | + |
| 26 | + |
| 27 | + // Load dependent modules |
| 28 | + let ScrollTrackMarkers, |
| 29 | + __PR, |
| 30 | + SpecRunnerUtils = require("spec/SpecRunnerUtils"); |
| 31 | + |
| 32 | + |
| 33 | + describe("integration:Scroll Track markers", function () { |
| 34 | + |
| 35 | + let testWindow, |
| 36 | + $, editor1Large, editor2; |
| 37 | + |
| 38 | + let currentProjectPath; |
| 39 | + |
| 40 | + beforeAll(async function () { |
| 41 | + testWindow = await SpecRunnerUtils.createTestWindowAndRun(); |
| 42 | + $ = testWindow.$; |
| 43 | + |
| 44 | + // Load module instances from brackets.test |
| 45 | + ScrollTrackMarkers = testWindow.brackets.test.ScrollTrackMarkers; |
| 46 | + __PR = testWindow.__PR; |
| 47 | + currentProjectPath = await SpecRunnerUtils.getTestPath("/spec/HTMLInstrumentation-test-files"); |
| 48 | + await SpecRunnerUtils.loadProjectInTestWindow(currentProjectPath); |
| 49 | + await __PR.EDITING.splitHorizontal(); |
| 50 | + await __PR.EDITING.openFileInFirstPane("REC-widgets-20121127.html", true); |
| 51 | + await __PR.EDITING.openFileInSecondPane("omitEndTags.html", true); |
| 52 | + editor1Large = __PR.EDITING.getFirstPaneEditor(); |
| 53 | + editor2 = __PR.EDITING.getSecondPaneEditor(); |
| 54 | + }, 30000); |
| 55 | + |
| 56 | + afterAll(async function () { |
| 57 | + await SpecRunnerUtils.parkProject(true); |
| 58 | + await __PR.EDITING.splitNone(); |
| 59 | + testWindow = null; |
| 60 | + __PR = null; |
| 61 | + await SpecRunnerUtils.closeTestWindow(); |
| 62 | + }, 30000); |
| 63 | + |
| 64 | + beforeEach(function () { |
| 65 | + ScrollTrackMarkers.clearAll(editor1Large); |
| 66 | + ScrollTrackMarkers.clearAll(editor2); |
| 67 | + }); |
| 68 | + |
| 69 | + |
| 70 | + it("should be able to add a line and side mark to both editors and clearAll", async function () { |
| 71 | + const trackerList = [{line: 10, ch: 0}]; |
| 72 | + ScrollTrackMarkers.addTickmarks(editor1Large, trackerList); |
| 73 | + expect($(".tickmark").length).toBe(1); |
| 74 | + ScrollTrackMarkers.addTickmarks(editor1Large, trackerList, { |
| 75 | + trackStyle: ScrollTrackMarkers.TRACK_STYLES.ON_LEFT |
| 76 | + }); |
| 77 | + expect($(".tickmark").length).toBe(2); |
| 78 | + expect($(".tickmark-side").length).toBe(1); |
| 79 | + ScrollTrackMarkers.addTickmarks(editor2, trackerList); |
| 80 | + expect($(".tickmark").length).toBe(3); |
| 81 | + expect($(".tickmark-side").length).toBe(1); |
| 82 | + ScrollTrackMarkers.addTickmarks(editor2, trackerList, { |
| 83 | + trackStyle: ScrollTrackMarkers.TRACK_STYLES.ON_LEFT |
| 84 | + }); |
| 85 | + expect($(".tickmark").length).toBe(4); |
| 86 | + expect($(".tickmark-side").length).toBe(2); |
| 87 | + |
| 88 | + // now clear all |
| 89 | + ScrollTrackMarkers.clearAll(editor1Large); |
| 90 | + expect($(".tickmark").length).toBe(2); |
| 91 | + expect($(".tickmark-side").length).toBe(1); |
| 92 | + ScrollTrackMarkers.clearAll(editor2); |
| 93 | + expect($(".tickmark").length).toBe(0); |
| 94 | + expect($(".tickmark-side").length).toBe(0); |
| 95 | + }); |
| 96 | + |
| 97 | + it("should be able to add and clear named marks", async function () { |
| 98 | + const trackerList = [{line: 10, ch: 0}]; |
| 99 | + const trackName1= "line_ed_1"; |
| 100 | + const trackName2= "side_ed_1"; |
| 101 | + ScrollTrackMarkers.addTickmarks(editor1Large, trackerList, { |
| 102 | + name: trackName1 |
| 103 | + }); |
| 104 | + expect($(".tickmark").length).toBe(1); |
| 105 | + ScrollTrackMarkers.addTickmarks(editor1Large, trackerList, { |
| 106 | + trackStyle: ScrollTrackMarkers.TRACK_STYLES.ON_LEFT, |
| 107 | + name: trackName2 |
| 108 | + }); |
| 109 | + expect($(".tickmark").length).toBe(2); |
| 110 | + expect($(".tickmark-side").length).toBe(1); |
| 111 | + |
| 112 | + // now remove by name |
| 113 | + ScrollTrackMarkers.clear(editor1Large, trackName1); |
| 114 | + expect($(".tickmark").length).toBe(1); |
| 115 | + expect($(".tickmark-side").length).toBe(1); |
| 116 | + ScrollTrackMarkers.clear(editor1Large, trackName2); |
| 117 | + expect($(".tickmark").length).toBe(0); |
| 118 | + expect($(".tickmark-side").length).toBe(0); |
| 119 | + }); |
| 120 | + |
| 121 | + it("should be able to add css classes marks", async function () { |
| 122 | + const trackerList = [{line: 10, ch: 0}]; |
| 123 | + const trackClass1= "line_ed_1"; |
| 124 | + const trackClass2= "side_ed_1"; |
| 125 | + ScrollTrackMarkers.addTickmarks(editor1Large, trackerList, { |
| 126 | + name: trackClass1, |
| 127 | + cssColorClass: trackClass1 |
| 128 | + }); |
| 129 | + expect($(`.tickmark.${trackClass1}`).length).toBe(1); |
| 130 | + expect($(".tickmark").length).toBe(1); |
| 131 | + ScrollTrackMarkers.addTickmarks(editor1Large, trackerList, { |
| 132 | + trackStyle: ScrollTrackMarkers.TRACK_STYLES.ON_LEFT, |
| 133 | + name: trackClass2, |
| 134 | + cssColorClass: trackClass2 |
| 135 | + }); |
| 136 | + expect($(`.tickmark-side.${trackClass2}`).length).toBe(1); |
| 137 | + expect($(".tickmark-side").length).toBe(1); |
| 138 | + }); |
| 139 | + |
| 140 | + it("should merge nearby scroll marks to single mark", async function () { |
| 141 | + const trackerList = [{line: 10, ch: 0}, {line: 11, ch: 0}]; |
| 142 | + ScrollTrackMarkers.addTickmarks(editor1Large, trackerList); |
| 143 | + expect($(".tickmark").length).toBe(1); |
| 144 | + expect($(".tickmark-side").length).toBe(0); |
| 145 | + ScrollTrackMarkers.addTickmarks(editor1Large, trackerList, { |
| 146 | + trackStyle: ScrollTrackMarkers.TRACK_STYLES.ON_LEFT |
| 147 | + }); |
| 148 | + expect($(".tickmark").length).toBe(2); |
| 149 | + expect($(".tickmark-side").length).toBe(1); |
| 150 | + }); |
| 151 | + |
| 152 | + it("should not merge far away scroll marks to single mark", async function () { |
| 153 | + const trackerList = [{line: 10, ch: 0}, {line: 2000, ch: 0}]; |
| 154 | + ScrollTrackMarkers.addTickmarks(editor1Large, trackerList); |
| 155 | + expect($(".tickmark").length).toBe(2); |
| 156 | + expect($(".tickmark-side").length).toBe(0); |
| 157 | + ScrollTrackMarkers.addTickmarks(editor1Large, trackerList, { |
| 158 | + trackStyle: ScrollTrackMarkers.TRACK_STYLES.ON_LEFT |
| 159 | + }); |
| 160 | + expect($(".tickmark").length).toBe(4); |
| 161 | + expect($(".tickmark-side").length).toBe(2); |
| 162 | + }); |
| 163 | + |
| 164 | + }); |
| 165 | +}); |
0 commit comments