From 2056ec94f8536240d4845bac921c1b7206dd1112 Mon Sep 17 00:00:00 2001 From: Ian Ynda-Hummel Date: Sun, 1 Dec 2019 18:50:17 -0500 Subject: [PATCH] Add test for tall layout --- Amethyst.xcodeproj/project.pbxproj | 4 + .../Tests/Layout/TallLayoutTests.swift | 197 ++++++++++++++++++ 2 files changed, 201 insertions(+) create mode 100644 AmethystTests/Tests/Layout/TallLayoutTests.swift diff --git a/Amethyst.xcodeproj/project.pbxproj b/Amethyst.xcodeproj/project.pbxproj index 89a5f5dc..e5903f97 100644 --- a/Amethyst.xcodeproj/project.pbxproj +++ b/Amethyst.xcodeproj/project.pbxproj @@ -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 */; }; @@ -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 = ""; }; 403E1A292337173600DB7B2A /* FloatingLayoutTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FloatingLayoutTests.swift; sourceTree = ""; }; + 403E1A2B233719E500DB7B2A /* TallLayoutTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TallLayoutTests.swift; sourceTree = ""; }; 4046EFCE2236019400113067 /* Window.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Window.swift; sourceTree = ""; }; 4046EFD02238949900113067 /* Application.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Application.swift; sourceTree = ""; }; 404BE9CD1CFBB6E900D6C537 /* BinarySpacePartitioningLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BinarySpacePartitioningLayout.swift; sourceTree = ""; }; @@ -395,6 +397,7 @@ 403E1A292337173600DB7B2A /* FloatingLayoutTests.swift */, 40B0D144232D2E630021E0A7 /* FullscreenLayoutTests.swift */, 40D491D723367590007E0CCB /* RowLayoutTests.swift */, + 403E1A2B233719E500DB7B2A /* TallLayoutTests.swift */, ); path = Layout; sourceTree = ""; @@ -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; diff --git a/AmethystTests/Tests/Layout/TallLayoutTests.swift b/AmethystTests/Tests/Layout/TallLayoutTests.swift new file mode 100644 index 00000000..7ae835be --- /dev/null +++ b/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( + windows: layoutWindows, + isWindowWithIDActive: { _ in return true }, + isWindowWithIDFloating: { _ in return false }, + windowForID: { id in return windows.first { $0.windowID() == id } } + ) + let layout = TallLayout() + 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( + windows: layoutWindows, + isWindowWithIDActive: { _ in return true }, + isWindowWithIDFloating: { _ in return false }, + windowForID: { id in return windows.first { $0.windowID() == id } } + ) + let layout = TallLayout() + + 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( + windows: layoutWindows, + isWindowWithIDActive: { _ in return true }, + isWindowWithIDFloating: { _ in return false }, + windowForID: { id in return windows.first { $0.windowID() == id } } + ) + let layout = TallLayout() + + 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) + ]) + } + } + } +}