-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔨 Refactoring window management impl
- Loading branch information
1 parent
8cca9d6
commit c5c1bc9
Showing
3 changed files
with
53 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 7 additions & 26 deletions
33
composeApp/src/desktopTest/kotlin/com/clipevery/app/TestAppWindowManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,38 @@ | ||
package com.clipevery.app | ||
|
||
import com.clipevery.listen.ActiveGraphicsDevice | ||
import kotlinx.coroutines.runBlocking | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.TestInstance | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertNull | ||
|
||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
class TestAppWindowManager { | ||
|
||
companion object { | ||
|
||
var testAppWindowManager: AppWindowManager = | ||
DesktopAppWindowManager( | ||
lazy { throw NotImplementedError("not invoke") }, | ||
object : ActiveGraphicsDevice { | ||
override fun getGraphicsDevice() = null | ||
}, | ||
-1, | ||
) | ||
|
||
@BeforeEach | ||
fun setUp() { | ||
TestWindowManager.init() | ||
} | ||
} | ||
|
||
@Test | ||
fun testMockTestAppWindowManager() { | ||
val mockOS = MockOS() | ||
val testAppWindowManager = TestWindowManager(mockOS) | ||
assertNull(testAppWindowManager.getPrevAppName()) | ||
runBlocking { testAppWindowManager.toPaste() } | ||
assertEquals(1, TestWindowManager.pasterId) | ||
assertEquals(1, testAppWindowManager.pasterId) | ||
assertNull(testAppWindowManager.getCurrentActiveAppName()) | ||
testAppWindowManager.activeMainWindow() | ||
assertEquals("Clipevery", testAppWindowManager.getCurrentActiveAppName()) | ||
testAppWindowManager.unActiveMainWindow() | ||
assertNull(testAppWindowManager.getCurrentActiveAppName()) | ||
TestWindowManager.activeApp("Chrome") | ||
mockOS.currentApp = "Chrome" | ||
runBlocking { testAppWindowManager.activeSearchWindow() } | ||
assertEquals("Clipevery", testAppWindowManager.getCurrentActiveAppName()) | ||
assertEquals("Chrome", testAppWindowManager.getPrevAppName()) | ||
runBlocking { testAppWindowManager.unActiveSearchWindow(preparePaste = { true }) } | ||
assertEquals(2, TestWindowManager.pasterId) | ||
assertEquals(2, testAppWindowManager.pasterId) | ||
assertEquals("Chrome", testAppWindowManager.getCurrentActiveAppName()) | ||
testAppWindowManager.activeMainWindow() | ||
runBlocking { testAppWindowManager.activeSearchWindow() } | ||
assertEquals("Clipevery", testAppWindowManager.getCurrentActiveAppName()) | ||
assertEquals("Chrome", testAppWindowManager.getPrevAppName()) | ||
runBlocking { testAppWindowManager.unActiveSearchWindow(preparePaste = { false }) } | ||
assertEquals(2, TestWindowManager.pasterId) | ||
assertEquals(2, testAppWindowManager.pasterId) | ||
runBlocking { testAppWindowManager.toPaste() } | ||
assertEquals(3, TestWindowManager.pasterId) | ||
assertEquals(3, testAppWindowManager.pasterId) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters