Skip to content

Commit

Permalink
WIP: work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
mikavilpas committed Jul 7, 2024
1 parent 87518e8 commit 12c7a06
Show file tree
Hide file tree
Showing 22 changed files with 575 additions and 217 deletions.
22 changes: 17 additions & 5 deletions integration-tests/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import { FitAddon } from "@xterm/addon-fit"
import { Terminal } from "@xterm/xterm"
import io from "socket.io-client"
import type {
StartAppMessage,
StartNeovimMessage,
StdinMessage,
StdoutMessage,
} from "../server/server"
import "./startAppGlobalType"
import type { StartAppMessageArguments } from "./startAppGlobalType"
import type {
StartNeovimArguments,
StartNeovimServerArguments,
} from "./testEnvironmentTypes"

const app = document.querySelector<HTMLDivElement>("#app")
if (!app) {
Expand Down Expand Up @@ -73,8 +75,18 @@ socket.on("disconnect", (reason) => {
console.log("disconnected: ", reason)
})

window.startApp = async function startApp(args: StartAppMessageArguments) {
await socket.emitWithAck("startApp" satisfies StartAppMessage, args)
window.startNeovim = async function startApp(
directory: string,
startArgs?: StartNeovimArguments,
) {
await socket.emitWithAck(
"startNeovim" satisfies StartNeovimMessage,
{
directory,
filename: startArgs?.filename ?? "initial-file.txt",
startupScriptModifications: startArgs?.startupScriptModifications,
} satisfies StartNeovimServerArguments,
)
}

socket.on(
Expand Down
12 changes: 0 additions & 12 deletions integration-tests/client/startAppGlobalType.ts

This file was deleted.

65 changes: 65 additions & 0 deletions integration-tests/client/testEnvironmentTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/** The arguments given from the tests to send to the server */
export type StartNeovimArguments = {
filename?: TestDirectoryFile | "."
startupScriptModifications?: StartupScriptModification[]
}

/** The arguments given to the server */
export type StartNeovimServerArguments = {
directory: string
} & StartNeovimArguments

export type StartupScriptModification =
"modify_yazi_config_to_use_ya_as_event_reader.lua"

declare global {
interface Window {
startNeovim(
directory: string,
startArguments?: StartNeovimArguments,
): Promise<void>
}
}

export type FileEntry = {
/** The name of the file and its extension.
* @example "file.txt"
*/
name: string

/** The name of the file without its extension.
* @example "file"
*/
stem: string

/** The extension of the file.
* @example ".txt"
*/
extension: string
}

/** Describes the contents test directory, which is a blueprint for files and
* directories. Tests can create a unique, safe environment for interacting
* with the contents of such a directory.
*
* Having strong typing for the test directory contents ensures that tests can
* be written with confidence that the files and directories they expect are
* actually found. Otherwise the tests are brittle and can break easily.
*/
export type TestDirectory = {
/** The path to the unique test directory itself (the root). */
rootPath: string

contents: {
["initial-file.txt"]: FileEntry
["test.lua"]: FileEntry
["file.txt"]: FileEntry
["subdirectory/sub.txt"]: FileEntry
["routes/posts.$postId/route.tsx"]: FileEntry
["routes/posts.$postId/adjacent-file.tsx"]: FileEntry
}
}

type TestDirectoryFile = keyof TestDirectory["contents"]

export {}
1 change: 1 addition & 0 deletions integration-tests/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export default defineConfig({
execSync(`cp ./test-environment/file.txt ${dir}/`)
execSync(`cp ./test-environment/test-setup.lua ${dir}/test.lua`)
execSync(`cp -r ./test-environment/subdirectory ${dir}/`)
execSync(`cp -r ./test-environment/config-modifications/ ${dir}/`)
execSync(`cp -r ./test-environment/routes ${dir}/`)
console.log(`Created test directory at ${dir}`)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
describe("opening files", () => {
beforeEach(() => {
cy.visit("http://localhost:5173")
})

it("can display yazi in a floating terminal", () => {
cy.startNeovim().then((dir) => {
// wait until text on the start screen is visible
cy.contains("If you see this text, Neovim is ready!")
cy.typeIntoTerminal("{upArrow}")

// yazi should now be visible, showing the names of adjacent files
cy.contains(dir.contents["test.lua"].name) // an adjacent file
})
})

it("can open a file that was selected in yazi", () => {
cy.startNeovim().then((dir) => {
cy.typeIntoTerminal("{upArrow}")
cy.contains(dir.contents["file.txt"].name)

// search for the file in yazi. This focuses the file in yazi
cy.typeIntoTerminal("gg/file.txt{enter}")
cy.typeIntoTerminal("{enter}")

// the file content should now be visible
cy.contains("Hello 👋")
})
})

it("can open a file in a vertical split", () => {
cy.startNeovim().then((dir) => {
cy.typeIntoTerminal("{upArrow}")
cy.typeIntoTerminal("j{control+v}")

// the file path must be visible at the bottom
cy.contains(dir.contents["test.lua"].name)
cy.contains(dir.contents["initial-file.txt"].name)
})
})

it("can open a file in a horizontal split", () => {
cy.startNeovim().then((dir) => {
cy.typeIntoTerminal("{upArrow}")
cy.typeIntoTerminal("j{control+x}")

// the file path must be visible at the bottom
cy.contains(dir.contents["test.lua"].name)
cy.contains(dir.contents["initial-file.txt"].name)
})
})

it("can send file names to the quickfix list", () => {
cy.startNeovim().then((dir) => {
cy.typeIntoTerminal("{upArrow}")
cy.typeIntoTerminal("{control+a}{enter}")

// items in the quickfix list should now be visible
cy.contains(`${dir.contents["file.txt"].name}||`)
cy.contains(`${dir.contents["initial-file.txt"].name}||`)
})
})

it("can open files with complex characters in their name", () => {
cy.startNeovim().then((dir) => {
cy.typeIntoTerminal("{upArrow}")

// enter the routes/ directory
cy.typeIntoTerminal("/routes{enter}")
cy.typeIntoTerminal("{rightArrow}")
cy.contains(dir.contents["routes/posts.$postId/route.tsx"].name) // file in the directory

// enter routes/posts.$postId/
cy.typeIntoTerminal("{rightArrow}")

// select route.tsx
cy.typeIntoTerminal(
`/${dir.contents["routes/posts.$postId/route.tsx"].name}{enter}`,
)

// open the file
cy.typeIntoTerminal("{enter}")

// close yazi just to be sure the file preview is not found instead
cy.get(
dir.contents["routes/posts.$postId/adjacent-file.tsx"].name,
).should("not.exist")

// the file contents should now be visible
cy.contains("02c67730-6b74-4b7c-af61-fe5844fdc3d7")
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ it("can read 'trash' events and close an open buffer when its file was trashed",

// internally, we should have received a trash event from yazi, and yazi.nvim should
// have closed the buffer
cy.get(dir.contents["initial-file.txt"].name).should("not.exist")
cy.contains(dir.contents["initial-file.txt"].name).should("not.exist")
cy.contains("If you see this text, Neovim is ready").should("not.exist")
})
})

Expand Down Expand Up @@ -78,6 +79,7 @@ it("can read 'delete' events and close an open buffer when its file was deleted"
// internally, we should have received a delete event from yazi, and yazi.nvim should
// have closed the buffer
cy.get(dir.contents["initial-file.txt"].name).should("not.exist")
cy.contains("If you see this text, Neovim is ready").should("not.exist")
})
})

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { startNeovimWithYa } from "./startNeovimWithYa"

describe("opening directories", () => {
it("can open a directory when starting with `neovim .`", () => {
cy.visit("http://localhost:5173")
startNeovimWithYa({
// `neovim .` specifies to open the current directory when neovim is
// starting
filename: ".",
}).then((dir) => {
// yazi should now be visible, showing the names of adjacent files
cy.contains(dir.contents["file.txt"].name)
cy.contains(dir.contents["initial-file.txt"].name)
})
})
})
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { startNeovimWithYa } from "./startNeovimWithYa"

describe("opening files", () => {
beforeEach(() => {
cy.visit("http://localhost:5173")
})

it("can display yazi in a floating terminal", () => {
cy.startNeovim().then((dir) => {
startNeovimWithYa().then((dir) => {
// wait until text on the start screen is visible
cy.contains("If you see this text, Neovim is ready!")
cy.typeIntoTerminal("{upArrow}")
Expand All @@ -15,7 +17,7 @@ describe("opening files", () => {
})

it("can open a file that was selected in yazi", () => {
cy.startNeovim().then((dir) => {
startNeovimWithYa().then((dir) => {
cy.typeIntoTerminal("{upArrow}")
cy.contains(dir.contents["file.txt"].name)

Expand All @@ -29,9 +31,10 @@ describe("opening files", () => {
})

it("can open a file in a vertical split", () => {
cy.startNeovim().then((dir) => {
startNeovimWithYa().then((dir) => {
cy.typeIntoTerminal("{upArrow}")
cy.typeIntoTerminal("j{control+v}")
cy.typeIntoTerminal("/test.lua{enter}")
cy.typeIntoTerminal("{control+v}")

// the file path must be visible at the bottom
cy.contains(dir.contents["test.lua"].name)
Expand All @@ -40,9 +43,10 @@ describe("opening files", () => {
})

it("can open a file in a horizontal split", () => {
cy.startNeovim().then((dir) => {
startNeovimWithYa().then((dir) => {
cy.typeIntoTerminal("{upArrow}")
cy.typeIntoTerminal("j{control+x}")
cy.typeIntoTerminal("/test.lua{enter}")
cy.typeIntoTerminal("{control+x}")

// the file path must be visible at the bottom
cy.contains(dir.contents["test.lua"].name)
Expand All @@ -51,7 +55,7 @@ describe("opening files", () => {
})

it("can send file names to the quickfix list", () => {
cy.startNeovim().then((dir) => {
startNeovimWithYa().then((dir) => {
cy.typeIntoTerminal("{upArrow}")
cy.typeIntoTerminal("{control+a}{enter}")

Expand All @@ -62,7 +66,7 @@ describe("opening files", () => {
})

it("can bulk rename files", () => {
cy.startNeovim().then((_dir) => {
startNeovimWithYa().then((_dir) => {
// in yazi, bulk renaming is done by
// - selecting files and pressing "r".
// - It opens the editor with the names of the selected files.
Expand All @@ -89,7 +93,7 @@ describe("opening files", () => {
})

it("can open files with complex characters in their name", () => {
cy.startNeovim().then((dir) => {
startNeovimWithYa().then((dir) => {
cy.typeIntoTerminal("{upArrow}")

// enter the routes/ directory
Expand Down
Loading

0 comments on commit 12c7a06

Please sign in to comment.