Skip to content

Commit

Permalink
Merge pull request #2387 from minvws/chore/5641-pdf-flow-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rool authored Jun 20, 2023
2 parents fe752b6 + 75c00e7 commit 57e0875
Show file tree
Hide file tree
Showing 8 changed files with 455 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,40 @@ extension HolderCoordinatorTests {
expect(self.sut.childCoordinators).to(beEmpty())
expect(self.navigationSpy.viewControllers.last is HolderDashboardViewController) == true
}

// MARK: - PDFExportFlowDelegate

func test_pdfExport_completed() {

// Given
sut.childCoordinators = [
PDFExportCoordinator(
navigationController: navigationSpy,
delegate: sut
)
]

// When
sut.exportCompleted()

// Then
expect(self.sut.childCoordinators).to(beEmpty())
}

func test_pdfExport_failed() {

// Given
sut.childCoordinators = [
PDFExportCoordinator(
navigationController: navigationSpy,
delegate: sut
)
]

// When
sut.exportFailed()

// Then
expect(self.sut.childCoordinators).to(beEmpty())
}
}
12 changes: 12 additions & 0 deletions CTRTests/Interface/Coordinators/HolderCoordinatorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -826,4 +826,16 @@ class HolderCoordinatorTests: XCTestCase {
expect(self.environmentSpies.walletManagerSpy.invokedRemoveExistingBlockedEvents) == true
expect(self.environmentSpies.walletManagerSpy.invokedRemoveExistingMismatchedIdentityEvents) == true
}

func test_userWishesToExportPDF() {

// Given

// When
sut.userWishesToExportPDF()

// Then
expect(self.sut.childCoordinators).toNot(beEmpty())
expect(self.sut.childCoordinators.first is PDFExportCoordinator) == true
}
}
150 changes: 150 additions & 0 deletions CTRTests/Interface/Coordinators/PDFExportCoordinatorTests.swift
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 CTRTests/Interface/Holder/PDF/Export/ExportPDFViewModelTests.swift
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
}
}
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()
}
}
Loading

0 comments on commit 57e0875

Please sign in to comment.