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