Browse Source

Add a test for toasty..

pull/113/head
Abhishek Banthia 3 years ago
parent
commit
075b1e4b67
  1. 12
      Clocker/ClockerUnitTests/ClockerUnitTests.swift
  2. 13
      Clocker/Panel/UI/Toasty.swift

12
Clocker/ClockerUnitTests/ClockerUnitTests.swift

@ -403,4 +403,16 @@ class ClockerUnitTests: XCTestCase {
XCTAssertEqual(emptyString.filteredName(), "") XCTAssertEqual(emptyString.filteredName(), "")
} }
func testToasty() {
let view = NSView(frame: CGRect.zero)
view.makeToast("Hello, this is a toast")
XCTAssertEqual(view.subviews.first?.accessibilityIdentifier(), "ToastView")
let expectation = expectation(description: "Toast View should hide after 1 second")
let result = XCTWaiter.wait(for: [expectation], timeout: 1.5) // Set 2 seconds here for a little leeway
if result == XCTWaiter.Result.timedOut {
XCTAssertTrue(view.subviews.isEmpty)
}
}
} }

13
Clocker/Panel/UI/Toasty.swift

@ -63,13 +63,12 @@ public protocol Style {
var horizontalMargin: CGFloat { get } var horizontalMargin: CGFloat { get }
var verticalMargin: CGFloat { get } var verticalMargin: CGFloat { get }
var cornerRadius: CGFloat { get } var cornerRadius: CGFloat { get }
var font: NSFont { get } var font: NSFont? { get }
var backgroundColor: NSColor { get } var backgroundColor: NSColor { get }
var foregroundColor: NSColor { get } var foregroundColor: NSColor { get }
var fadeInOutDuration: CGFloat { get } var fadeInOutDuration: CGFloat { get }
var fadeInOutDelay: CGFloat { get } var fadeInOutDelay: CGFloat { get }
var labelOriginWithMargin: CGPoint { get } var labelOriginWithMargin: CGPoint { get }
var activitySize: CGSize { get }
} }
public extension Style { public extension Style {
@ -78,11 +77,8 @@ public extension Style {
} }
var fontSize: CGFloat { return 12 } var fontSize: CGFloat { return 12 }
var font: NSFont { var font: NSFont? {
if let avenirFont = NSFont(name: "Avenir-Light", size: fontSize) { return NSFont(name: "Avenir-Light", size: fontSize)
return avenirFont
}
return NSFont.systemFont(ofSize: fontSize)
} }
var horizontalMargin: CGFloat { return 10 } var horizontalMargin: CGFloat { return 10 }
@ -90,7 +86,6 @@ public extension Style {
var cornerRadius: CGFloat { return 8 } var cornerRadius: CGFloat { return 8 }
var backgroundColor: NSColor { return .black } var backgroundColor: NSColor { return .black }
var foregroundColor: NSColor { return .white } var foregroundColor: NSColor { return .white }
var activitySize: CGSize { return CGSize(width: 100, height: 100) }
var fadeInOutDuration: CGFloat { return 1.0 } var fadeInOutDuration: CGFloat { return 1.0 }
var fadeInOutDelay: CGFloat { return 1.0 } var fadeInOutDelay: CGFloat { return 1.0 }
} }
@ -155,7 +150,7 @@ class ToastView: NSView {
text.frame = rect text.frame = rect
text.position = CGRect.center(of: container) text.position = CGRect.center(of: container)
text.string = message text.string = message
text.font = NSFont.systemFont(ofSize: style.fontSize) text.font = style.font
text.fontSize = style.fontSize text.fontSize = style.fontSize
text.alignmentMode = .center text.alignmentMode = .center
text.foregroundColor = style.foregroundColor.cgColor text.foregroundColor = style.foregroundColor.cgColor

Loading…
Cancel
Save