|
| 1 | +import XCTest |
| 2 | + |
| 3 | +@testable import BitwardenShared |
| 4 | + |
| 5 | +class VaultListSectionTests: BitwardenTestCase { |
| 6 | + // MARK: Tests |
| 7 | + |
| 8 | + /// `hasLoginItems` returns `false` if there's no login items within the sections. |
| 9 | + func test_vaultListSectionArray_hasLoginItems_false() { |
| 10 | + let subjectEmpty = [VaultListSection]() |
| 11 | + XCTAssertFalse(subjectEmpty.hasLoginItems) |
| 12 | + |
| 13 | + let subjectWithoutLogin = [ |
| 14 | + VaultListSection(id: "2", items: [.fixtureGroup(group: .card, count: 2)], name: "Cards"), |
| 15 | + VaultListSection(id: "3", items: [.fixtureGroup(group: .identity, count: 3)], name: "Identities"), |
| 16 | + VaultListSection(id: "4", items: [.fixtureGroup(group: .secureNote, count: 0)], name: "Notes"), |
| 17 | + ] |
| 18 | + XCTAssertFalse(subjectWithoutLogin.hasLoginItems) |
| 19 | + |
| 20 | + let subjectLoginsEmpty = [ |
| 21 | + VaultListSection(id: "1", items: [.fixtureGroup(group: .login, count: 0)], name: "Logins"), |
| 22 | + VaultListSection(id: "2", items: [.fixtureGroup(group: .card, count: 2)], name: "Cards"), |
| 23 | + VaultListSection(id: "3", items: [.fixtureGroup(group: .identity, count: 3)], name: "Identities"), |
| 24 | + VaultListSection(id: "4", items: [.fixtureGroup(group: .secureNote, count: 0)], name: "Notes"), |
| 25 | + ] |
| 26 | + XCTAssertFalse(subjectLoginsEmpty.hasLoginItems) |
| 27 | + |
| 28 | + let subjectCiphersNoLogins = [ |
| 29 | + VaultListSection(id: "5", items: [.fixture(cipherView: .fixture(type: .identity))], name: "Items"), |
| 30 | + ] |
| 31 | + XCTAssertFalse(subjectCiphersNoLogins.hasLoginItems) |
| 32 | + } |
| 33 | + |
| 34 | + /// `hasLoginItems` returns `true` if there's a login group with more than one item or a login |
| 35 | + /// cipher within the sections. |
| 36 | + func test_vaultListSectionArray_hasLoginItems_true() { |
| 37 | + let subjectWithLogin = [ |
| 38 | + VaultListSection(id: "1", items: [.fixtureGroup(group: .login, count: 1)], name: "Logins"), |
| 39 | + ] |
| 40 | + XCTAssertTrue(subjectWithLogin.hasLoginItems) |
| 41 | + |
| 42 | + let subjectWithMultipleSections = [ |
| 43 | + VaultListSection(id: "1", items: [.fixtureGroup(group: .login, count: 1)], name: "Logins"), |
| 44 | + VaultListSection(id: "2", items: [.fixtureGroup(group: .card, count: 2)], name: "Cards"), |
| 45 | + VaultListSection(id: "3", items: [.fixtureGroup(group: .identity, count: 3)], name: "Identities"), |
| 46 | + VaultListSection(id: "4", items: [.fixtureGroup(group: .secureNote, count: 0)], name: "Notes"), |
| 47 | + ] |
| 48 | + XCTAssertTrue(subjectWithMultipleSections.hasLoginItems) |
| 49 | + |
| 50 | + let subjectWithCipher = [ |
| 51 | + VaultListSection(id: "2", items: [.fixtureGroup(group: .card, count: 2)], name: "Cards"), |
| 52 | + VaultListSection(id: "5", items: [.fixture(cipherView: .fixture(type: .login))], name: "Items"), |
| 53 | + ] |
| 54 | + XCTAssertTrue(subjectWithCipher.hasLoginItems) |
| 55 | + |
| 56 | + let subjectWithTOTP = [ |
| 57 | + VaultListSection(id: "1", items: [.fixtureTOTP(totp: .fixture())], name: "TOTP"), |
| 58 | + ] |
| 59 | + XCTAssertTrue(subjectWithTOTP.hasLoginItems) |
| 60 | + |
| 61 | + let subjectWithTOTPGroup = [ |
| 62 | + VaultListSection(id: "2", items: [.fixtureGroup(group: .totp, count: 2)], name: "TOTP"), |
| 63 | + ] |
| 64 | + XCTAssertTrue(subjectWithTOTPGroup.hasLoginItems) |
| 65 | + } |
| 66 | +} |
0 commit comments