Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
201 additions
and
0 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
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 |
---|---|---|
@@ -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) | ||
]) | ||
} | ||
} | ||
} | ||
} |