Skip to content

Commit

Permalink
Add test for tall layout
Browse files Browse the repository at this point in the history
  • Loading branch information
ianyh committed Dec 2, 2019
1 parent a442778 commit 2056ec9
Show file tree
Hide file tree
Showing 2 changed files with 201 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Amethyst.xcodeproj/project.pbxproj
Expand Up @@ -41,6 +41,7 @@
402DB6F81742E41A00D1C936 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 402DB6F61742E41A00D1C936 /* MainMenu.xib */; };
402DB6FF1742E44E00D1C936 /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 402DB6FE1742E44E00D1C936 /* Carbon.framework */; };
403E1A2A2337173600DB7B2A /* FloatingLayoutTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 403E1A292337173600DB7B2A /* FloatingLayoutTests.swift */; };
403E1A2C233719E500DB7B2A /* TallLayoutTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 403E1A2B233719E500DB7B2A /* TallLayoutTests.swift */; };
4046EFCF2236019400113067 /* Window.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4046EFCE2236019400113067 /* Window.swift */; };
4046EFD12238949900113067 /* Application.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4046EFD02238949900113067 /* Application.swift */; };
404BE9CE1CFBB6E900D6C537 /* BinarySpacePartitioningLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 404BE9CD1CFBB6E900D6C537 /* BinarySpacePartitioningLayout.swift */; };
Expand Down Expand Up @@ -152,6 +153,7 @@
402DB6FE1742E44E00D1C936 /* Carbon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Carbon.framework; path = System/Library/Frameworks/Carbon.framework; sourceTree = SDKROOT; };
40378E22238F39B900D11E22 /* Amethyst.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Amethyst.entitlements; sourceTree = "<group>"; };
403E1A292337173600DB7B2A /* FloatingLayoutTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FloatingLayoutTests.swift; sourceTree = "<group>"; };
403E1A2B233719E500DB7B2A /* TallLayoutTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TallLayoutTests.swift; sourceTree = "<group>"; };
4046EFCE2236019400113067 /* Window.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Window.swift; sourceTree = "<group>"; };
4046EFD02238949900113067 /* Application.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Application.swift; sourceTree = "<group>"; };
404BE9CD1CFBB6E900D6C537 /* BinarySpacePartitioningLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BinarySpacePartitioningLayout.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -395,6 +397,7 @@
403E1A292337173600DB7B2A /* FloatingLayoutTests.swift */,
40B0D144232D2E630021E0A7 /* FullscreenLayoutTests.swift */,
40D491D723367590007E0CCB /* RowLayoutTests.swift */,
403E1A2B233719E500DB7B2A /* TallLayoutTests.swift */,
);
path = Layout;
sourceTree = "<group>";
Expand Down Expand Up @@ -789,6 +792,7 @@
40B0D145232D2E630021E0A7 /* FullscreenLayoutTests.swift in Sources */,
40B0D14B232D944C0021E0A7 /* TestWindow.swift in Sources */,
40D491D823367590007E0CCB /* RowLayoutTests.swift in Sources */,
403E1A2C233719E500DB7B2A /* TallLayoutTests.swift in Sources */,
40D491DB23367630007E0CCB /* FrameAssignmentVerification.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
197 changes: 197 additions & 0 deletions AmethystTests/Tests/Layout/TallLayoutTests.swift
@@ -0,0 +1,197 @@
//
// TallLayoutTests.swift
// AmethystTests
//
// Created by Ian Ynda-Hummel on 9/21/19.
// Copyright © 2019 Ian Ynda-Hummel. All rights reserved.
//

@testable import Amethyst
import Nimble
import Quick
import Silica

class TallLayoutTests: QuickSpec {
override func spec() {
afterEach {
TestScreen.availableScreens = []
}

describe("layout") {
it("separates into a main pane and a secondary pane") {
let screen = TestScreen(frame: CGRect(origin: .zero, size: CGSize(width: 2000, height: 1000)))
TestScreen.availableScreens = [screen]

let windows = [
TestWindow(element: nil)!,
TestWindow(element: nil)!,
TestWindow(element: nil)!
]
let layoutWindows = windows.map {
LayoutWindow(id: $0.windowID(), frame: $0.frame(), isFocused: false)
}
let windowSet = WindowSet<TestWindow>(
windows: layoutWindows,
isWindowWithIDActive: { _ in return true },
isWindowWithIDFloating: { _ in return false },
windowForID: { id in return windows.first { $0.windowID() == id } }
)
let layout = TallLayout<TestWindow>()
let frameAssignments = layout.frameAssignments(windowSet, on: screen)!

expect(layout.mainPaneCount).to(equal(1))

let mainAssignment = frameAssignments.forWindows(windows[..<1])
let secondaryAssignments = frameAssignments.forWindows(windows[1...])

mainAssignment.verify(frames: [
CGRect(origin: .zero, size: CGSize(width: 1000, height: 1000))
])
secondaryAssignments.verify(frames: [
CGRect(x: 1000, y: 0, width: 1000, height: 500),
CGRect(x: 1000, y: 500, width: 1000, height: 500)
])
}

it("increases and decreases windows in the main pane") {
let screen = TestScreen(frame: CGRect(origin: .zero, size: CGSize(width: 2000, height: 1000)))
TestScreen.availableScreens = [screen]

let windows = [
TestWindow(element: nil)!,
TestWindow(element: nil)!,
TestWindow(element: nil)!,
TestWindow(element: nil)!
]
let layoutWindows = windows.map {
LayoutWindow(id: $0.windowID(), frame: $0.frame(), isFocused: false)
}
let windowSet = WindowSet<TestWindow>(
windows: layoutWindows,
isWindowWithIDActive: { _ in return true },
isWindowWithIDFloating: { _ in return false },
windowForID: { id in return windows.first { $0.windowID() == id } }
)
let layout = TallLayout<TestWindow>()

expect(layout.mainPaneCount).to(equal(1))

var frameAssignments = layout.frameAssignments(windowSet, on: screen)!
var mainAssignments = frameAssignments.forWindows(windows[..<1])
var secondaryAssignments = frameAssignments.forWindows(windows[1...])

mainAssignments.verify(frames: [
CGRect(x: 0, y: 0, width: 1000, height: 1000)
])

secondaryAssignments.verify(frames: [
CGRect(x: 1000, y: 0, width: 1000, height: 333),
CGRect(x: 1000, y: 333, width: 1000, height: 333),
CGRect(x: 1000, y: 666, width: 1000, height: 333)
])

layout.increaseMainPaneCount()
expect(layout.mainPaneCount).to(equal(2))

frameAssignments = layout.frameAssignments(windowSet, on: screen)!
mainAssignments = frameAssignments.forWindows(windows[..<2])
secondaryAssignments = frameAssignments.forWindows(windows[2...])

mainAssignments.verify(frames: [
CGRect(x: 0, y: 0, width: 1000, height: 500),
CGRect(x: 0, y: 500, width: 1000, height: 500)
])

secondaryAssignments.verify(frames: [
CGRect(x: 1000, y: 0, width: 1000, height: 500),
CGRect(x: 1000, y: 500, width: 1000, height: 500)
])

layout.increaseMainPaneCount()
expect(layout.mainPaneCount).to(equal(3))

frameAssignments = layout.frameAssignments(windowSet, on: screen)!
mainAssignments = frameAssignments.forWindows(windows[..<3])
secondaryAssignments = frameAssignments.forWindows(windows[3...])

mainAssignments.verify(frames: [
CGRect(x: 0, y: 0, width: 1000, height: 333),
CGRect(x: 0, y: 333, width: 1000, height: 333),
CGRect(x: 0, y: 666, width: 1000, height: 333)
])

secondaryAssignments.verify(frames: [
CGRect(x: 1000, y: 0, width: 1000, height: 1000)
])
}

it("changes distribution based on pane ratio") {
let screen = TestScreen(frame: CGRect(origin: .zero, size: CGSize(width: 2000, height: 1000)))
TestScreen.availableScreens = [screen]

let windows = [
TestWindow(element: nil)!,
TestWindow(element: nil)!,
TestWindow(element: nil)!
]
let layoutWindows = windows.map {
LayoutWindow(id: $0.windowID(), frame: $0.frame(), isFocused: false)
}
let windowSet = WindowSet<TestWindow>(
windows: layoutWindows,
isWindowWithIDActive: { _ in return true },
isWindowWithIDFloating: { _ in return false },
windowForID: { id in return windows.first { $0.windowID() == id } }
)
let layout = TallLayout<TestWindow>()

expect(layout.mainPaneCount).to(equal(1))

var frameAssignments = layout.frameAssignments(windowSet, on: screen)!
var mainAssignments = frameAssignments.forWindows(windows[..<1])
var secondaryAssignments = frameAssignments.forWindows(windows[1...])

mainAssignments.verify(frames: [
CGRect(x: 0, y: 0, width: 1000, height: 1000)
])

secondaryAssignments.verify(frames: [
CGRect(x: 1000, y: 0, width: 1000, height: 500),
CGRect(x: 1000, y: 500, width: 1000, height: 500)
])

layout.recommendMainPaneRatio(0.75)
expect(layout.mainPaneRatio).to(equal(0.75))

frameAssignments = layout.frameAssignments(windowSet, on: screen)!
mainAssignments = frameAssignments.forWindows(windows[..<1])
secondaryAssignments = frameAssignments.forWindows(windows[1...])

mainAssignments.verify(frames: [
CGRect(x: 0, y: 0, width: 1500, height: 1000)
])

secondaryAssignments.verify(frames: [
CGRect(x: 1500, y: 0, width: 500, height: 500),
CGRect(x: 1500, y: 500, width: 500, height: 500)
])

layout.recommendMainPaneRatio(0.25)
expect(layout.mainPaneRatio).to(equal(0.25))

frameAssignments = layout.frameAssignments(windowSet, on: screen)!
mainAssignments = frameAssignments.forWindows(windows[..<1])
secondaryAssignments = frameAssignments.forWindows(windows[1...])

mainAssignments.verify(frames: [
CGRect(x: 0, y: 0, width: 500, height: 1000)
])

secondaryAssignments.verify(frames: [
CGRect(x: 500, y: 0, width: 1500, height: 500),
CGRect(x: 500, y: 500, width: 1500, height: 500)
])
}
}
}
}

0 comments on commit 2056ec9

Please sign in to comment.