|
| 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, beforeAll, afterAll */ |
| 23 | + |
| 24 | +define(function (require, exports, module) { |
| 25 | + |
| 26 | + |
| 27 | + var SpecRunnerUtils = require("spec/SpecRunnerUtils"); |
| 28 | + |
| 29 | + describe("integration:Auto space and tabs detect", function () { |
| 30 | + const testRootSpec = "/spec/space-detect-test-files/"; |
| 31 | + let testProjectsFolder = SpecRunnerUtils.getTestPath(testRootSpec), |
| 32 | + testWindow, |
| 33 | + $, |
| 34 | + __PR; // __PR can be debugged using debug menu> phoenix code diag tools> test builder |
| 35 | + |
| 36 | + beforeAll(async function () { |
| 37 | + testWindow = await SpecRunnerUtils.createTestWindowAndRun(); |
| 38 | + // Load module instances from brackets.test |
| 39 | + await SpecRunnerUtils.loadProjectInTestWindow(testProjectsFolder); |
| 40 | + __PR = testWindow.__PR; |
| 41 | + $ = testWindow.$; |
| 42 | + }, 30000); |
| 43 | + |
| 44 | + afterAll(async function () { |
| 45 | + await __PR.closeAll(); |
| 46 | + testWindow = null; |
| 47 | + __PR = null; |
| 48 | + $ = null; |
| 49 | + await SpecRunnerUtils.closeTestWindow(); |
| 50 | + }, 30000); |
| 51 | + |
| 52 | + function validateSpacing(type, value, autoMode) { |
| 53 | + __PR.validateEqual($("#indent-type").text(), type); |
| 54 | + __PR.validateEqual($("#indent-width-label").text(), value); |
| 55 | + __PR.validateEqual($("#indent-auto").text(), autoMode); |
| 56 | + } |
| 57 | + |
| 58 | + it(`should detect 1 space auto`, async function () { |
| 59 | + await __PR.openFile("space-1.js"); |
| 60 | + validateSpacing("Spaces:", "1", "Auto"); |
| 61 | + await __PR.closeFile(); |
| 62 | + }); |
| 63 | + |
| 64 | + it(`should detect 12 space as 10 spaces auto`, async function () { |
| 65 | + await __PR.openFile("space-12.js"); |
| 66 | + validateSpacing("Spaces:", "10", "Auto"); |
| 67 | + await __PR.closeFile(); |
| 68 | + }); |
| 69 | + |
| 70 | + it(`should detect no space as default 4 spaces auto`, async function () { |
| 71 | + await __PR.openFile("space-none.js"); |
| 72 | + validateSpacing("Spaces:", "4", "Auto"); |
| 73 | + await __PR.closeFile(); |
| 74 | + }); |
| 75 | + |
| 76 | + it(`should detect 2 tabs auto`, async function () { |
| 77 | + await __PR.openFile("tab-2.js"); |
| 78 | + validateSpacing("Tab Size:", "2", "Auto"); |
| 79 | + await __PR.closeFile(); |
| 80 | + }); |
| 81 | + |
| 82 | + it(`should detect 12 tabs as 10 tabs auto`, async function () { |
| 83 | + await __PR.openFile("tab-12.js"); |
| 84 | + validateSpacing("Tab Size:", "10", "Auto"); |
| 85 | + await __PR.closeFile(); |
| 86 | + }); |
| 87 | + |
| 88 | + it(`should be able to override individual file's tab/spacing in auto mode`, async function () { |
| 89 | + await __PR.openFile("space-1.js"); |
| 90 | + validateSpacing("Spaces:", "1", "Auto"); |
| 91 | + $("#indent-type").click(); |
| 92 | + validateSpacing("Tab Size:", "4", "Auto"); |
| 93 | + // now switch to another file |
| 94 | + await __PR.openFile("tab-2.js"); |
| 95 | + validateSpacing("Tab Size:", "2", "Auto"); |
| 96 | + // now switch back and it should remember the overridden settings |
| 97 | + await __PR.openFile("space-1.js"); |
| 98 | + validateSpacing("Tab Size:", "4", "Auto"); |
| 99 | + // now change the tab units |
| 100 | + __PR.EDITING.setEditorSpacing(true, 6, true); |
| 101 | + validateSpacing("Tab Size:", "6", "Auto"); |
| 102 | + // now close the file and switch to another file |
| 103 | + await __PR.closeFile(); |
| 104 | + await __PR.openFile("tab-2.js"); |
| 105 | + validateSpacing("Tab Size:", "2", "Auto"); |
| 106 | + // now switch back and it should remember the overridden settings |
| 107 | + await __PR.openFile("space-1.js"); |
| 108 | + validateSpacing("Tab Size:", "6", "Auto"); |
| 109 | + await __PR.closeFile(); |
| 110 | + }); |
| 111 | + }); |
| 112 | +}); |
0 commit comments