MCPcopy
hub / github.com/yorukot/superfile / TestFileRename

Function TestFileRename

src/internal/model_file_operations_test.go:119–192  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

117}
118
119func TestFileRename(t *testing.T) {
120 curTestDir := t.TempDir()
121 file1 := filepath.Join(curTestDir, "file1.txt")
122 file2 := filepath.Join(curTestDir, "file2.txt")
123 file3 := filepath.Join(curTestDir, "file3.txt")
124
125 utils.SetupFilesWithData(t, []byte("f1"), file1)
126 utils.SetupFilesWithData(t, []byte("f2"), file2)
127 utils.SetupFilesWithData(t, []byte("f3"), file3)
128
129 file1New := filepath.Join(curTestDir, "file1_new.txt")
130
131 t.Run("Basic rename", func(t *testing.T) {
132 m := defaultTestModel(curTestDir)
133 p := NewTestTeaProgWithEventLoop(t, m)
134 setFilePanelSelectedItemByLocation(t, m.getFocusedFilePanel(), file1)
135
136 p.SendKey(common.Hotkeys.FilePanelItemRename[0])
137 p.SendKey("_new")
138 p.Send(tea.KeyPressMsg{Code: tea.KeyEnter})
139
140 assert.Eventually(t, func() bool {
141 _, err1 := os.Stat(file1)
142 _, err1New := os.Stat(file1New)
143 return err1New == nil && os.IsNotExist(err1)
144 }, DefaultTestTimeout, DefaultTestTick, "File never got renamed")
145 })
146
147 t.Run("Rename confirmation for same name", func(t *testing.T) {
148 actualTest := func(doRename bool) {
149 m := defaultTestModel(curTestDir)
150 p := NewTestTeaProgWithEventLoop(t, m)
151 setFilePanelSelectedItemByLocation(t, m.getFocusedFilePanel(), file3)
152
153 p.SendKey(common.Hotkeys.FilePanelItemRename[0])
154 p.Send(tea.KeyPressMsg{Code: tea.KeyBackspace})
155 p.SendKey("2")
156 p.Send(tea.KeyPressMsg{Code: tea.KeyEnter})
157
158 require.Eventually(t, func() bool {
159 return m.notifyModel.IsOpen()
160 }, DefaultTestTimeout, DefaultTestTick,
161 "Notify modal never opened, renaming text : %v", m.getFocusedFilePanel().Rename.Value())
162
163 assert.Equal(t, notify.New(true,
164 common.SameRenameWarnTitle,
165 common.SameRenameWarnContent,
166 notify.RenameAction), m.notifyModel, "Notify model should be as expected")
167
168 if doRename {
169 p.Send(tea.KeyPressMsg{Code: tea.KeyEnter})
170 } else {
171 p.SendKey(common.Hotkeys.CancelTyping[0])
172 }
173
174 assert.Eventually(t, func() bool {
175 _, err2 := os.Stat(file2)
176 _, err3 := os.Stat(file3)

Callers

nothing calls this directly

Calls 9

SetupFilesWithDataFunction · 0.92
NewFunction · 0.92
getFocusedFilePanelMethod · 0.80
SendKeyMethod · 0.80
SendMethod · 0.80
defaultTestModelFunction · 0.70
IsOpenMethod · 0.45

Tested by

no test coverage detected