@@ -33,6 +33,7 @@ import com.intellij.testFramework.TestApplicationManager
3333import com.intellij.testFramework.fixtures.CodeInsightTestFixture
3434import com.mituuz.fuzzier.actions.FuzzyAction
3535import com.mituuz.fuzzier.components.SimpleFinderComponent
36+ import com.mituuz.fuzzier.entities.FuzzyContainer
3637import com.mituuz.fuzzier.entities.FuzzyContainer.FilenameType.*
3738import com.mituuz.fuzzier.entities.FuzzyMatchContainer
3839import com.mituuz.fuzzier.entities.FuzzyMatchContainer.FileType.FILE
@@ -41,10 +42,7 @@ import org.junit.jupiter.api.Assertions.*
4142import org.junit.jupiter.api.Test
4243import java.awt.event.InputEvent
4344import java.awt.event.KeyEvent
44- import javax.swing.JComponent
45- import javax.swing.JLabel
46- import javax.swing.JList
47- import javax.swing.KeyStroke
45+ import javax.swing.*
4846
4947class FuzzyActionTest {
5048 @Suppress(" unused" )
@@ -185,6 +183,48 @@ class FuzzyActionTest {
185183 assertEquals(expectedIcon, component.icon)
186184 }
187185
186+ @Test
187+ fun `Test moveListUp rollover` () {
188+ val action = getAction()
189+ action.component = SimpleFinderComponent ()
190+ val model = DefaultListModel <FuzzyContainer >()
191+ model.addElement(FuzzyMatchContainer (FuzzyScore (), " /src/asd1" , " asd1" , " " , FILE ))
192+ model.addElement(FuzzyMatchContainer (FuzzyScore (), " /src/asd2" , " asd2" , " " , FILE ))
193+ model.addElement(FuzzyMatchContainer (FuzzyScore (), " /src/asd3" , " asd3" , " " , FILE ))
194+ action.component.fileList.model = model
195+ action.component.fileList.selectedIndex = 0
196+
197+ action.moveListUp()
198+ assertEquals(2 , action.component.fileList.selectedIndex)
199+
200+ action.moveListUp()
201+ assertEquals(1 , action.component.fileList.selectedIndex)
202+
203+ action.moveListUp()
204+ assertEquals(0 , action.component.fileList.selectedIndex)
205+ }
206+
207+ @Test
208+ fun `Test moveListDown rollover` () {
209+ val action = getAction()
210+ action.component = SimpleFinderComponent ()
211+ val model = DefaultListModel <FuzzyContainer >()
212+ model.addElement(FuzzyMatchContainer (FuzzyScore (), " /src/asd1" , " asd1" , " " , FILE ))
213+ model.addElement(FuzzyMatchContainer (FuzzyScore (), " /src/asd2" , " asd2" , " " , FILE ))
214+ model.addElement(FuzzyMatchContainer (FuzzyScore (), " /src/asd3" , " asd3" , " " , FILE ))
215+ action.component.fileList.model = model
216+ action.component.fileList.selectedIndex = 2
217+
218+ action.moveListDown()
219+ assertEquals(0 , action.component.fileList.selectedIndex)
220+
221+ action.moveListDown()
222+ assertEquals(1 , action.component.fileList.selectedIndex)
223+
224+ action.moveListDown()
225+ assertEquals(2 , action.component.fileList.selectedIndex)
226+ }
227+
188228 private fun getAction (): FuzzyAction {
189229 return object : FuzzyAction () {
190230 override fun actionPerformed (actionEvent : AnActionEvent ) {
0 commit comments