Skip to content

Commit

Permalink
Add test for floating layout
Browse files Browse the repository at this point in the history
  • Loading branch information
ianyh committed Dec 2, 2019
1 parent 95079c9 commit a442778
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 8 deletions.
4 changes: 4 additions & 0 deletions Amethyst.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
402DB6F21742E41A00D1C936 /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 402DB6F01742E41A00D1C936 /* Credits.rtf */; };
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 */; };
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 @@ -150,6 +151,7 @@
402DB6F71742E41A00D1C936 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/MainMenu.xib; sourceTree = "<group>"; };
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>"; };
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 @@ -390,6 +392,7 @@
children = (
404BE9D01CFBDF1900D6C537 /* BinarySpacePartitioningLayoutTests.swift */,
401BBCB52333067F005118F8 /* ColumnLayoutTests.swift */,
403E1A292337173600DB7B2A /* FloatingLayoutTests.swift */,
40B0D144232D2E630021E0A7 /* FullscreenLayoutTests.swift */,
40D491D723367590007E0CCB /* RowLayoutTests.swift */,
);
Expand Down Expand Up @@ -776,6 +779,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
403E1A2A2337173600DB7B2A /* FloatingLayoutTests.swift in Sources */,
40111CC9223370FD003D20BD /* SIWindow+AmethystTests.swift in Sources */,
401BBCB62333067F005118F8 /* ColumnLayoutTests.swift in Sources */,
401BC8AE1CE8FD4700F89B3F /* UserConfigurationTests.swift in Sources */,
Expand Down
10 changes: 2 additions & 8 deletions AmethystTests/Helpers/FrameAssignmentVerification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,12 @@ import Foundation
import Nimble

extension RandomAccessCollection where Element == FrameAssignment<TestWindow>, Index == Int {
typealias Window = TestWindow

func filtered(byIDs ids: [CGWindowID]) -> [Element] {
return filter { ids.contains($0.window.id) }
}

func forWindows<C: RandomAccessCollection>(_ windows: C) -> [Element] where C.Element == Window, C.Index == Index {
let convertedWindows = Array(windows)
guard convertedWindows.count > 1 else {
return filtered(byIDs: [convertedWindows[0].windowID()]).sorted()
}
return filtered(byIDs: convertedWindows.map { $0.windowID() }).sorted()
func forWindows<C: RandomAccessCollection>(_ windows: C) -> [Element] where C.Element == TestWindow, C.Index == Index {
return filtered(byIDs: Array(windows).map { $0.windowID() }).sorted()
}

func sorted() -> [FrameAssignment<TestWindow>] {
Expand Down
46 changes: 46 additions & 0 deletions AmethystTests/Tests/Layout/FloatingLayoutTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// FloatingLayoutTests.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 FloatingLayoutTests: QuickSpec {
override func spec() {
afterEach {
TestScreen.availableScreens = []
}

describe("layout") {
it("generates no assignments") {
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 = FloatingLayout<TestWindow>()

expect(layout.frameAssignments(windowSet, on: screen)).to(beNil())
}
}
}
}

0 comments on commit a442778

Please sign in to comment.