/**
 * Test the Markdown-preview plugin
 */ import { Assertor } from "./Assert" ; import { awaitEditorMode , getElementByClassName , getTemporaryFilePath , insertText , navigateToFile , } from "./Common" ; import * as Oni from "oni-api" ; interface IMarkdownPreviewPlugin { isPaneOpen ( ) : boolean ; getUnrenderedContent ( ) : string ; getRenderedContent ( ) : string ; toggle ( ) : void ; } export const settings = { config : { "experimental.markdownPreview.enabled" : true , } , } ; export async function test ( oni ) { const assert = new Assertor ( "Markdown-preview" ) ; await oni . automation . waitForEditors ( ) ; await oni . automation . waitFor ( ( ) => oni . plugins . loaded ) ; const markdownPlugin = oni . plugins . getPlugin ( "oni-plugin-markdown-preview" ) as IMarkdownPreviewPlugin ; assert . defined ( markdownPlugin , "plugin instance" ) ; assert . assert ( ! markdownPlugin . isPaneOpen ( ) , "Preview pane is initially closed." ) ; const markdownFilePath = getTemporaryFilePath ( "md" ) ; await navigateToFile ( markdownFilePath , oni ) ; await oni . automation . waitFor ( ( ) => markdownPlugin . isPaneOpen ( ) ) ; assert . isEmpty ( markdownPlugin . getUnrenderedContent ( ) . trim ( ) , "Preview pane shown for Markdown buffer." ) ; await insertText ( oni , "# Title 1" ) ; assert . contains ( markdownPlugin . getRenderedContent ( ) , ">Title 1</h1>" , "Preview pane with renders header element." ) ; oni . automation . sendKeys ( "o" ) ; await oni . automation . waitFor ( ( ) => oni . editors . activeEditor . mode === "insert" ) ; oni . automation . sendKeys ( "```<enter>" ) ; oni . automation . sendKeys ( "const test = 'Oni'<enter>" ) ; oni . automation . sendKeys ( "```" ) ; oni . automation . sendKeys ( "<esc>" ) ; await oni . automation . waitFor ( ( ) => oni . editors . activeEditor . mode === "normal" ) ; assert . contains ( markdownPlugin . getRenderedContent ( ) , "code>" , "Code block present in preview HTML." ) ; assert . assert ( getElementByClassName ( "hljs-keyword" ) . innerText === "const" , "Syntax highlights present in preview HTML." ) ; const nonMDFilePath = getTemporaryFilePath ( "ts" ) ; await navigateToFile ( nonMDFilePath , oni ) ; await oni . automation . waitFor ( ( ) => oni . editors . activeEditor . activeBuffer . language === "typescript" ) ; assert . assert ( ! markdownPlugin . isPaneOpen ( ) , "Preview pane is closed for non-MD file." ) ; await navigateToFile ( markdownFilePath , oni ) ; await oni . automation . waitFor ( ( ) => oni . editors . activeEditor . activeBuffer . language === "markdown" ) ; assert . assert ( markdownPlugin . isPaneOpen ( ) , "Preview pane opens for MD file." ) ; markdownPlugin . toggle ( ) ; assert . assert ( ! markdownPlugin . isPaneOpen ( ) , "Preview pane closes on toggle." ) ; await navigateToFile ( nonMDFilePath , oni ) ; await oni . automation . waitFor ( ( ) => oni . editors . activeEditor . activeBuffer . language === "typescript" ) ; await navigateToFile ( markdownFilePath , oni ) ; await oni . automation . waitFor ( ( ) => oni . editors . activeEditor . activeBuffer . language === "markdown" ) ; assert . assert ( ! markdownPlugin . isPaneOpen ( ) , "Preview pane remains closed for MD file when manually closed." ) ; }