forked from phcode-dev/staging.phcode.dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinteg-tests.js
More file actions
1 lines (1 loc) · 8.66 KB
/
Copy pathinteg-tests.js
File metadata and controls
1 lines (1 loc) · 8.66 KB
1
define(function(require,exports,module){const SpecRunnerUtils=brackets.getModule("spec/SpecRunnerUtils"),StringUtils=brackets.getModule("utils/StringUtils"),KeyEvent=brackets.getModule("utils/KeyEvent");describe("integration:HTML Code Hints integration tests",function(){const testPath=SpecRunnerUtils.getTestPath("/spec/LiveDevelopment-MultiBrowser-test-files");let FileViewController,ProjectManager,CommandManager,Commands,testWindow,EditorManager,MainViewManager,brackets,FileSystem,CSSUtils,$;async function closeSession(){await awaitsForDone(CommandManager.execute(Commands.FILE_CLOSE_ALL,{_forceClose:!0}),"closing all file")}async function openFile(fileNameInProject,workingSet){await awaitsForDone(FileViewController.openAndSelectDocument(testPath+"/"+fileNameInProject,workingSet?FileViewController.WORKING_SET_VIEW:FileViewController.PROJECT_MANAGER))}async function verifySrcJumpToDef(location,targetFileName,jumpShouldFail){await openFile("jumpToDef.html");const selected=ProjectManager.getSelectedItem();let editor;expect(selected.fullPath).toBe(testPath+"/jumpToDef.html"),EditorManager.getActiveEditor().setCursorPos(location),jumpShouldFail?await awaitsForFail(CommandManager.execute(Commands.NAVIGATE_JUMPTO_DEFINITION),"jump to def on div"):await awaitsForDone(CommandManager.execute(Commands.NAVIGATE_JUMPTO_DEFINITION),"jump to def on div");let currentFile=MainViewManager.getCurrentlyViewedFile();expect(currentFile.fullPath.endsWith(targetFileName)).toBeTrue(),await closeSession()}async function _deleteFile(relativeFileName){let deleted=!1;FileSystem.getFileForPath(`${testPath}/${relativeFileName}`).unlink(()=>{deleted=!0}),await awaitsFor(function(){return deleted},"extension interface registration notification")}async function createAndVerifyFileContents(fileName,firstLineOfContent){await awaitsForDone(CommandManager.execute(Commands.FILE_NEW),"new file"),await awaitsFor(function(){return!!$(".jstree-rename-input")[0]},"input to come");let fileNameInput=$(".jstree-rename-input");expect(fileNameInput[0]).toBeDefined(),await _deleteFile(fileName),fileNameInput.val(fileName),SpecRunnerUtils.simulateKeyEvent(KeyEvent.DOM_VK_RETURN,"keydown",fileNameInput[0]),await awaitsFor(function(){return!$(".jstree-rename-input")[0]},"input to go away"),await awaitsFor(function(){return!!EditorManager.getActiveEditor()},"wait for editor to be active"),expect(EditorManager.getActiveEditor().document.getText().split("\n")[0]).toBe(firstLineOfContent),await closeSession(),await _deleteFile(fileName)}async function _validateCodeHints(cursor,expectedSomeHintsArray,selectItemNumber){let editor;EditorManager.getActiveEditor().setCursorPos(cursor),await awaitsForDone(CommandManager.execute(Commands.SHOW_CODE_HINTS),"show code hints"),await awaitsFor(async function(){for(let hint of expectedSomeHintsArray){const allSelectors=await CSSUtils.getAllCssSelectorsInProject();if(!allSelectors.includes("."+hint))return!1}return!0},"CSSUtils project selectors to be updated"),await awaitsFor(function(){return $(".codehint-menu").is(":visible")},"codehints to be shown"),await awaitsFor(function(){for(let hint of expectedSomeHintsArray)if(!$(".codehint-menu").text().includes(hint))return!1;return!0},"expected hints to be there"),selectItemNumber>=0?$(".code-hints-list-item")[selectItemNumber].click():(SpecRunnerUtils.simulateKeyEvent(KeyEvent.DOM_VK_ESCAPE,"keydown",testWindow.document.body),await awaitsFor(function(){return!$(".codehint-menu").is(":visible")},"codehints to be hidden"))}function setText(cursor,text){let editor;EditorManager.getActiveEditor().replaceRange(text,cursor)}async function _validateCssEdit(cssFileName){await openFile("htmlOther/inlineStyle.html",!0),await openFile(cssFileName,!0);const cssClassName=StringUtils.randomString(5,"cls");setText({line:0,ch:0},`.${cssClassName}{}\n`),await openFile("htmlOther/inlineStyle.html",!0),await _validateCodeHints({line:12,ch:16},[cssClassName]),await closeSession()}async function _testCssClassHintInFile(htmlLikeFile){await openFile(htmlLikeFile,!0),await openFile("cssLive.css",!0);const cssClassName=StringUtils.randomString(5,"aaaaaaaaaaa");setText({line:0,ch:0},`.${cssClassName}{}\n`),await openFile(htmlLikeFile,!0),setText({line:12,ch:31}," "),await _validateCodeHints({line:12,ch:32},[cssClassName],0),expect(EditorManager.getActiveEditor().getToken().string).toBe(`"integratedStyle ${cssClassName}"`),await closeSession()}beforeAll(async function(){testWindow=await SpecRunnerUtils.createTestWindowAndRun(),brackets=testWindow.brackets,$=testWindow.$,FileViewController=brackets.test.FileViewController,ProjectManager=brackets.test.ProjectManager,CommandManager=brackets.test.CommandManager,Commands=brackets.test.Commands,EditorManager=brackets.test.EditorManager,MainViewManager=brackets.test.MainViewManager,FileSystem=brackets.test.FileSystem,CSSUtils=brackets.test.CSSUtils,await SpecRunnerUtils.loadProjectInTestWindow(testPath)},3e4),afterAll(async function(){FileViewController=null,ProjectManager=null,testWindow=null,CSSUtils=null,brackets=null,await SpecRunnerUtils.closeTestWindow()},3e4),it("Should jump to definition on div tag",async function(){await openFile("jumpToDef.html");const selected=ProjectManager.getSelectedItem();expect(selected.fullPath).toBe(testPath+"/jumpToDef.html");let editor=EditorManager.getActiveEditor();editor.setCursorPos({line:5,ch:6}),await awaitsForDone(CommandManager.execute(Commands.NAVIGATE_JUMPTO_DEFINITION),"jump to def on div"),editor=EditorManager.getFocusedInlineEditor(),expect(editor.document.file.fullPath.endsWith("LiveDevelopment-MultiBrowser-test-files/simpleShared.css")).toBeTrue(),await closeSession()}),it("Should jump to definition on css class",async function(){await openFile("jumpToDef.html");const selected=ProjectManager.getSelectedItem();expect(selected.fullPath).toBe(testPath+"/jumpToDef.html");let editor=EditorManager.getActiveEditor();editor.setCursorPos({line:6,ch:23}),await awaitsForDone(CommandManager.execute(Commands.NAVIGATE_JUMPTO_DEFINITION),"jump to def on div"),editor=EditorManager.getFocusedInlineEditor(),expect(editor.document.file.fullPath.endsWith("LiveDevelopment-MultiBrowser-test-files/sub/test.css")).toBeTrue(),await closeSession()}),it("Should jump to files on href/src attributes",async function(){await verifySrcJumpToDef({line:3,ch:44},"sub/test.css"),await verifySrcJumpToDef({line:13,ch:29},"blank.css"),await verifySrcJumpToDef({line:11,ch:32},"sub/icon_chevron.png"),await closeSession()}),it("Should not jump to files on non href/src attributes",async function(){await verifySrcJumpToDef({line:14,ch:47},"jumpToDef.html",!0),await verifySrcJumpToDef({line:7,ch:20},"jumpToDef.html",!0),await verifySrcJumpToDef({line:3,ch:22},"jumpToDef.html",!0),await closeSession()}),it("Should creating new html and xhtml file with template contents",async function(){await createAndVerifyFileContents("test1.html","<!DOCTYPE html>"),await createAndVerifyFileContents("test1.xhtml",'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">')}),it("Should not put template contents for non html files creation",async function(){await createAndVerifyFileContents("test1.txt","")}),it("Should show css class hints in html file",async function(){await openFile("jumpToDef.html",!0),await _validateCodeHints({line:9,ch:21},["testClass"]),await closeSession()}),it("should show inline styles in html document",async function(){await openFile("htmlOther/inlineStyle.html",!0),await _validateCodeHints({line:12,ch:19},["integratedStyle"]),await closeSession()}),it("should inline css class hint in unsaved html inline styles",async function(){await openFile("htmlOther/inlineStyle.html",!0),setText({line:8,ch:11},".newInlineStyleYo{}"),await _validateCodeHints({line:12,ch:19},["newInlineStyleYo"]),await closeSession()}),it("should CSS file edits show up in class list without saving",async function(){await _validateCssEdit("cssLive.css")}),it("should LESS file edits show up in class list without saving",async function(){await _validateCssEdit("cssLive1.less")}),it("should SCSS file edits show up in class list without saving",async function(){await _validateCssEdit("cssLive1.scss")}),it("should get external https css style sheet",async function(){await openFile("htmlOther/externalStyle.html",!0),await awaitsFor(async function(){const allSelectors=await CSSUtils.getAllCssSelectorsInProject();return allSelectors.includes(".devicon-aarch64-original-wordmark")||allSelectors.includes(".night")},"external style sheet hints to be loaded")});const extensions=["html","htm","xhtml","php","asp","aspx","jsp","shtml"];for(let extn of extensions)it(`should be able to add the class name by selecting the code hint in ${extn} file`,async function(){await _testCssClassHintInFile(`htmlOther/inlineStyle.${extn}`)})})});