Skip to content

Commit

Permalink
fix: not being able to open directories with enter (#272)
Browse files Browse the repository at this point in the history
* refactor(tests): fix old test file name

* test: can open a directory with `:edit .`

* fixup! test: can open a directory with `:edit .`

* fix: not being able to open directories with enter

This broke when I added the fix from yesterday,
c9ebbf6
  • Loading branch information
mikavilpas authored Jul 27, 2024
1 parent 28e9ac0 commit d70bb91
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 46 deletions.
2 changes: 1 addition & 1 deletion integration-tests/client/testEnvironmentTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export type TestDirectory = {

contents: {
["initial-file.txt"]: FileEntry
["test.lua"]: FileEntry
["test-setup.lua"]: FileEntry
["file.txt"]: FileEntry
["modify_yazi_config_to_use_ya_as_event_reader.lua"]: FileEntry
["subdirectory/subdirectory-file.txt"]: FileEntry
Expand Down
10 changes: 6 additions & 4 deletions integration-tests/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ export default defineConfig({
stem: "initial-file",
extension: ".txt",
},
"test.lua": {
name: "test.lua",
stem: "test",
"test-setup.lua": {
name: "test-setup.lua",
stem: "test-setup",
extension: ".lua",
},
"file.txt": {
Expand Down Expand Up @@ -119,7 +119,9 @@ export default defineConfig({

execSync(`cp ./test-environment/initial-file.txt ${dir}/`)
execSync(`cp ./test-environment/file.txt ${dir}/`)
execSync(`cp ./test-environment/test-setup.lua ${dir}/test.lua`)
execSync(
`cp ./test-environment/test-setup.lua ${dir}/test-setup.lua`,
)
execSync(`cp -r ./test-environment/subdirectory ${dir}/`)
execSync(`cp -r ./test-environment/other-subdirectory ${dir}/`)
execSync(`cp -r ./test-environment/config-modifications/ ${dir}/`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,43 @@ describe("opening directories", () => {
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["test-setup.lua"].name)
})
})

it("can open a directory with `:edit .`", () => {
cy.visit("http://localhost:5173")
cy.startNeovim().then((dir) => {
// yazi should now be visible, showing the names of adjacent files
cy.contains(dir.contents["initial-file.txt"].name)

// open the current directory using a command
cy.typeIntoTerminal(":edit .{enter}")

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

it("can open a directory when pressing enter on a directory in yazi", () => {
cy.visit("http://localhost:5173")
cy.startNeovim().then((dir) => {
// yazi should now be visible, showing the names of adjacent files
cy.contains(dir.contents["initial-file.txt"].name)

cy.typeIntoTerminal("{upArrow}")
cy.contains(dir.contents["test-setup.lua"].name)

// select a directory
cy.typeIntoTerminal("/routes{enter}")
// the contents of the directory should now be visible
cy.contains("posts.$postId")

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

// yazi should now be visible in the new directory
cy.contains(dir.contents["routes/posts.$postId/route.tsx"].name)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe("opening files", () => {
cy.typeIntoTerminal("{upArrow}")

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

Expand All @@ -31,40 +31,40 @@ describe("opening files", () => {
it("can open a file in a vertical split", () => {
cy.startNeovim().then((dir) => {
cy.typeIntoTerminal("{upArrow}")
cy.contains(dir.contents["test.lua"].name)
cy.typeIntoTerminal("/test.lua{enter}")
cy.contains(dir.contents["test-setup.lua"].name)
cy.typeIntoTerminal("/test-setup.lua{enter}")
cy.typeIntoTerminal("{control+v}")

// yazi should now be closed
cy.contains("-- TERMINAL --").should("not.exist")

// the file path must be visible at the bottom
cy.contains(dir.contents["test.lua"].name)
cy.contains(dir.contents["test-setup.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.contains(dir.contents["test.lua"].name)
cy.typeIntoTerminal("/test.lua{enter}")
cy.contains(dir.contents["test-setup.lua"].name)
cy.typeIntoTerminal("/test-setup.lua{enter}")
cy.typeIntoTerminal("{control+x}")

// yazi should now be closed
cy.contains("-- TERMINAL --").should("not.exist")

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

it("can open a file in a new tab", () => {
cy.startNeovim().then((dir) => {
cy.typeIntoTerminal("{upArrow}")
cy.contains(dir.contents["test.lua"].name)
cy.typeIntoTerminal("/test.lua{enter}")
cy.contains(dir.contents["test-setup.lua"].name)
cy.typeIntoTerminal("/test-setup.lua{enter}")
cy.typeIntoTerminal("{control+t}")

// yazi should now be closed
Expand All @@ -75,7 +75,7 @@ describe("opening files", () => {

cy.contains("If you see this text, Neovim is ready!")

cy.contains(dir.contents["test.lua"].name)
cy.contains(dir.contents["test-setup.lua"].name)
cy.contains(dir.contents["initial-file.txt"].name)
})
})
Expand All @@ -85,7 +85,7 @@ describe("opening files", () => {
cy.typeIntoTerminal("{upArrow}")

// wait for yazi to open
cy.contains(dir.contents["test.lua"].name)
cy.contains(dir.contents["test-setup.lua"].name)

// select the initial file, the cursor moves one line down to the next file
cy.typeIntoTerminal(" ")
Expand All @@ -104,7 +104,7 @@ describe("opening files", () => {
it("can open files with complex characters in their name", () => {
cy.startNeovim().then((dir) => {
cy.typeIntoTerminal("{upArrow}")
cy.contains(dir.contents["test.lua"].name)
cy.contains(dir.contents["test-setup.lua"].name)

// enter the routes/ directory
cy.typeIntoTerminal("/routes{enter}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe("highlighting the buffer with 'hover' events", () => {
cy.typeIntoTerminal("{upArrow}")

// yazi is shown and adjacent files should be visible now
cy.contains(dir.contents["test.lua"].name)
cy.contains(dir.contents["test-setup.lua"].name)

hoverAnotherFileToEnsureHoverEventIsReceivedInCI(
dir.contents["initial-file.txt"].name,
Expand All @@ -85,7 +85,7 @@ describe("highlighting the buffer with 'hover' events", () => {
isHovered("If you see this text, Neovim is ready!")

// hover another file - the highlight should be removed
cy.typeIntoTerminal(`/^${dir.contents["test.lua"].name}{enter}`)
cy.typeIntoTerminal(`/^${dir.contents["test-setup.lua"].name}{enter}`)

isNotHovered("If you see this text, Neovim is ready!")
})
Expand All @@ -100,7 +100,7 @@ describe("highlighting the buffer with 'hover' events", () => {
// wait until text on the start screen is visible
isNotHovered("f you see this text, Neovim is ready!")

const testFile = dir.contents["test.lua"].name
const testFile = dir.contents["test-setup.lua"].name
// open an adjacent file and wait for it to be displayed
cy.typeIntoTerminal(
`:vsplit ${dir.rootPathAbsolute}/${testFile}{enter}`,
Expand Down Expand Up @@ -139,7 +139,7 @@ describe("highlighting the buffer with 'hover' events", () => {
cy.typeIntoTerminal("{upArrow}")

hoverAnotherFileToEnsureHoverEventIsReceivedInCI(
dir.contents["test.lua"].name,
dir.contents["test-setup.lua"].name,
)

// yazi is shown and adjacent files should be visible now
Expand Down Expand Up @@ -172,7 +172,7 @@ describe("highlighting the buffer with 'hover' events", () => {
cy.typeIntoTerminal("{upArrow}")

hoverAnotherFileToEnsureHoverEventIsReceivedInCI(
dir.contents["test.lua"].name,
dir.contents["test-setup.lua"].name,
)

// yazi is shown and adjacent files should be visible now
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ describe("mouse support", () => {
cy.typeIntoTerminal("{upArrow}")

// yazi should be showing adjacent files
cy.contains(dir.contents["test.lua"].name)
cy.contains(dir.contents["test-setup.lua"].name)

// click outside of the yazi floating window. This should close it
// because it's designed to close when it loses focus
cy.contains("-- TERMINAL --").click()
cy.contains("If you see this text, Neovim is ready!").click()

// clicking outside of the yazi window should close it, after which
// Neovim should not be showing the TERMINAL buffer any longer
cy.contains("-- TERMINAL --").should("not.exist")
// Neovim should not be showing adjacent files
cy.contains(dir.contents["test-setup.lua"].name).should("not.exist")
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,45 @@ describe("opening directories", () => {
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["test-setup.lua"].name)

cy.typeIntoTerminal("{downArrow}")
})
})

it("can open a directory with `:edit .`", () => {
cy.visit("http://localhost:5173")
startNeovimWithYa().then((dir) => {
// yazi should now be visible, showing the names of adjacent files
cy.contains(dir.contents["initial-file.txt"].name)

// open the current directory using a command
cy.typeIntoTerminal(":edit .{enter}")

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

it("can open a directory when pressing enter on a directory in yazi", () => {
cy.visit("http://localhost:5173")
startNeovimWithYa().then((dir) => {
// yazi should now be visible, showing the names of adjacent files
cy.contains(dir.contents["initial-file.txt"].name)

cy.typeIntoTerminal("{upArrow}")
cy.contains(dir.contents["test-setup.lua"].name)

// select a directory
cy.typeIntoTerminal("/routes{enter}")
// the contents of the directory should now be visible
cy.contains("posts.$postId")

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

// yazi should now be visible in the new directory
cy.contains(dir.contents["routes/posts.$postId/route.tsx"].name)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe("opening files", () => {
cy.typeIntoTerminal("{upArrow}")

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

Expand All @@ -33,40 +33,40 @@ describe("opening files", () => {
it("can open a file in a vertical split", () => {
startNeovimWithYa().then((dir) => {
cy.typeIntoTerminal("{upArrow}")
cy.contains(dir.contents["test.lua"].name)
cy.typeIntoTerminal("/test.lua{enter}")
cy.contains(dir.contents["test-setup.lua"].name)
cy.typeIntoTerminal("/test-setup.lua{enter}")
cy.typeIntoTerminal("{control+v}")

// yazi should now be closed
cy.contains("-- TERMINAL --").should("not.exist")

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

it("can open a file in a horizontal split", () => {
startNeovimWithYa().then((dir) => {
cy.typeIntoTerminal("{upArrow}")
cy.contains(dir.contents["test.lua"].name)
cy.typeIntoTerminal("/test.lua{enter}")
cy.contains(dir.contents["test-setup.lua"].name)
cy.typeIntoTerminal("/test-setup.lua{enter}")
cy.typeIntoTerminal("{control+x}")

// yazi should now be closed
cy.contains("-- TERMINAL --").should("not.exist")

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

it("can open a file in a new tab", () => {
startNeovimWithYa().then((dir) => {
cy.typeIntoTerminal("{upArrow}")
cy.contains(dir.contents["test.lua"].name)
cy.typeIntoTerminal("/test.lua{enter}")
cy.contains(dir.contents["test-setup.lua"].name)
cy.typeIntoTerminal("/test-setup.lua{enter}")
cy.typeIntoTerminal("{control+t}")

// yazi should now be closed
Expand All @@ -77,7 +77,7 @@ describe("opening files", () => {

cy.contains("If you see this text, Neovim is ready!")

cy.contains(dir.contents["test.lua"].name)
cy.contains(dir.contents["test-setup.lua"].name)
cy.contains(dir.contents["initial-file.txt"].name)
})
})
Expand All @@ -87,7 +87,7 @@ describe("opening files", () => {
cy.typeIntoTerminal("{upArrow}")

// wait for yazi to open
cy.contains(dir.contents["test.lua"].name)
cy.contains(dir.contents["test-setup.lua"].name)

// select the initial file, the cursor moves one line down to the next file
cy.typeIntoTerminal(" ")
Expand All @@ -113,7 +113,7 @@ describe("opening files", () => {
// file.
// - Finally, yazi should rename the files to match the new names.
cy.typeIntoTerminal("{upArrow}")
cy.contains(dir.contents["test.lua"].name)
cy.contains(dir.contents["test-setup.lua"].name)
cy.typeIntoTerminal("{control+a}r")

// yazi should now have opened an embedded Neovim. The file name should say
Expand All @@ -135,7 +135,7 @@ describe("opening files", () => {
it("can rename a buffer that's open in Neovim", () => {
startNeovimWithYa().then((dir) => {
cy.typeIntoTerminal("{upArrow}")
cy.contains(dir.contents["test.lua"].name)
cy.contains(dir.contents["test-setup.lua"].name)
// select only the current file to make the test easier
cy.typeIntoTerminal("v")
cy.typeIntoTerminal("r") // start renaming
Expand Down
Loading

0 comments on commit d70bb91

Please sign in to comment.