diff --git a/Calendr.xcodeproj/project.pbxproj b/Calendr.xcodeproj/project.pbxproj index e518beab..bb8bbbd1 100644 --- a/Calendr.xcodeproj/project.pbxproj +++ b/Calendr.xcodeproj/project.pbxproj @@ -1101,7 +1101,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); - MARKETING_VERSION = 1.4.1; + MARKETING_VERSION = 1.4.2; PRODUCT_BUNDLE_IDENTIFIER = br.paker.Calendr; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Calendr/Config/Calendr-Bridging-Header.h"; @@ -1125,7 +1125,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); - MARKETING_VERSION = 1.4.1; + MARKETING_VERSION = 1.4.2; PRODUCT_BUNDLE_IDENTIFIER = br.paker.Calendr; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Calendr/Config/Calendr-Bridging-Header.h"; diff --git a/Calendr/Events/EventViewModel.swift b/Calendr/Events/EventViewModel.swift index d3a53954..c407a5e6 100644 --- a/Calendr/Events/EventViewModel.swift +++ b/Calendr/Events/EventViewModel.swift @@ -66,8 +66,10 @@ class EventViewModel { let url = linkURL?.absoluteString - subtitle = (event.location ?? url ?? event.notes)? - .replacingOccurrences(of: "https://", with: "") + subtitle = [event.location, url, event.notes] + .lazy + .compactMap { $0?.replacingOccurrences(of: "https://", with: "").trimmed } + .first(where: \.isEmpty.isFalse)? .prefix(while: \.isNewline.isFalse) .trimmed ?? "" diff --git a/CalendrTests/EventViewModelTests.swift b/CalendrTests/EventViewModelTests.swift index 41de6e81..650dc300 100644 --- a/CalendrTests/EventViewModelTests.swift +++ b/CalendrTests/EventViewModelTests.swift @@ -29,6 +29,42 @@ class EventViewModelTests: XCTestCase { XCTAssertEqual(viewModel.isPending, true) } + func testSubtitle_withExtraSpacesInLocation_withURLInLocation_shouldShowTrimmedLocation() { + + let viewModel = mock( + event: .make(location: " \n Location https://someurl.com ") + ) + + XCTAssertEqual(viewModel.subtitle, "Location someurl.com") + } + + func testSubtitle_withExtraSpacesInLocation_withURLInLocation_shouldShowURL() { + + let viewModel = mock( + event: .make(location: " \n https://someurl.com ") + ) + + XCTAssertEqual(viewModel.subtitle, "someurl.com") + } + + func testSubtitle_withEmptyLocation_withURL_shouldShowURL() { + + let viewModel = mock( + event: .make(location: " ", url: URL(string: "https://someurl.com")!) + ) + + XCTAssertEqual(viewModel.subtitle, "someurl.com") + } + + func testSubtitle_withEmptyLocation_withURLInNotes_shouldShowURL() { + + let viewModel = mock( + event: .make(location: " ", notes: " \nSome \nnotes https://someurl.com ") + ) + + XCTAssertEqual(viewModel.subtitle, "someurl.com") + } + func testSubtitle_withLocation_withoutURL_shouldShowLocation() { let viewModel = mock( @@ -65,7 +101,7 @@ class EventViewModelTests: XCTestCase { XCTAssertEqual(viewModel.subtitle, "Some address") } - func testSubtitle_withoutLocation_withoutURL_withUrlInNotes_shouldShowURL() { + func testSubtitle_withoutLocation_withoutURL_withURLInNotes_shouldShowURL() { let viewModel = mock( event: .make(notes: "Some notes https://someurl.com")