-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update CalendarViewContent closures to accept nil values
- Loading branch information
Showing
4 changed files
with
197 additions
and
64 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Created by Cal Stephens on 9/18/23. | ||
// Copyright © 2023 Airbnb Inc. All rights reserved. | ||
|
||
@testable import HorizonCalendar | ||
import XCTest | ||
|
||
final class CalendarContentTests: XCTestCase { | ||
|
||
func testCanReturnNilFromCalendarContentClosures() { | ||
_ = CalendarViewContent( | ||
visibleDateRange: Date.distantPast...Date.distantFuture, | ||
monthsLayout: .vertical) | ||
.monthHeaderItemProvider { _ in | ||
nil | ||
} | ||
.dayOfWeekItemProvider { _, _ in | ||
nil | ||
} | ||
.dayItemProvider { _ in | ||
nil | ||
} | ||
.dayBackgroundItemProvider { _ in | ||
nil | ||
} | ||
.dayRangeItemProvider(for: Set([Date.distantPast...Date.distantFuture])) { _ in | ||
nil | ||
} | ||
.overlayItemProvider(for: Set([.day(containingDate: .distantPast)])) { _ in | ||
nil | ||
} | ||
} | ||
|
||
func testNilDayItemUsesDefaultValue() { | ||
let content = CalendarViewContent( | ||
visibleDateRange: Date.distantPast...Date.distantFuture, | ||
monthsLayout: .vertical) | ||
|
||
let day = Day(month: Month(era: 1, year: 2023, month: 1, isInGregorianCalendar: true), day: 1) | ||
let defaultDayItem = content.dayItemProvider(day) | ||
|
||
let contentWithNilDayItem = content.dayItemProvider { _ in nil } | ||
let updatedDayItem = contentWithNilDayItem.dayItemProvider(day) | ||
|
||
XCTAssert(defaultDayItem._isContentEqual(toContentOf: updatedDayItem)) | ||
} | ||
|
||
func testNilDayOfWeekItemUsesDefaultValue() { | ||
let content = CalendarViewContent( | ||
visibleDateRange: Date.distantPast...Date.distantFuture, | ||
monthsLayout: .vertical) | ||
|
||
let month = Month(era: 1, year: 2023, month: 1, isInGregorianCalendar: true) | ||
let defaultDayOfWeekItem = content.dayOfWeekItemProvider(month, 1) | ||
|
||
let contentWithNilDayOfWeekItem = content.dayOfWeekItemProvider { _, _ in nil } | ||
let updatedDayOfWeekItem = contentWithNilDayOfWeekItem.dayOfWeekItemProvider(month, 1) | ||
|
||
XCTAssert(defaultDayOfWeekItem._isContentEqual(toContentOf: updatedDayOfWeekItem)) | ||
} | ||
|
||
func testNilMonthHeaderItemUsesDefaultValue() { | ||
let content = CalendarViewContent( | ||
visibleDateRange: Date.distantPast...Date.distantFuture, | ||
monthsLayout: .vertical) | ||
|
||
let month = Month(era: 1, year: 2023, month: 1, isInGregorianCalendar: true) | ||
let defaultMonthHeaderItem = content.monthHeaderItemProvider(month) | ||
|
||
let contentWithNilMonthHeaderItem = content.monthHeaderItemProvider { _ in nil } | ||
let updatedMonthHeaderItem = contentWithNilMonthHeaderItem.monthHeaderItemProvider(month) | ||
|
||
XCTAssert(defaultMonthHeaderItem._isContentEqual(toContentOf: updatedMonthHeaderItem)) | ||
} | ||
|
||
} |