Skip to content

Commit

Permalink
Fix tests (except for exec-and-wait)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitabobko committed Nov 25, 2023
1 parent 5d8bf3f commit f992d74
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 37 deletions.
2 changes: 1 addition & 1 deletion test/command/FlattenWorkspaceTreeCommandTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ final class FlattenWorkspaceTreeCommandTest: XCTestCase {
func testSimple() {
let workspace = Workspace.get(byName: name).apply {
$0.rootTilingContainer.apply {
TestWindow(id: 1, parent: $0).nativeFocus()
TestWindow(id: 1, parent: $0).focus()
TilingContainer.newHTiles(parent: $0, adaptiveWeight: 1).apply {
TestWindow(id: 2, parent: $0)
}
Expand Down
24 changes: 10 additions & 14 deletions test/command/FocusCommandTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ final class FocusCommandTest: XCTestCase {
XCTAssertEqual(focusedWindow, nil)
Workspace.get(byName: name).rootTilingContainer.apply {
TestWindow(id: 1, parent: $0)
TestWindow(id: 2, parent: $0).nativeFocus()
TestWindow(id: 2, parent: $0).focus()
TestWindow(id: 3, parent: $0)
}
XCTAssertEqual(focusedWindow?.windowId, 2)
}

func testFocusAlongTheContainerOrientation() {
Workspace.get(byName: name).rootTilingContainer.apply {
TestWindow(id: 1, parent: $0).nativeFocus()
TestWindow(id: 1, parent: $0).focus()
TestWindow(id: 2, parent: $0)
}

Expand All @@ -46,7 +46,7 @@ final class FocusCommandTest: XCTestCase {

func testFocusAcrossTheContainerOrientation() {
Workspace.get(byName: name).rootTilingContainer.apply {
TestWindow(id: 1, parent: $0).nativeFocus()
TestWindow(id: 1, parent: $0).focus()
TestWindow(id: 2, parent: $0)
}

Expand All @@ -58,7 +58,7 @@ final class FocusCommandTest: XCTestCase {

func testFocusNoWrapping() {
Workspace.get(byName: name).rootTilingContainer.apply {
TestWindow(id: 1, parent: $0).nativeFocus()
TestWindow(id: 1, parent: $0).focus()
TestWindow(id: 2, parent: $0)
}

Expand All @@ -73,7 +73,7 @@ final class FocusCommandTest: XCTestCase {
var window3: Window!
var unrelatedWindow: Window!
workspace.rootTilingContainer.apply {
startWindow = TestWindow(id: 1, parent: $0).apply { $0.nativeFocus() }
startWindow = TestWindow(id: 1, parent: $0).apply { $0.focus() }
TilingContainer.newVTiles(parent: $0, adaptiveWeight: 1).apply {
TilingContainer.newHTiles(parent: $0, adaptiveWeight: 1).apply {
window2 = TestWindow(id: 2, parent: $0)
Expand All @@ -83,18 +83,14 @@ final class FocusCommandTest: XCTestCase {
}
}

XCTAssertEqual(workspace.mostRecentWindow?.windowId, 3) // The latest binded
FocusCommand(direction: .right).testRun()
XCTAssertEqual(focusedWindow?.windowId, 3)

startWindow.nativeFocus()
window2.markAsMostRecentChild()
startWindow.focus()
FocusCommand(direction: .right).testRun()
XCTAssertEqual(focusedWindow?.windowId, 2)

startWindow.nativeFocus()
window3.markAsMostRecentChild()
unrelatedWindow.markAsMostRecentChild()
startWindow.focus()
FocusCommand(direction: .right).testRun()
XCTAssertEqual(focusedWindow?.windowId, 2)
}
Expand All @@ -103,7 +99,7 @@ final class FocusCommandTest: XCTestCase {
Workspace.get(byName: name).rootTilingContainer.apply {
TestWindow(id: 1, parent: $0)
TilingContainer.newVTiles(parent: $0, adaptiveWeight: 1).apply {
TestWindow(id: 2, parent: $0).nativeFocus()
TestWindow(id: 2, parent: $0).focus()
}
}

Expand All @@ -115,7 +111,7 @@ final class FocusCommandTest: XCTestCase {
Workspace.get(byName: name).rootTilingContainer.apply {
TestWindow(id: 1, parent: $0)
TilingContainer.newHTiles(parent: $0, adaptiveWeight: 1).apply {
TestWindow(id: 2, parent: $0).nativeFocus()
TestWindow(id: 2, parent: $0).focus()
}
}

Expand All @@ -134,6 +130,6 @@ extension Command {
state = .emptyWorkspace(focusedWorkspaceName)
}
runWithoutLayout(subject: &state)
state.windowOrNil?.nativeFocus()
state.windowOrNil?.focus()
}
}
2 changes: 1 addition & 1 deletion test/command/JoinWithCommandTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ final class MoveInCommandTest: XCTestCase {
func testMoveIn() {
let root = Workspace.get(byName: name).rootTilingContainer.apply {
TestWindow(id: 0, parent: $0)
TestWindow(id: 1, parent: $0).nativeFocus()
TestWindow(id: 1, parent: $0).focus()
TestWindow(id: 2, parent: $0)
}

Expand Down
8 changes: 2 additions & 6 deletions test/command/MoveNodeToWorkspaceCommandTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,21 @@ final class MoveNodeToWorkspaceCommandTest: XCTestCase {
func testSimple() {
let workspaceA = Workspace.get(byName: "a")
workspaceA.rootTilingContainer.apply {
TestWindow(id: 1, parent: $0).nativeFocus()
TestWindow(id: 1, parent: $0).focus()
}

XCTAssertTrue(focusSourceOfTruth == .macOs)
MoveNodeToWorkspaceCommand(targetWorkspaceName: "b").testRun()
XCTAssertTrue(workspaceA.isEffectivelyEmpty)
XCTAssertTrue(focusSourceOfTruth == .ownModel)
XCTAssertEqual((Workspace.get(byName: "b").rootTilingContainer.children.singleOrNil() as? Window)?.windowId, 1)
}

func testPreserveFloatingLayout() {
let workspaceA = Workspace.get(byName: "a").apply {
TestWindow(id: 1, parent: $0).nativeFocus()
TestWindow(id: 1, parent: $0).focus()
}

XCTAssertTrue(focusSourceOfTruth == .macOs)
MoveNodeToWorkspaceCommand(targetWorkspaceName: "b").testRun()
XCTAssertTrue(workspaceA.isEffectivelyEmpty)
XCTAssertTrue(focusSourceOfTruth == .ownModel)
XCTAssertEqual(Workspace.get(byName: "b").children.filterIsInstance(of: Window.self).singleOrNil()?.windowId, 1)
}
}
16 changes: 9 additions & 7 deletions test/command/MoveThroughCommandTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ final class MoveThroughCommandTest: XCTestCase {

func testMove_swapWindows() {
let root = Workspace.get(byName: name).rootTilingContainer.apply {
TestWindow(id: 1, parent: $0).nativeFocus()
TestWindow(id: 1, parent: $0).focus()
TestWindow(id: 2, parent: $0)
}

Expand All @@ -17,7 +17,7 @@ final class MoveThroughCommandTest: XCTestCase {
func testMoveInto_findTopMostContainerWithRightOrientation() {
let root = Workspace.get(byName: name).rootTilingContainer.apply {
TestWindow(id: 0, parent: $0)
TestWindow(id: 1, parent: $0).nativeFocus()
TestWindow(id: 1, parent: $0).focus()
TilingContainer.newHTiles(parent: $0, adaptiveWeight: 1).apply {
TilingContainer.newHTiles(parent: $0, adaptiveWeight: 1).apply {
TestWindow(id: 2, parent: $0)
Expand All @@ -42,9 +42,10 @@ final class MoveThroughCommandTest: XCTestCase {

func testMove_mru() {
var window3: Window!
var start: Window!
let root = Workspace.get(byName: name).rootTilingContainer.apply {
TestWindow(id: 0, parent: $0)
TestWindow(id: 1, parent: $0).nativeFocus()
start = TestWindow(id: 1, parent: $0)
TilingContainer.newVTiles(parent: $0, adaptiveWeight: 1).apply {
TilingContainer.newHTiles(parent: $0, adaptiveWeight: 1).apply {
TestWindow(id: 2, parent: $0)
Expand All @@ -54,6 +55,7 @@ final class MoveThroughCommandTest: XCTestCase {
}
}
window3.markAsMostRecentChild()
start.focus()

MoveThroughCommand(direction: .right).testRun()
XCTAssertEqual(
Expand All @@ -76,7 +78,7 @@ final class MoveThroughCommandTest: XCTestCase {
let root = Workspace.get(byName: name).rootTilingContainer
let window1 = TestWindow(id: 1, parent: root, adaptiveWeight: 1)
let window2 = TestWindow(id: 2, parent: root, adaptiveWeight: 2)
window2.nativeFocus()
window2.focus()

MoveThroughCommand(direction: .left).testRun() // todo replace all 'runWithoutRefresh' with 'run' in tests
XCTAssertEqual(window2.hWeight, 2)
Expand All @@ -93,7 +95,7 @@ final class MoveThroughCommandTest: XCTestCase {
window2 = TestWindow(id: 2, parent: $0, adaptiveWeight: 1)
}
}
window1.nativeFocus()
window1.focus()

MoveThroughCommand(direction: .right).testRun()
XCTAssertEqual(window2.hWeight, 1)
Expand All @@ -106,7 +108,7 @@ final class MoveThroughCommandTest: XCTestCase {
let workspace = Workspace.get(byName: name)
workspace.rootTilingContainer.apply {
TestWindow(id: 1, parent: $0)
TestWindow(id: 2, parent: $0).nativeFocus()
TestWindow(id: 2, parent: $0).focus()
TestWindow(id: 3, parent: $0)
}

Expand All @@ -126,7 +128,7 @@ final class MoveThroughCommandTest: XCTestCase {
let root = Workspace.get(byName: name).rootTilingContainer.apply {
TestWindow(id: 1, parent: $0)
TilingContainer.newVTiles(parent: $0, adaptiveWeight: 1).apply {
TestWindow(id: 2, parent: $0).nativeFocus()
TestWindow(id: 2, parent: $0).focus()
TestWindow(id: 3, parent: $0)
TestWindow(id: 4, parent: $0)
}
Expand Down
8 changes: 4 additions & 4 deletions test/command/SplitCommandTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ final class SplitCommandTest: XCTestCase {

func testSplit() {
let root = Workspace.get(byName: name).rootTilingContainer.apply {
TestWindow(id: 1, parent: $0).nativeFocus()
TestWindow(id: 1, parent: $0).focus()
TestWindow(id: 2, parent: $0)
}

Expand All @@ -21,7 +21,7 @@ final class SplitCommandTest: XCTestCase {

func testSplitOppositeOrientation() {
let root = Workspace.get(byName: name).rootTilingContainer.apply {
TestWindow(id: 1, parent: $0).nativeFocus()
TestWindow(id: 1, parent: $0).focus()
TestWindow(id: 2, parent: $0)
}

Expand All @@ -37,7 +37,7 @@ final class SplitCommandTest: XCTestCase {
func testChangeOrientation() {
let root = Workspace.get(byName: name).rootTilingContainer.apply {
TilingContainer.newVTiles(parent: $0, adaptiveWeight: 1).apply {
TestWindow(id: 1, parent: $0).nativeFocus()
TestWindow(id: 1, parent: $0).focus()
}
TestWindow(id: 2, parent: $0)
}
Expand All @@ -54,7 +54,7 @@ final class SplitCommandTest: XCTestCase {
func testToggleOrientation() {
let root = Workspace.get(byName: name).rootTilingContainer.apply {
TilingContainer.newVTiles(parent: $0, adaptiveWeight: 1).apply {
TestWindow(id: 1, parent: $0).nativeFocus()
TestWindow(id: 1, parent: $0).focus()
}
TestWindow(id: 2, parent: $0)
}
Expand Down
4 changes: 0 additions & 4 deletions test/testUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,3 @@ func testParseCommandFail(_ command: String, msg expected: String) {
XCTAssertEqual(msg, expected)
}
}

var focusSourceOfTruth: FocusSourceOfTruth {
getFocusSourceOfTruth(startup: false)
}

0 comments on commit f992d74

Please sign in to comment.