-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from designatednerd/main
Looks good, thank you!
- Loading branch information
Showing
5 changed files
with
119 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
Tests/DoNilDisturbPluginTests/DoNotDisturbPluginTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import XCTest | ||
import Foundation | ||
import iCalendar | ||
|
||
@testable import PluginBinary | ||
|
||
final class DoNotDisturbPluginTests: XCTestCase { | ||
|
||
func testHolidayLoad() throws { | ||
let date = Foundation.Calendar.current.date(from: DateComponents(year: 2022, month: 8, day: 30, hour: 13))! | ||
let calendarFileURL = try XCTUnwrap(Bundle.module.url(forResource: "TestCal", withExtension: "ics", subdirectory: "Resources")) | ||
let icalContents = try String(contentsOf: calendarFileURL) | ||
let parseResult = Parser.parse(ics: icalContents) | ||
switch parseResult { | ||
case .success(let calendar): | ||
let content = PluginBinary.content(for: date, holidayCalendars: [calendar]) | ||
XCTAssertEqual(content, | ||
""" | ||
#error("Do not disturb is ON") | ||
#warning("It is The Feast of Maximum Occupancy") | ||
""") | ||
case .failure(let error): | ||
XCTFail(error.localizedDescription) | ||
} | ||
} | ||
|
||
func testWeekendError() throws { | ||
let sunday = Calendar.current.date(from: DateComponents(year: 2022, month: 08, day: 28))! | ||
|
||
let content = PluginBinary.content(for: sunday, holidayCalendars: []) | ||
XCTAssertEqual(content, | ||
""" | ||
#error("Do not disturb is ON") | ||
#warning("It's the weekend") | ||
""") | ||
} | ||
|
||
func test2amError() { | ||
var calendar = Foundation.Calendar.current | ||
|
||
// Prevents errors when the calendar is in a different locale | ||
calendar.locale = Locale(identifier: "en-US") | ||
|
||
let monday2am = calendar.date(from: DateComponents(year: 2022, month: 08, day: 29, hour: 2))! | ||
|
||
let content = PluginBinary.content(for: monday2am, | ||
holidayCalendars: [], | ||
systemCalendar: calendar) | ||
XCTAssertEqual(content, | ||
""" | ||
#error("Do not disturb is ON") | ||
#warning("It's 2:00 AM") | ||
""") | ||
} | ||
|
||
func testWorkTime() { | ||
let monday2pm = Calendar.current.date(from: DateComponents(year: 2022, month: 08, day: 29, hour: 14))! | ||
let content = PluginBinary.content(for: monday2pm, holidayCalendars: []) | ||
XCTAssertEqual(content, "// All is good, do not disturb is off.") | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
BEGIN:VCALENDAR | ||
METHOD:PUBLISH | ||
VERSION:2.0 | ||
X-WR-CALNAME:TestCal | ||
PRODID:-//Apple Inc.//macOS 12.5.1//EN | ||
X-APPLE-CALENDAR-COLOR:#0E61B9 | ||
X-WR-TIMEZONE:America/Denver | ||
CALSCALE:GREGORIAN | ||
BEGIN:VEVENT | ||
CREATED:20220829T020826Z | ||
UID:413F797E-DA05-4920-AF63-D6A2E2D5CDC8 | ||
DTSTART;VALUE=DATE:20220830 | ||
DTEND;VALUE=DATE:20220831 | ||
TRANSP:TRANSPARENT | ||
X-APPLE-TRAVEL-ADVISORY-BEHAVIOR:AUTOMATIC | ||
SUMMARY:The Feast of Maximum Occupancy | ||
LAST-MODIFIED:20220829T020840Z | ||
DTSTAMP:20220829T020840Z | ||
SEQUENCE:1 | ||
END:VEVENT | ||
END:VCALENDAR |
This file was deleted.
Oops, something went wrong.