-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid rendering trailing spaces for 6-digit codes (#85)
- Loading branch information
1 parent
edff0c7
commit f1dc721
Showing
16 changed files
with
191 additions
and
1 deletion.
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
24 changes: 24 additions & 0 deletions
24
AuthenticatorShared/Core/Vault/Services/TOTP/TOTPCodeModelTests.swift
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,24 @@ | ||
import Foundation | ||
import XCTest | ||
|
||
@testable import AuthenticatorShared | ||
|
||
final class TOTPCodeModelTests: AuthenticatorTestCase { | ||
// MARK: Tests | ||
|
||
/// `displayCode` groups digits correctly | ||
func test_displayCode_spaces() { | ||
XCTAssertEqual(model(for: "12345").displayCode, "123 45") | ||
XCTAssertEqual(model(for: "123456").displayCode, "123 456") | ||
XCTAssertEqual(model(for: "1234567").displayCode, "123 456 7") | ||
XCTAssertEqual(model(for: "12345678").displayCode, "123 456 78") | ||
XCTAssertEqual(model(for: "123456789").displayCode, "123 456 789") | ||
XCTAssertEqual(model(for: "1234567890").displayCode, "123 456 789 0") | ||
} | ||
|
||
// MARK: Private Methods | ||
|
||
func model(for code: String) -> TOTPCodeModel { | ||
TOTPCodeModel(code: code, codeGenerationDate: Date(), period: 30) | ||
} | ||
} |
106 changes: 106 additions & 0 deletions
106
AuthenticatorShared/UI/Vault/ItemList/ItemList/ItemListSection+Fixtures.swift
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,106 @@ | ||
import Foundation | ||
|
||
#if DEBUG | ||
|
||
extension ItemListSection { | ||
static func digitsFixture(accountNames: Bool = false) -> ItemListSection { // swiftlint:disable:this function_body_length line_length | ||
ItemListSection( | ||
id: "Digits", | ||
items: [ | ||
ItemListItem( | ||
id: "5", | ||
name: "Five", | ||
accountName: accountNames ? "[email protected]" : nil, | ||
itemType: .totp( | ||
model: ItemListTotpItem( | ||
itemView: .fixture(), | ||
totpCode: TOTPCodeModel( | ||
code: "12345", | ||
codeGenerationDate: Date(), | ||
period: 30 | ||
) | ||
) | ||
) | ||
), | ||
ItemListItem( | ||
id: "6", | ||
name: "Six", | ||
accountName: accountNames ? "[email protected]" : nil, | ||
itemType: .totp( | ||
model: ItemListTotpItem( | ||
itemView: .fixture(), | ||
totpCode: TOTPCodeModel( | ||
code: "123456", | ||
codeGenerationDate: Date(), | ||
period: 30 | ||
) | ||
) | ||
) | ||
), | ||
ItemListItem( | ||
id: "7", | ||
name: "Seven", | ||
accountName: accountNames ? "[email protected]" : nil, | ||
itemType: .totp( | ||
model: ItemListTotpItem( | ||
itemView: .fixture(), | ||
totpCode: TOTPCodeModel( | ||
code: "1234567", | ||
codeGenerationDate: Date(), | ||
period: 30 | ||
) | ||
) | ||
) | ||
), | ||
ItemListItem( | ||
id: "8", | ||
name: "Eight", | ||
accountName: accountNames ? "[email protected]" : nil, | ||
itemType: .totp( | ||
model: ItemListTotpItem( | ||
itemView: .fixture(), | ||
totpCode: TOTPCodeModel( | ||
code: "12345678", | ||
codeGenerationDate: Date(), | ||
period: 30 | ||
) | ||
) | ||
) | ||
), | ||
ItemListItem( | ||
id: "9", | ||
name: "Nine", | ||
accountName: accountNames ? "[email protected]" : nil, | ||
itemType: .totp( | ||
model: ItemListTotpItem( | ||
itemView: .fixture(), | ||
totpCode: TOTPCodeModel( | ||
code: "123456789", | ||
codeGenerationDate: Date(), | ||
period: 30 | ||
) | ||
) | ||
) | ||
), | ||
ItemListItem( | ||
id: "10", | ||
name: "Ten", | ||
accountName: accountNames ? "[email protected]" : nil, | ||
itemType: .totp( | ||
model: ItemListTotpItem( | ||
itemView: .fixture(), | ||
totpCode: TOTPCodeModel( | ||
code: "1234567890", | ||
codeGenerationDate: Date(), | ||
period: 30 | ||
) | ||
) | ||
) | ||
), | ||
], | ||
name: "Digits" | ||
) | ||
} | ||
} | ||
|
||
#endif |
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
Binary file modified
BIN
+15 Bytes
(100%)
...mListViewTests/test_snapshot_ItemListView_previews.1-Search-Result-portrait.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-9 Bytes
(100%)
...tViewTests/test_snapshot_ItemListView_previews.1-Search-Result-portraitDark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-38 Bytes
(100%)
...ListViewTests/test_snapshot_ItemListView_previews.3-Search-Results-portrait.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-48 Bytes
(100%)
...ViewTests/test_snapshot_ItemListView_previews.3-Search-Results-portraitDark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+209 KB
...ots__/ItemListViewTests/test_snapshot_ItemListView_previews.Digits-portrait.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+216 KB
...__/ItemListViewTests/test_snapshot_ItemListView_previews.Digits-portraitAX5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+213 KB
..._/ItemListViewTests/test_snapshot_ItemListView_previews.Digits-portraitDark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-45 Bytes
(100%)
...tViewTests/test_snapshot_ItemListView_previews.Items-with-Favorite-portrait.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1 Byte
(100%)
...wTests/test_snapshot_ItemListView_previews.Items-with-Favorite-portraitDark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-149 Bytes
(100%)
...ewTests/test_snapshot_ItemListView_previews.Items-without-Favorite-portrait.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+49 Bytes
(100%)
...sts/test_snapshot_ItemListView_previews.Items-without-Favorite-portraitDark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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