-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2387 from minvws/chore/5641-pdf-flow-tests
- Loading branch information
Showing
8 changed files
with
455 additions
and
3 deletions.
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
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
150 changes: 150 additions & 0 deletions
150
CTRTests/Interface/Coordinators/PDFExportCoordinatorTests.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,150 @@ | ||
/* | ||
* Copyright (c) 2022 De Staat der Nederlanden, Ministerie van Volksgezondheid, Welzijn en Sport. | ||
* Licensed under the EUROPEAN UNION PUBLIC LICENCE v. 1.2 | ||
* | ||
* SPDX-License-Identifier: EUPL-1.2 | ||
*/ | ||
|
||
import XCTest | ||
@testable import CTR | ||
import Nimble | ||
@testable import Models | ||
@testable import Transport | ||
@testable import Resources | ||
@testable import ReusableViews | ||
|
||
class PDFExportCoordinatorTests: XCTestCase { | ||
|
||
var sut: PDFExportCoordinator! | ||
var navigationSpy: NavigationControllerSpy! | ||
var delegateSpy: PDFExportFlowDelegateSpy! | ||
|
||
override func setUp() { | ||
|
||
super.setUp() | ||
|
||
navigationSpy = NavigationControllerSpy() | ||
delegateSpy = PDFExportFlowDelegateSpy() | ||
_ = setupEnvironmentSpies() | ||
sut = PDFExportCoordinator(navigationController: navigationSpy, delegate: delegateSpy) | ||
} | ||
|
||
// MARK: - Tests | ||
|
||
func test_start() { | ||
|
||
// Given | ||
|
||
// When | ||
sut.start() | ||
|
||
// Then | ||
expect(self.navigationSpy.viewControllers).to(haveCount(1)) | ||
expect(self.navigationSpy.viewControllers.last is PagedAnnouncementViewController) == true | ||
expect(self.delegateSpy.invokedExportFailed) == false | ||
expect(self.delegateSpy.invokedExportCompleted) == false | ||
} | ||
|
||
func test_consumeLink() { | ||
|
||
// Given | ||
let universalLink = UniversalLink.redeemHolderToken(requestToken: RequestToken( | ||
token: "STXT2VF3389TJ2", | ||
protocolVersion: "3.0", | ||
providerIdentifier: "XXX" | ||
)) | ||
|
||
// When | ||
let result = sut.consume(universalLink: universalLink) | ||
|
||
// Then | ||
expect(result) == false | ||
} | ||
|
||
func test_userWishesToStart() { | ||
|
||
// Given | ||
|
||
// When | ||
sut.userWishesToStart() | ||
|
||
// Then | ||
expect(self.navigationSpy.viewControllers).to(haveCount(1)) | ||
expect(self.navigationSpy.viewControllers.last is PagedAnnouncementViewController) == true | ||
expect(self.delegateSpy.invokedExportFailed) == false | ||
expect(self.delegateSpy.invokedExportCompleted) == false | ||
} | ||
|
||
func test_userWishesToExport() { | ||
|
||
// Given | ||
|
||
// When | ||
sut.userWishesToExport() | ||
|
||
// Then | ||
expect(self.navigationSpy.viewControllers).to(haveCount(1)) | ||
expect(self.navigationSpy.viewControllers.last is PDFExportViewController) == true | ||
expect(self.delegateSpy.invokedExportFailed) == false | ||
expect(self.delegateSpy.invokedExportCompleted) == false | ||
} | ||
|
||
func test_displayError() throws { | ||
|
||
// Given | ||
let content = Content( | ||
title: L.generalNetworkwasbusyTitle() | ||
) | ||
|
||
// When | ||
sut.displayError(content: content) | ||
|
||
// Then | ||
expect(self.navigationSpy.pushViewControllerCallCount) == 1 | ||
expect(self.navigationSpy.viewControllers.last is ContentViewController) == true | ||
let viewModel = try XCTUnwrap( (self.navigationSpy.viewControllers.last as? ContentViewController)?.viewModel) | ||
expect(viewModel.content.title) == L.generalNetworkwasbusyTitle() | ||
expect(self.delegateSpy.invokedExportFailed) == false | ||
expect(self.delegateSpy.invokedExportCompleted) == false | ||
} | ||
|
||
func test_share() throws { | ||
|
||
// Given | ||
let url = try XCTUnwrap(URL(string: "https://apple.com")) | ||
|
||
// When | ||
sut.userWishesToShare(url) | ||
|
||
// Then | ||
expect(self.navigationSpy.invokedPresent) == true | ||
expect(self.delegateSpy.invokedExportFailed) == false | ||
expect(self.delegateSpy.invokedExportCompleted) == false | ||
} | ||
|
||
func test_exportFailed() { | ||
|
||
// Given | ||
|
||
// When | ||
sut.exportFailed() | ||
|
||
// Then | ||
expect(self.delegateSpy.invokedExportCompleted) == false | ||
expect(self.delegateSpy.invokedExportFailed) == true | ||
} | ||
|
||
func test_didFinishPagedAnnouncement() { | ||
|
||
// Given | ||
|
||
// When | ||
sut.didFinishPagedAnnouncement() | ||
|
||
// Then | ||
expect(self.navigationSpy.viewControllers).to(haveCount(1)) | ||
expect(self.navigationSpy.viewControllers.last is PDFExportViewController) == true | ||
expect(self.delegateSpy.invokedExportFailed) == false | ||
expect(self.delegateSpy.invokedExportCompleted) == false | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
CTRTests/Interface/Holder/PDF/Export/ExportPDFViewModelTests.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,118 @@ | ||
/* | ||
* Copyright (c) 2023 De Staat der Nederlanden, Ministerie van Volksgezondheid, Welzijn en Sport. | ||
* Licensed under the EUROPEAN UNION PUBLIC LICENCE v. 1.2 | ||
* | ||
* SPDX-License-Identifier: EUPL-1.2 | ||
*/ | ||
|
||
import XCTest | ||
import Nimble | ||
@testable import CTR | ||
@testable import Transport | ||
@testable import Shared | ||
import TestingShared | ||
import Persistence | ||
@testable import Models | ||
@testable import Managers | ||
@testable import Resources | ||
import WebKit | ||
|
||
final class ExportPDFViewModelTests: XCTestCase { | ||
|
||
private var sut: PDFExportViewModel! | ||
private var environmentSpies: EnvironmentSpies! | ||
private var coordinatorSpy: PDFExportCoordinatorSpy! | ||
|
||
override func setUp() { | ||
super.setUp() | ||
|
||
environmentSpies = setupEnvironmentSpies() | ||
coordinatorSpy = PDFExportCoordinatorSpy() | ||
|
||
sut = PDFExportViewModel(coordinator: coordinatorSpy) | ||
} | ||
|
||
func test_openUrl() throws { | ||
|
||
// Given | ||
let url = try XCTUnwrap(URL(string: "https://apple.com")) | ||
|
||
// When | ||
sut.openUrl(url) | ||
|
||
// Then | ||
expect(self.coordinatorSpy.invokedOpenUrl) == true | ||
expect(self.coordinatorSpy.invokedOpenUrlParameters?.0) == url | ||
} | ||
|
||
func test_openPDF() { | ||
|
||
// Given | ||
expect(self.sut.previewURL.value) == nil | ||
|
||
// When | ||
sut.openPDF() | ||
|
||
// Then | ||
expect(self.sut.previewURL.value) != nil | ||
} | ||
|
||
func test_sharePDF() { | ||
|
||
// Given | ||
|
||
// When | ||
sut.sharePDF() | ||
|
||
// Then | ||
expect(self.coordinatorSpy.invokedUserWishesToShare) == true | ||
} | ||
|
||
func to_be_fixed_test_test_viewDidAppear() { | ||
|
||
// Given | ||
environmentSpies.contactInformationSpy.stubbedPhoneNumberLink = "PHONENUMBER" | ||
|
||
// When | ||
sut.viewDidAppear() | ||
|
||
// Then | ||
expect(self.coordinatorSpy.invokedDisplayError) == true | ||
expect(self.coordinatorSpy.invokedDisplayErrorParameters?.content.body) == L.holder_pdfExport_error_body("PHONENUMBER", "i 1510 000 121") // Can't load file (config) | ||
expect(self.sut.html.value) == nil | ||
} | ||
|
||
func to_be_fixed_test_viewDidAppear_withConfig() throws { | ||
|
||
// Given | ||
environmentSpies.contactInformationSpy.stubbedPhoneNumberLink = "PHONENUMBER" | ||
environmentSpies.cryptoLibUtilitySpy.stubbedReadResult = try XCTUnwrap( JSONEncoder().encode(environmentSpies.remoteConfigManagerSpy.stubbedStoredConfiguration) | ||
) | ||
|
||
// When | ||
sut.viewDidAppear() | ||
|
||
// Then | ||
expect(self.coordinatorSpy.invokedDisplayError) == true | ||
expect(self.coordinatorSpy.invokedDisplayErrorParameters?.content.body) == L.holder_pdfExport_error_body("PHONENUMBER", "i 1510 000 124") // No DCC's | ||
expect(self.sut.html.value) == nil | ||
} | ||
|
||
func to_be_fixed_test_viewDidAppear_withConfig_withDCC() throws { | ||
|
||
// Given | ||
environmentSpies.contactInformationSpy.stubbedPhoneNumberLink = "PHONENUMBER" | ||
environmentSpies.cryptoLibUtilitySpy.stubbedReadResult = try XCTUnwrap( JSONEncoder().encode(environmentSpies.remoteConfigManagerSpy.stubbedStoredConfiguration) | ||
) | ||
let greencards = GreenCard.sampleInternationalMultipleVaccineDCC(dataStoreManager: environmentSpies.dataStoreManager) | ||
environmentSpies.walletManagerSpy.stubbedListGreenCardsResult = greencards | ||
environmentSpies.cryptoManagerSpy.stubbedReadEuCredentialsResult = EuCredentialAttributes.fakeVaccination() | ||
|
||
// When | ||
sut.viewDidAppear() | ||
|
||
// Then | ||
expect(self.coordinatorSpy.invokedDisplayError) == false | ||
expect(self.sut.html.value) != nil | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
CTRTests/Interface/Holder/PDF/Start/StartPDFExportFactoryTests.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,31 @@ | ||
/* | ||
* Copyright (c) 2023 De Staat der Nederlanden, Ministerie van Volksgezondheid, Welzijn en Sport. | ||
* Licensed under the EUROPEAN UNION PUBLIC LICENCE v. 1.2 | ||
* | ||
* SPDX-License-Identifier: EUPL-1.2 | ||
*/ | ||
|
||
import Nimble | ||
import XCTest | ||
@testable import CTR | ||
import Resources | ||
|
||
final class StartPDFExportFactoryTests: XCTestCase { | ||
|
||
var sut: StartPDFExportFactory! | ||
|
||
func test_getExportInstructions() { | ||
|
||
// Given | ||
sut = StartPDFExportFactory() | ||
|
||
// When | ||
let pages = sut.getExportInstructions() | ||
|
||
// Then | ||
expect(pages).to(haveCount(1)) | ||
expect(pages.first?.title) == L.holder_pdfExport_start_title() | ||
expect(pages.first?.content) == L.holder_pdfExport_start_message() | ||
expect(pages.first?.nextButtonTitle) == L.holder_pdfExport_start_buttonTitle() | ||
} | ||
} |
Oops, something went wrong.