Skip to content

Commit

Permalink
Fix layout issue due to faulty event subtitle trimming (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
pakerwreah committed Feb 22, 2022
1 parent df674ab commit a96c76a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Calendr.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
Expand Down
6 changes: 4 additions & 2 deletions Calendr/Events/EventViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? ""

Expand Down
38 changes: 37 additions & 1 deletion CalendrTests/EventViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit a96c76a

Please sign in to comment.