Browse Source

Merge branch 'master' of https://github.com/n0shake/Clocker

pull/113/head
Abhishek 3 years ago
parent
commit
6572238159
  1. 4
      Clocker/AppDelegate.swift
  2. 8
      Clocker/Clocker.xcodeproj/project.pbxproj
  3. 73
      Clocker/ClockerUnitTests/AppDelegateTests.swift
  4. 11
      Clocker/ClockerUnitTests/ClockerUnitTests.swift
  5. 36
      Clocker/ClockerUnitTests/DateFormatterManagerTests.swift
  6. 25
      Clocker/Overall App/DateFormatterManager.swift
  7. 2
      Clocker/Panel/ParentPanelController.swift

4
Clocker/AppDelegate.swift

@ -262,10 +262,6 @@ open class AppDelegate: NSObject, NSApplicationDelegate {
return statusBarHandler
}
open func setPanelDefaults() {
panelController.updateDefaultPreferences()
}
open func setupMenubarTimer() {
statusBarHandler.setupStatusItem()
}

8
Clocker/Clocker.xcodeproj/project.pbxproj

@ -51,6 +51,8 @@
3548C45F26BEEFB400AFB533 /* UpcomingEventsDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3548C45E26BEEFB400AFB533 /* UpcomingEventsDataSource.swift */; };
3548C46126BEEFE400AFB533 /* UpcomingEventViewItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3548C46026BEEFE400AFB533 /* UpcomingEventViewItem.swift */; };
35584D1427EF8EB5006E3EAD /* ThemerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35584D1327EF8EB5006E3EAD /* ThemerTests.swift */; };
35584D1827F0B019006E3EAD /* DateFormatterManagerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35584D1727F0B019006E3EAD /* DateFormatterManagerTests.swift */; };
35584D1A27F0B64E006E3EAD /* AppDelegateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35584D1927F0B64E006E3EAD /* AppDelegateTests.swift */; };
357391872507277500D30819 /* TimeMarkerViewItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 357391852507277500D30819 /* TimeMarkerViewItem.swift */; };
357391882507277500D30819 /* HourMarkerViewItem.xib in Resources */ = {isa = PBXBuildFile; fileRef = 357391862507277500D30819 /* HourMarkerViewItem.xib */; };
3579765E2680208C009DDA6E /* ParentPanelController+ModernSlider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3579765D2680208C009DDA6E /* ParentPanelController+ModernSlider.swift */; };
@ -286,6 +288,8 @@
3552066427AF6488000EF08F /* pl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pl; path = pl.lproj/InfoPlist.strings; sourceTree = "<group>"; };
3552066527AF6489000EF08F /* pl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = pl; path = pl.lproj/Localizable.strings; sourceTree = "<group>"; };
35584D1327EF8EB5006E3EAD /* ThemerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemerTests.swift; sourceTree = "<group>"; };
35584D1727F0B019006E3EAD /* DateFormatterManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateFormatterManagerTests.swift; sourceTree = "<group>"; };
35584D1927F0B64E006E3EAD /* AppDelegateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegateTests.swift; sourceTree = "<group>"; };
3569A44E25441F320087E254 /* pt-BR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "pt-BR"; path = "pt-BR.lproj/Localizable.strings"; sourceTree = "<group>"; };
357391852507277500D30819 /* TimeMarkerViewItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimeMarkerViewItem.swift; sourceTree = "<group>"; };
357391862507277500D30819 /* HourMarkerViewItem.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = HourMarkerViewItem.xib; sourceTree = "<group>"; };
@ -881,6 +885,8 @@
C20839CB21515C1F00C86589 /* Info.plist */,
9A0385BA269E3434003B5E72 /* StandardMenubarHandlerTests.swift */,
35584D1327EF8EB5006E3EAD /* ThemerTests.swift */,
35584D1727F0B019006E3EAD /* DateFormatterManagerTests.swift */,
35584D1927F0B64E006E3EAD /* AppDelegateTests.swift */,
);
path = ClockerUnitTests;
sourceTree = "<group>";
@ -1267,7 +1273,9 @@
buildActionMask = 2147483647;
files = (
35584D1427EF8EB5006E3EAD /* ThemerTests.swift in Sources */,
35584D1A27F0B64E006E3EAD /* AppDelegateTests.swift in Sources */,
9A0385BB269E3434003B5E72 /* StandardMenubarHandlerTests.swift in Sources */,
35584D1827F0B019006E3EAD /* DateFormatterManagerTests.swift in Sources */,
C20839CA21515C1E00C86589 /* ClockerUnitTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;

73
Clocker/ClockerUnitTests/AppDelegateTests.swift

@ -0,0 +1,73 @@
// Copyright © 2015 Abhishek Banthia
import XCTest
@testable import Clocker
class AppDelegateTests: XCTestCase {
func testStatusItemIsInitialized() throws {
let subject = NSApplication.shared.delegate as? AppDelegate
let statusHandler = subject?.statusItemForPanel()
XCTAssertNotNil(EventCenter.sharedCenter)
XCTAssertNotNil(statusHandler)
}
func testDockMenu() throws {
let subject = NSApplication.shared.delegate as? AppDelegate
let dockMenu = subject?.applicationDockMenu(NSApplication.shared)
let items = dockMenu?.items ?? []
XCTAssertEqual(dockMenu?.title, "Quick Access")
XCTAssertEqual(items.first?.title, "Toggle Panel")
XCTAssertEqual(items[1].title, "Preferences")
XCTAssertEqual(items[1].keyEquivalent, ",")
XCTAssertEqual(items[2].title, "Hide from Dock")
// Test selections
XCTAssertEqual(items.first?.action, #selector(AppDelegate.togglePanel(_:)))
XCTAssertEqual(items[2].action, #selector(AppDelegate.hideFromDock))
items.forEach { menuItem in
XCTAssertTrue(menuItem.isEnabled)
}
}
func testSetupMenubarTimer() {
let subject = NSApplication.shared.delegate as? AppDelegate
let statusItemHandler = subject?.statusItemForPanel()
XCTAssertEqual(statusItemHandler?.statusItem.autosaveName, NSStatusItem.AutosaveName("ClockerStatusItem"))
}
func testFloatingWindow() {
let subject = NSApplication.shared.delegate as? AppDelegate
let previousWindows = NSApplication.shared.windows
XCTAssertEqual(previousWindows.count, 1) // Only the status bar window should be present
subject?.setupFloatingWindow(true)
let floatingWindow = NSApplication.shared.windows.first { window in
if ((window.windowController as? FloatingWindowController) != nil) {
return true
}
return false
}
XCTAssertNotNil(floatingWindow)
XCTAssertEqual(floatingWindow?.windowController?.windowFrameAutosaveName, NSWindow.FrameAutosaveName("FloatingWindowAutoSave"))
subject?.setupFloatingWindow(false)
let closedFloatingWindow = NSApplication.shared.windows.first { window in
if ((window.windowController as? FloatingWindowController) != nil) {
return true
}
return false
}
XCTAssertNotNil(closedFloatingWindow)
}
}

11
Clocker/ClockerUnitTests/ClockerUnitTests.swift

@ -392,4 +392,15 @@ class ClockerUnitTests: XCTestCase {
XCTAssertNotNil(convertedDate)
}
}
func testStringFiltering() {
let stringWithComma = "Mumbai, Maharashtra"
let stringWithoutComma = "Mumbai"
let emptyString = ""
XCTAssertEqual(stringWithComma.filteredName(), "Mumbai")
XCTAssertEqual(stringWithoutComma.filteredName(), "Mumbai")
XCTAssertEqual(emptyString.filteredName(), "")
}
}

36
Clocker/ClockerUnitTests/DateFormatterManagerTests.swift

@ -0,0 +1,36 @@
// Copyright © 2015 Abhishek Banthia
import XCTest
@testable import Clocker
class DateFormatterManagerTests: XCTestCase {
func testRegularDateFormatter() throws {
let subject = DateFormatterManager.dateFormatter(with: .medium, for: "UTC")
XCTAssertEqual(subject.dateStyle, .medium)
XCTAssertEqual(subject.timeStyle, .medium)
XCTAssertEqual(subject.locale.identifier, "en_US")
XCTAssertEqual(subject.timeZone.identifier, "GMT")
}
func testDateFormatterWithFormat() throws {
let subject = DateFormatterManager.dateFormatterWithFormat(with: .none, format: "hh:mm a", timezoneIdentifier: "Asia/Calcutta")
XCTAssertEqual(subject.dateStyle, .none)
XCTAssertEqual(subject.timeStyle, .none)
XCTAssertEqual(subject.locale.identifier, "en_US")
XCTAssertEqual(subject.timeZone.identifier, "Asia/Calcutta")
XCTAssertEqual(subject.locale.identifier, "en_US")
XCTAssertEqual(subject.dateFormat, "hh:mm a")
}
func testLocalizedDateFormatter() throws {
let subject = DateFormatterManager.localizedFormatter(with: "hh:mm:ss", for: "America/Los_Angeles")
XCTAssertEqual(subject.dateStyle, .none)
XCTAssertEqual(subject.timeStyle, .none)
XCTAssertEqual(subject.locale.identifier, Locale.autoupdatingCurrent.identifier)
XCTAssertEqual(subject.timeZone.identifier, "America/Los_Angeles")
XCTAssertEqual(subject.dateFormat, "hh:mm:ss")
}
}

25
Clocker/Overall App/DateFormatterManager.swift

@ -3,7 +3,6 @@
import Cocoa
class DateFormatterManager: NSObject {
public static let sharedInstance = DateFormatterManager()
private static var dateFormatter = DateFormatter()
private static var calendarDateFormatter = DateFormatter()
@ -22,21 +21,6 @@ class DateFormatterManager: NSObject {
return dateFormatter
}
class func dateFormatterWithCalendar(with style: DateFormatter.Style) -> DateFormatter {
calendarDateFormatter.dateStyle = style
calendarDateFormatter.timeStyle = style
calendarDateFormatter.locale = USLocale
calendarDateFormatter.calendar = gregorianCalendar
return calendarDateFormatter
}
class func simpleFormatter(with style: DateFormatter.Style) -> DateFormatter {
simpleFormatter.dateStyle = style
simpleFormatter.timeStyle = style
simpleFormatter.locale = USLocale
return simpleFormatter
}
class func dateFormatterWithFormat(with style: DateFormatter.Style, format: String, timezoneIdentifier: String, locale: Locale = Locale(identifier: "en_US")) -> DateFormatter {
specializedFormatter.dateStyle = style
specializedFormatter.timeStyle = style
@ -55,15 +39,6 @@ class DateFormatterManager: NSObject {
return dateFormatter
}
class func localizedCalendaricalDateFormatter(with format: String) -> DateFormatter {
calendarDateFormatter.dateStyle = .none
calendarDateFormatter.timeStyle = .none
calendarDateFormatter.locale = Locale.autoupdatingCurrent
calendarDateFormatter.dateFormat = format
calendarDateFormatter.calendar = gregorianCalendar
return calendarDateFormatter
}
class func localizedSimpleFormatter(_ format: String) -> DateFormatter {
localizedSimpleFormatter.dateStyle = .none
localizedSimpleFormatter.timeStyle = .none

2
Clocker/Panel/ParentPanelController.swift

@ -785,7 +785,7 @@ class ParentPanelController: NSWindowController {
sharedDelegate.setupFloatingWindow(false)
} else {
sharedDelegate.setupFloatingWindow(true)
sharedDelegate.setPanelDefaults()
updateDefaultPreferences()
}
let mode = inverseSelection.isEqual(to: NSNumber(value: 1)) ? "Floating Mode" : "Menubar Mode"

Loading…
Cancel
Save