Browse Source

Swiftformat.

pull/113/head
Abhishek Banthia 3 years ago
parent
commit
4dcd80e4e1
  1. 2
      Clocker/AppDelegate.swift
  2. 2
      Clocker/ClockerUnitTests/ClockerUnitTests.swift
  3. 19
      Clocker/ClockerUnitTests/EventInfoTests.swift
  4. 39
      Clocker/ClockerUnitTests/StandardMenubarHandlerTests.swift
  5. 2
      Clocker/Onboarding/OnboardingParentViewController.swift
  6. 6
      Clocker/Onboarding/OnboardingSearchController.swift
  7. 2
      Clocker/Overall App/AppKit + Additions.swift
  8. 4
      Clocker/Overall App/DataStore.swift
  9. 2
      Clocker/Panel/PanelController.swift
  10. 2
      Clocker/Panel/ParentPanelController.swift
  11. 2
      Clocker/Preferences/About/AboutViewController.swift
  12. 4
      Clocker/Preferences/App Feedback/AppFeedbackWindowController.swift

2
Clocker/AppDelegate.swift

@ -110,7 +110,7 @@ open class AppDelegate: NSObject, NSApplicationDelegate {
if controller != nil { if controller != nil {
controller = nil controller = nil
} }
// Check if another instance of the app is already running. If so, then stop this one. // Check if another instance of the app is already running. If so, then stop this one.
checkIfAppIsAlreadyOpen() checkIfAppIsAlreadyOpen()

2
Clocker/ClockerUnitTests/ClockerUnitTests.swift

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

19
Clocker/ClockerUnitTests/EventInfoTests.swift

@ -1,8 +1,8 @@
// Copyright © 2015 Abhishek Banthia // Copyright © 2015 Abhishek Banthia
import XCTest
@testable import Clocker @testable import Clocker
import EventKit import EventKit
import XCTest
class EventInfoTests: XCTestCase { class EventInfoTests: XCTestCase {
private let eventStore = EKEventStore() private let eventStore = EKEventStore()
@ -12,7 +12,7 @@ class EventInfoTests: XCTestCase {
let mockEvent = EKEvent(eventStore: eventStore) let mockEvent = EKEvent(eventStore: eventStore)
mockEvent.title = "Mock Title" mockEvent.title = "Mock Title"
mockEvent.startDate = Date().add(futureChunk) mockEvent.startDate = Date().add(futureChunk)
let mockEventInfo = EventInfo(event: mockEvent, let mockEventInfo = EventInfo(event: mockEvent,
isAllDay: false, isAllDay: false,
meetingURL: nil, meetingURL: nil,
@ -20,13 +20,13 @@ class EventInfoTests: XCTestCase {
XCTAssert(mockEventInfo.metadataForMeeting() == "in 5m", XCTAssert(mockEventInfo.metadataForMeeting() == "in 5m",
"Metadata for meeting: \(mockEventInfo.metadataForMeeting()) doesn't match expectation") "Metadata for meeting: \(mockEventInfo.metadataForMeeting()) doesn't match expectation")
} }
func testMetadataForUpcomingEventHappeningInTenSeconds() throws { func testMetadataForUpcomingEventHappeningInTenSeconds() throws {
let futureChunk = TimeChunk(seconds: 10, minutes: 0, hours: 0, days: 0, weeks: 0, months: 0, years: 0) let futureChunk = TimeChunk(seconds: 10, minutes: 0, hours: 0, days: 0, weeks: 0, months: 0, years: 0)
let mockEvent = EKEvent(eventStore: eventStore) let mockEvent = EKEvent(eventStore: eventStore)
mockEvent.title = "Mock Title" mockEvent.title = "Mock Title"
mockEvent.startDate = Date().add(futureChunk) mockEvent.startDate = Date().add(futureChunk)
let mockEventInfo = EventInfo(event: mockEvent, let mockEventInfo = EventInfo(event: mockEvent,
isAllDay: false, isAllDay: false,
meetingURL: nil, meetingURL: nil,
@ -40,7 +40,7 @@ class EventInfoTests: XCTestCase {
let mockEvent = EKEvent(eventStore: eventStore) let mockEvent = EKEvent(eventStore: eventStore)
mockEvent.title = "Mock Title" mockEvent.title = "Mock Title"
mockEvent.startDate = Date().subtract(pastChunk) mockEvent.startDate = Date().subtract(pastChunk)
let mockEventInfo = EventInfo(event: mockEvent, let mockEventInfo = EventInfo(event: mockEvent,
isAllDay: false, isAllDay: false,
meetingURL: nil, meetingURL: nil,
@ -48,13 +48,13 @@ class EventInfoTests: XCTestCase {
XCTAssert(mockEventInfo.metadataForMeeting() == "started +2m.", XCTAssert(mockEventInfo.metadataForMeeting() == "started +2m.",
"Metadata for meeting: \(mockEventInfo.metadataForMeeting()) doesn't match expectation") "Metadata for meeting: \(mockEventInfo.metadataForMeeting()) doesn't match expectation")
} }
func testMetadataForEventPastTenMinutes() throws { func testMetadataForEventPastTenMinutes() throws {
let pastChunk = TimeChunk(seconds: 10, minutes: 10, hours: 0, days: 0, weeks: 0, months: 0, years: 0) let pastChunk = TimeChunk(seconds: 10, minutes: 10, hours: 0, days: 0, weeks: 0, months: 0, years: 0)
let mockEvent = EKEvent(eventStore: eventStore) let mockEvent = EKEvent(eventStore: eventStore)
mockEvent.title = "Mock Title" mockEvent.title = "Mock Title"
mockEvent.startDate = Date().subtract(pastChunk) mockEvent.startDate = Date().subtract(pastChunk)
let mockEventInfo = EventInfo(event: mockEvent, let mockEventInfo = EventInfo(event: mockEvent,
isAllDay: false, isAllDay: false,
meetingURL: nil, meetingURL: nil,
@ -62,13 +62,13 @@ class EventInfoTests: XCTestCase {
XCTAssert(mockEventInfo.metadataForMeeting() == "Error", XCTAssert(mockEventInfo.metadataForMeeting() == "Error",
"Metadata for meeting: \(mockEventInfo.metadataForMeeting()) doesn't match expectation") "Metadata for meeting: \(mockEventInfo.metadataForMeeting()) doesn't match expectation")
} }
func testMetadataForEventHappeningTomorrow() throws { func testMetadataForEventHappeningTomorrow() throws {
let pastChunk = TimeChunk(seconds: 10, minutes: 0, hours: 25, days: 0, weeks: 0, months: 0, years: 0) let pastChunk = TimeChunk(seconds: 10, minutes: 0, hours: 25, days: 0, weeks: 0, months: 0, years: 0)
let mockEvent = EKEvent(eventStore: eventStore) let mockEvent = EKEvent(eventStore: eventStore)
mockEvent.title = "Mock Title" mockEvent.title = "Mock Title"
mockEvent.startDate = Date().add(pastChunk) mockEvent.startDate = Date().add(pastChunk)
let mockEventInfo = EventInfo(event: mockEvent, let mockEventInfo = EventInfo(event: mockEvent,
isAllDay: false, isAllDay: false,
meetingURL: nil, meetingURL: nil,
@ -76,5 +76,4 @@ class EventInfoTests: XCTestCase {
XCTAssert(mockEventInfo.metadataForMeeting() == "in 25h", XCTAssert(mockEventInfo.metadataForMeeting() == "in 25h",
"Metadata for meeting: \(mockEventInfo.metadataForMeeting()) doesn't match expectation") "Metadata for meeting: \(mockEventInfo.metadataForMeeting()) doesn't match expectation")
} }
} }

39
Clocker/ClockerUnitTests/StandardMenubarHandlerTests.swift

@ -1,14 +1,14 @@
// Copyright © 2015 Abhishek Banthia // Copyright © 2015 Abhishek Banthia
import CoreModelKit import CoreModelKit
import XCTest
import EventKit import EventKit
import XCTest
@testable import Clocker @testable import Clocker
class StandardMenubarHandlerTests: XCTestCase { class StandardMenubarHandlerTests: XCTestCase {
private let eventStore = EKEventStore() private let eventStore = EKEventStore()
private let mumbai = ["customLabel": "Ghar", private let mumbai = ["customLabel": "Ghar",
"formattedAddress": "Mumbai", "formattedAddress": "Mumbai",
"place_id": "ChIJwe1EZjDG5zsRaYxkjY_tpF0", "place_id": "ChIJwe1EZjDG5zsRaYxkjY_tpF0",
@ -116,73 +116,68 @@ class StandardMenubarHandlerTests: XCTestCase {
let menubarHandler = MenubarTitleProvider(with: store) let menubarHandler = MenubarTitleProvider(with: store)
XCTAssertNotNil(menubarHandler.titleForMenubar()) XCTAssertNotNil(menubarHandler.titleForMenubar())
} }
func testFormattedUpcomingEvent() { func testFormattedUpcomingEvent() {
let store = makeMockStore() let store = makeMockStore()
let futureChunk = TimeChunk(seconds: 10, minutes: 10, hours: 0, days: 0, weeks: 0, months: 0, years: 0) let futureChunk = TimeChunk(seconds: 10, minutes: 10, hours: 0, days: 0, weeks: 0, months: 0, years: 0)
let mockEvent = EKEvent(eventStore: eventStore) let mockEvent = EKEvent(eventStore: eventStore)
mockEvent.title = "Mock Title" mockEvent.title = "Mock Title"
mockEvent.startDate = Date().add(futureChunk) mockEvent.startDate = Date().add(futureChunk)
let menubarHandler = MenubarTitleProvider(with: store) let menubarHandler = MenubarTitleProvider(with: store)
XCTAssert(menubarHandler.format(event: mockEvent) == "Mock Title in 10m", XCTAssert(menubarHandler.format(event: mockEvent) == "Mock Title in 10m",
"Suffix \(menubarHandler.format(event: mockEvent)) doesn't match expectation") "Suffix \(menubarHandler.format(event: mockEvent)) doesn't match expectation")
} }
func testUpcomingEventHappeningWithinOneMinute() { func testUpcomingEventHappeningWithinOneMinute() {
let store = makeMockStore() let store = makeMockStore()
let futureChunk = TimeChunk(seconds: 10, minutes: 1, hours: 0, days: 0, weeks: 0, months: 0, years: 0) let futureChunk = TimeChunk(seconds: 10, minutes: 1, hours: 0, days: 0, weeks: 0, months: 0, years: 0)
let mockEvent = EKEvent(eventStore: eventStore) let mockEvent = EKEvent(eventStore: eventStore)
mockEvent.title = "Mock Title" mockEvent.title = "Mock Title"
mockEvent.startDate = Date().add(futureChunk) mockEvent.startDate = Date().add(futureChunk)
let menubarHandler = MenubarTitleProvider(with: store) let menubarHandler = MenubarTitleProvider(with: store)
XCTAssert(menubarHandler.format(event: mockEvent) == "Mock Title in 1m", XCTAssert(menubarHandler.format(event: mockEvent) == "Mock Title in 1m",
"Suffix \(menubarHandler.format(event: mockEvent)) doesn't match expectation") "Suffix \(menubarHandler.format(event: mockEvent)) doesn't match expectation")
} }
func testUpcomingEventHappeningWithinSeconds() { func testUpcomingEventHappeningWithinSeconds() {
let store = makeMockStore() let store = makeMockStore()
let futureChunk = TimeChunk(seconds: 10, minutes: 0, hours: 0, days: 0, weeks: 0, months: 0, years: 0) let futureChunk = TimeChunk(seconds: 10, minutes: 0, hours: 0, days: 0, weeks: 0, months: 0, years: 0)
let mockEvent = EKEvent(eventStore: eventStore) let mockEvent = EKEvent(eventStore: eventStore)
mockEvent.title = "Mock Title" mockEvent.title = "Mock Title"
mockEvent.startDate = Date().add(futureChunk) mockEvent.startDate = Date().add(futureChunk)
let menubarHandler = MenubarTitleProvider(with: store) let menubarHandler = MenubarTitleProvider(with: store)
XCTAssert(menubarHandler.format(event: mockEvent) == "Mock Title starts now.", XCTAssert(menubarHandler.format(event: mockEvent) == "Mock Title starts now.",
"Suffix \(menubarHandler.format(event: mockEvent)) doesn't match expectation") "Suffix \(menubarHandler.format(event: mockEvent)) doesn't match expectation")
} }
func testEmptyUpcomingEvent() { func testEmptyUpcomingEvent() {
let store = makeMockStore() let store = makeMockStore()
let futureChunk = TimeChunk(seconds: 10, minutes: 0, hours: 0, days: 0, weeks: 0, months: 0, years: 0) let futureChunk = TimeChunk(seconds: 10, minutes: 0, hours: 0, days: 0, weeks: 0, months: 0, years: 0)
let mockEvent = EKEvent(eventStore: eventStore) let mockEvent = EKEvent(eventStore: eventStore)
mockEvent.startDate = Date().add(futureChunk) mockEvent.startDate = Date().add(futureChunk)
let menubarHandler = MenubarTitleProvider(with: store) let menubarHandler = MenubarTitleProvider(with: store)
XCTAssert(menubarHandler.format(event: mockEvent) == CLEmptyString, XCTAssert(menubarHandler.format(event: mockEvent) == CLEmptyString,
"Suffix \(menubarHandler.format(event: mockEvent)) doesn't match expectation") "Suffix \(menubarHandler.format(event: mockEvent)) doesn't match expectation")
} }
func testLongUpcomingEvent() { func testLongUpcomingEvent() {
let store = makeMockStore() let store = makeMockStore()
let futureChunk = TimeChunk(seconds: 10, minutes: 0, hours: 0, days: 0, weeks: 0, months: 0, years: 0) let futureChunk = TimeChunk(seconds: 10, minutes: 0, hours: 0, days: 0, weeks: 0, months: 0, years: 0)
let mockEvent = EKEvent(eventStore: eventStore) let mockEvent = EKEvent(eventStore: eventStore)
mockEvent.title = "Really long calendar event title that longer than the longest name" mockEvent.title = "Really long calendar event title that longer than the longest name"
mockEvent.startDate = Date().add(futureChunk) mockEvent.startDate = Date().add(futureChunk)
let menubarHandler = MenubarTitleProvider(with: store) let menubarHandler = MenubarTitleProvider(with: store)
XCTAssert(menubarHandler.format(event: mockEvent) == "Really long calendar event tit... starts now.", XCTAssert(menubarHandler.format(event: mockEvent) == "Really long calendar event tit... starts now.",
"Suffix \(menubarHandler.format(event: mockEvent)) doesn't match expectation") "Suffix \(menubarHandler.format(event: mockEvent)) doesn't match expectation")
} }
} }

2
Clocker/Onboarding/OnboardingParentViewController.swift

@ -223,7 +223,7 @@ class OnboardingParentViewController: NSViewController {
if ProcessInfo.processInfo.arguments.contains(CLOnboaringTestsLaunchArgument) == false { if ProcessInfo.processInfo.arguments.contains(CLOnboaringTestsLaunchArgument) == false {
UserDefaults.standard.set(true, forKey: CLShowOnboardingFlow) UserDefaults.standard.set(true, forKey: CLShowOnboardingFlow)
} }
// Install the menubar option! // Install the menubar option!
let appDelegate = NSApplication.shared.delegate as? AppDelegate let appDelegate = NSApplication.shared.delegate as? AppDelegate
appDelegate?.continueUsually() appDelegate?.continueUsually()

6
Clocker/Onboarding/OnboardingSearchController.swift

@ -40,7 +40,7 @@ class OnboardingSearchController: NSViewController {
super.viewDidLoad() super.viewDidLoad()
view.wantsLayer = true view.wantsLayer = true
resultsTableView.isHidden = true resultsTableView.isHidden = true
resultsTableView.delegate = self resultsTableView.delegate = self
resultsTableView.setAccessibility("ResultsTableView") resultsTableView.setAccessibility("ResultsTableView")
@ -69,12 +69,12 @@ class OnboardingSearchController: NSViewController {
setupUndoButton() setupUndoButton()
} }
override func viewWillAppear() { override func viewWillAppear() {
super.viewWillAppear() super.viewWillAppear()
searchResultsDataSource = SearchDataSource(with: searchBar, location: .onboarding) searchResultsDataSource = SearchDataSource(with: searchBar, location: .onboarding)
} }
override func viewWillDisappear() { override func viewWillDisappear() {
super.viewWillDisappear() super.viewWillDisappear()
searchResultsDataSource = nil searchResultsDataSource = nil

2
Clocker/Overall App/AppKit + Additions.swift

@ -21,7 +21,7 @@ extension NSTextField {
} }
extension NSFont { extension NSFont {
func size(_ string: String, _ width: Double, attributes: [NSAttributedString.Key: AnyObject]) -> CGSize { func size(for string: String, width: Double, attributes: [NSAttributedString.Key: AnyObject]) -> CGSize {
let size = CGSize(width: width, let size = CGSize(width: width,
height: Double.greatestFiniteMagnitude) height: Double.greatestFiniteMagnitude)

4
Clocker/Overall App/DataStore.swift

@ -71,11 +71,11 @@ class DataStore: NSObject {
let cloudTimezones = ubiquitousStore?.object(forKey: CLDefaultPreferenceKey) as? [Data] let cloudTimezones = ubiquitousStore?.object(forKey: CLDefaultPreferenceKey) as? [Data]
let cloudLastUpdateDate = (ubiquitousStore?.object(forKey: CLUbiquitousStoreLastUpdateKey) as? Date) ?? Date() let cloudLastUpdateDate = (ubiquitousStore?.object(forKey: CLUbiquitousStoreLastUpdateKey) as? Date) ?? Date()
let defaultsLastUpdateDate = (ubiquitousStore?.object(forKey: CLUserDefaultsLastUpdateKey) as? Date) ?? Date() let defaultsLastUpdateDate = (ubiquitousStore?.object(forKey: CLUserDefaultsLastUpdateKey) as? Date) ?? Date()
if cloudTimezones == currentTimezones { if cloudTimezones == currentTimezones {
Logger.info("Ubiquitous Store timezones aren't equal to current timezones") Logger.info("Ubiquitous Store timezones aren't equal to current timezones")
} }
if defaultsLastUpdateDate.isLaterThanOrEqual(to: cloudLastUpdateDate) { if defaultsLastUpdateDate.isLaterThanOrEqual(to: cloudLastUpdateDate) {
Logger.info("Ubiquitous Store is stale as compared to User Defaults") Logger.info("Ubiquitous Store is stale as compared to User Defaults")
} }

2
Clocker/Panel/PanelController.swift

@ -74,7 +74,7 @@ class PanelController: ParentPanelController {
super.dismissRowActions() super.dismissRowActions()
updateDefaultPreferences() updateDefaultPreferences()
setupUpcomingEventViewCollectionViewIfNeccesary() setupUpcomingEventViewCollectionViewIfNeccesary()
if DataStore.shared().timezones().isEmpty || DataStore.shared().shouldDisplay(.futureSlider) == false { if DataStore.shared().timezones().isEmpty || DataStore.shared().shouldDisplay(.futureSlider) == false {

2
Clocker/Panel/ParentPanelController.swift

@ -1151,7 +1151,7 @@ extension ParentPanelController: AppFeedbackWindowControllerDelegate {
func appFeedbackWindowWillClose() { func appFeedbackWindowWillClose() {
feedbackWindow = nil feedbackWindow = nil
} }
func appFeedbackWindoEntryPoint() -> String { func appFeedbackWindoEntryPoint() -> String {
return "parent_panel_controller" return "parent_panel_controller"
} }

2
Clocker/Preferences/About/AboutViewController.swift

@ -157,7 +157,7 @@ extension AboutViewController: AppFeedbackWindowControllerDelegate {
func appFeedbackWindowWillClose() { func appFeedbackWindowWillClose() {
feedbackWindow = nil feedbackWindow = nil
} }
func appFeedbackWindoEntryPoint() -> String { func appFeedbackWindoEntryPoint() -> String {
return "about_view_controller" return "about_view_controller"
} }

4
Clocker/Preferences/App Feedback/AppFeedbackWindowController.swift

@ -210,7 +210,7 @@ class AppFeedbackWindowController: NSWindowController {
AppFeedbackConstants.CLClockerVersion: versionInfo, AppFeedbackConstants.CLClockerVersion: versionInfo,
AppFeedbackConstants.CLAppFeedbackDateProperty: todaysDate(), AppFeedbackConstants.CLAppFeedbackDateProperty: todaysDate(),
AppFeedbackConstants.CLAppFeedbackUserPreferences: generateUserPreferences(), AppFeedbackConstants.CLAppFeedbackUserPreferences: generateUserPreferences(),
AppFeedbackConstants.CLFeedbackEntryPoint: appFeedbackWindowDelegate?.appFeedbackWindoEntryPoint() ?? "Error" AppFeedbackConstants.CLFeedbackEntryPoint: appFeedbackWindowDelegate?.appFeedbackWindoEntryPoint() ?? "Error",
] ]
} }
@ -228,7 +228,7 @@ class AppFeedbackWindowController: NSWindowController {
#if DEBUG #if DEBUG
Logger.info("Sending a feedback in Debug builds will lead to a no-op") Logger.info("Sending a feedback in Debug builds will lead to a no-op")
#endif #endif
guard let identifier = serialNumber else { guard let identifier = serialNumber else {
assertionFailure("Serial Identifier was unexpectedly nil") assertionFailure("Serial Identifier was unexpectedly nil")
return return

Loading…
Cancel
Save