Skip to content
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

Fix crash: duplicate items when rendering payment methods list #1840

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Adyen.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@
B62D48C52BBE8F3B001EF01A /* XCTestCase+Wait.swift in Sources */ = {isa = PBXBuildFile; fileRef = B62D48C22BBE8ED6001EF01A /* XCTestCase+Wait.swift */; };
B62D48C62BBE8F45001EF01A /* XCTestCase+Wait.swift in Sources */ = {isa = PBXBuildFile; fileRef = B62D48C22BBE8ED6001EF01A /* XCTestCase+Wait.swift */; };
B62D48C82BBE8F47001EF01A /* XCTestCase+Wait.swift in Sources */ = {isa = PBXBuildFile; fileRef = B62D48C22BBE8ED6001EF01A /* XCTestCase+Wait.swift */; };
B6ABA1C32CA6B058003514E5 /* ListItemTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6ABA1C22CA6B058003514E5 /* ListItemTests.swift */; };
B6D808032BCD140E00F3F5EB /* AssetsAccessTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F91760A62594C5DF00D653BE /* AssetsAccessTests.swift */; };
B6D808042BCD147600F3F5EB /* UILabelHelpersTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AD40F42263150F90090E01C /* UILabelHelpersTests.swift */; };
B6D808052BCD147600F3F5EB /* KeyedDecodingContainerExtensionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E9021E032264C55E009CF7F4 /* KeyedDecodingContainerExtensionsTests.swift */; };
Expand Down Expand Up @@ -1785,6 +1786,7 @@
B62D48AC2BBE8D79001EF01A /* UnitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = UnitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
B62D48C22BBE8ED6001EF01A /* XCTestCase+Wait.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "XCTestCase+Wait.swift"; sourceTree = "<group>"; };
B62D48CA2BBE9059001EF01A /* UnitTests.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = UnitTests.xctestplan; sourceTree = "<group>"; };
B6ABA1C22CA6B058003514E5 /* ListItemTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListItemTests.swift; sourceTree = "<group>"; };
B6EE0F432BBEBFD000B9810D /* IntegrationTests.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = IntegrationTests.xctestplan; sourceTree = "<group>"; };
C90D26A627565750001A488F /* FormViewController+ViewProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FormViewController+ViewProtocol.swift"; sourceTree = "<group>"; };
C90D26B1275900B9001A488F /* BACSInputFormViewProtocolMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BACSInputFormViewProtocolMock.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -4527,6 +4529,7 @@
81DC5A502A73C52500DBF2D1 /* AdyenContextTests.swift */,
81FC2C922BB198AB007F1316 /* ImageLoaderTests.swift */,
81A91AB62BEBEA21001E00C8 /* OpenExternalAppDetectorTests.swift */,
B6ABA1C22CA6B058003514E5 /* ListItemTests.swift */,
);
path = Core;
sourceTree = "<group>";
Expand Down Expand Up @@ -6729,6 +6732,7 @@
B6D808322BCD1F8900F3F5EB /* BalanceCheckerTests.swift in Sources */,
B6D808192BCD151F00F3F5EB /* PaymentMethodMock.swift in Sources */,
B6D808052BCD147600F3F5EB /* KeyedDecodingContainerExtensionsTests.swift in Sources */,
B6ABA1C32CA6B058003514E5 /* ListItemTests.swift in Sources */,
B6D808092BCD147600F3F5EB /* StringExtensionsTests.swift in Sources */,
B6D808152BCD151F00F3F5EB /* AppLauncherMock.swift in Sources */,
B62D48B52BBE8DBE001EF01A /* AnalyticsEventTests.swift in Sources */,
Expand Down
10 changes: 6 additions & 4 deletions Adyen/UI/List/ListItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ public class ListItem: FormItem {

loadingHandler(isLoading, self)
}

// MARK: - Private

private let listIdentifier: UUID = .init()
}

// MARK: - Hashable & Equatable
Expand All @@ -110,12 +114,10 @@ public class ListItem: FormItem {
extension ListItem: Hashable {

public func hash(into hasher: inout Hasher) {
hasher.combine(title)
hasher.combine(icon)
hasher.combine(trailingText)
hasher.combine(listIdentifier)
}

public static func == (lhs: ListItem, rhs: ListItem) -> Bool {
lhs.title == rhs.title && lhs.icon == rhs.icon && lhs.trailingText == rhs.trailingText
lhs.listIdentifier == rhs.listIdentifier
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -457,4 +457,3 @@ extension GiftCardComponent: PartialPaymentComponent {}

@_spi(AdyenInternal)
extension GiftCardComponent: PublicKeyConsumer {}

25 changes: 25 additions & 0 deletions Tests/UnitTests/Core/ListItemTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// Copyright (c) 2024 Adyen N.V.
//
// This file is open source and available under the MIT license. See the LICENSE file for more info.
//

import XCTest
@testable @_spi(AdyenInternal) import Adyen

final class ListItemTests: XCTestCase {
// Checks COIOS-797: NSInternalInconsistencyException 1008: Item identifiers are not unique
func test_listItem_isAlwaysUnique() {
let item1 = ListItem(title: "Test title 11", icon: .dummy(), trailingText: "Text")
let item2 = ListItem(title: "Test title 11", icon: .dummy(), trailingText: "Text")

XCTAssertNotEqual(item1, item2, "Items used for UITableView sections should be unique even if visually they are identical")
XCTAssertNotEqual(item1.hashValue, item2.hashValue, "Items hashValues used for UITableViewDiffableDataSource should be unique even if visually they are identical")
}
}

private extension ListItem.Icon {
static func dummy() -> ListItem.Icon {
.init(image: UIImage.checkmark)
}
}
Loading