-
Notifications
You must be signed in to change notification settings - Fork 234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update CalendarViewContent closures to accept nil return values #269
Merged
bryankeller
merged 2 commits into
airbnb:master
from
calda:cal--optional-closure-return-values
Sep 19, 2023
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// 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 | ||
} | ||
} | ||
|
||
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)) | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid having to change any of the existing call sites, we can have the instance properties still always return a non-nil value, even if the user-provided closure returns nil. An easy way to do this is to just fall back to the existing default item provider, which always returns a valid value.