Skip to content

Commit

Permalink
added snapthost testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ezimet-livefront committed Jan 15, 2025
1 parent aa27099 commit 5c6dbb1
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class BitwardenSliderTests: BitwardenTestCase {
func test_snapshot_slider_minValue() {
let subject = BitwardenSlider(
value: .constant(0),
in: 0...50,
in: 0 ... 50,
step: 1,
onEditingChanged: { _ in }
)
Expand All @@ -26,7 +26,7 @@ class BitwardenSliderTests: BitwardenTestCase {
func test_snapshot_slider_midValue() {
let subject = BitwardenSlider(
value: .constant(25),
in: 0...50,
in: 0 ... 50,
step: 1,
onEditingChanged: { _ in }
)
Expand All @@ -40,7 +40,7 @@ class BitwardenSliderTests: BitwardenTestCase {
func test_snapshot_slider_maxValue() {
let subject = BitwardenSlider(
value: .constant(50),
in: 0...50,
in: 0 ... 50,
step: 1,
onEditingChanged: { _ in }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ final class GeneratorProcessor: StateProcessor<GeneratorState, GeneratorAction,
await checkLearnGeneratorActionCardEligibility()
case .dismissLearnGeneratorActionCard:
await services.stateService.setLearnGeneratorActionCardStatus(.complete)
state.isLearnGeneratorActionCardEligible = false
case .showLearnGeneratorGuidedTour:
await services.stateService.setLearnGeneratorActionCardStatus(.complete)
state.isLearnGeneratorActionCardEligible = false
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,44 @@ import XCTest
class GeneratorProcessorTests: BitwardenTestCase { // swiftlint:disable:this type_body_length
// MARK: Properties

var configService: MockConfigService!
var coordinator: MockCoordinator<GeneratorRoute, Void>!
var errorReporter: MockErrorReporter!
var generatorRepository: MockGeneratorRepository!
var pasteboardService: MockPasteboardService!
var policyService: MockPolicyService!
var reviewPromptService: MockReviewPromptService!
var stateService: MockStateService!
var subject: GeneratorProcessor!

// MARK: Setup & Teardown

override func setUp() {
super.setUp()

configService = MockConfigService()
coordinator = MockCoordinator()
errorReporter = MockErrorReporter()
generatorRepository = MockGeneratorRepository()
pasteboardService = MockPasteboardService()
policyService = MockPolicyService()
reviewPromptService = MockReviewPromptService()
stateService = MockStateService()

setUpSubject()
}

override func tearDown() {
super.tearDown()

configService = nil
coordinator = nil
errorReporter = nil
generatorRepository = nil
pasteboardService = nil
policyService = nil
reviewPromptService = nil
stateService = nil
subject = nil
}

Expand All @@ -49,11 +55,13 @@ class GeneratorProcessorTests: BitwardenTestCase { // swiftlint:disable:this typ
subject = GeneratorProcessor(
coordinator: coordinator.asAnyCoordinator(),
services: ServiceContainer.withMocks(
configService: configService,
errorReporter: errorReporter,
generatorRepository: generatorRepository,
pasteboardService: pasteboardService,
policyService: policyService,
reviewPromptService: reviewPromptService
reviewPromptService: reviewPromptService,
stateService: stateService
),
state: GeneratorState()
)
Expand Down Expand Up @@ -376,30 +384,6 @@ class GeneratorProcessorTests: BitwardenTestCase { // swiftlint:disable:this typ
)
}

/// Tapping the dismiss button in the learn generator action card sends the
/// `.dismissLearnGeneratorActionCard` effect.
@MainActor
func test_learnGeneratorActionCard_visible_tapDismiss() async throws {
processor.state.isLearnGeneratorActionCardEligible = true
let actionCard = try subject.inspect().find(actionCard: Localizations.exploreTheGenerator)

let button = try actionCard.find(asyncButton: Localizations.dismiss)
try await button.tap()
XCTAssertEqual(processor.effects, [.dismissLearnGeneratorActionCard])
}

/// Tapping the 'Get started' button in the learn generator action card sends the
/// `.showLearnNewLoginGuidedTour` effect.
@MainActor
func test_learnGeneratorActionCard_visible_tapGetStarted() async throws {
processor.state.isLearnGeneratorActionCardEligible = true
let actionCard = try subject.inspect().find(actionCard: Localizations.exploreTheGenerator)

let button = try actionCard.find(asyncButton: Localizations.getStarted)
try await button.tap()
XCTAssertEqual(processor.effects, [.showLearnGeneratorGuidedTour])
}

/// `perform(_:)` with `.appeared` generates a new generated value.
@MainActor
func test_perform_appear_generatesValue() {
Expand Down Expand Up @@ -431,6 +415,39 @@ class GeneratorProcessorTests: BitwardenTestCase { // swiftlint:disable:this typ
XCTAssertEqual(generatorRepository.passwordGeneratorRequest?.length, 50)
}

/// `perform(:)` with `.appeared` should set the `isLearnGeneratorActionCardEligible` to `true`
/// if the `learnGeneratorActionCardStatus` is `incomplete`, and feature flag is enabled.
@MainActor
func test_perform_checkLearnNewLoginActionCardEligibility() async {
configService.featureFlagsBool[.nativeCreateAccountFlow] = true
stateService.learnGeneratorActionCardStatus = .incomplete
setUpSubject()
await subject.perform(.appeared)
XCTAssertTrue(subject.state.isLearnGeneratorActionCardEligible)
}

/// `perform(:)` with `.appeared` should not set the `isLearnNewLoginActionCardEligible` to `true`
/// if the feature flag `nativeCreateAccountFlow` is `false`.
@MainActor
func test_perform_checkLearnNewLoginActionCardEligibility_false() async {
configService.featureFlagsBool[.nativeCreateAccountFlow] = false
stateService.learnGeneratorActionCardStatus = .incomplete
setUpSubject()
await subject.perform(.appeared)
XCTAssertFalse(subject.state.isLearnGeneratorActionCardEligible)
}

/// `perform(:)` with `.appeared` should not set the `isLearnNewLoginActionCardEligible` to `true`
/// if the `learnGeneratorActionCardStatus` is `complete`.
@MainActor
func test_perform_checkLearnNewLoginActionCardEligibility_false_complete() async {
configService.featureFlagsBool[.nativeCreateAccountFlow] = true
stateService.learnGeneratorActionCardStatus = .complete
setUpSubject()
await subject.perform(.appeared)
XCTAssertFalse(subject.state.isLearnGeneratorActionCardEligible)
}

/// `receive(_:)` with `.copyGeneratedValØue` copies the generated password to the system
/// pasteboard and shows a toast.
@MainActor
Expand Down Expand Up @@ -483,6 +500,26 @@ class GeneratorProcessorTests: BitwardenTestCase { // swiftlint:disable:this typ
XCTAssertEqual(coordinator.routes.last, .cancel)
}

/// `perform(_:)` with `.dismissNewLoginActionCard` will set `.isLearnGeneratorActionCardEligible` to
/// false and updates `.learnGeneratorActionCardStatus` via stateService.
@MainActor
func test_perform_dismissLearnGeneratorActionCard() async {
subject.state.isLearnGeneratorActionCardEligible = true
await subject.perform(.dismissLearnGeneratorActionCard)
XCTAssertFalse(subject.state.isLearnGeneratorActionCardEligible)
XCTAssertEqual(stateService.learnGeneratorActionCardStatus, .complete)
}

/// `perform(_:)` with `.showLearnGeneratorGuidedTour` sets `isLearnGeneratorActionCardEligible`
/// to `false`.
@MainActor
func test_perform_showLearnNewLoginGuidedTour() async {
subject.state.isLearnGeneratorActionCardEligible = true
await subject.perform(.showLearnGeneratorGuidedTour)
XCTAssertFalse(subject.state.isLearnGeneratorActionCardEligible)
XCTAssertEqual(stateService.learnGeneratorActionCardStatus, .complete)
}

/// `receive(_:)` with `.emailTypeChanged` updates the state's catch all email type.
@MainActor
func test_receive_emailTypeChanged_catchAll() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,30 @@ class GeneratorViewTests: BitwardenTestCase {
XCTAssertEqual(processor.dispatchedActions.last, .refreshGeneratedValue)
}

/// Tapping the dismiss button in the learn generator action card sends the
/// `.dismissLearnGeneratorActionCard` effect.
@MainActor
func test_learnGeneratorActionCard_visible_tapDismiss() async throws {
processor.state.isLearnGeneratorActionCardEligible = true
let actionCard = try subject.inspect().find(actionCard: Localizations.exploreTheGenerator)

let button = try actionCard.find(asyncButton: Localizations.dismiss)
try await button.tap()
XCTAssertEqual(processor.effects, [.dismissLearnGeneratorActionCard])
}

/// Tapping the 'Get started' button in the learn generator action card sends the
/// `.showLearnNewLoginGuidedTour` effect.
@MainActor
func test_learnGeneratorActionCard_visible_tapGetStarted() async throws {
processor.state.isLearnGeneratorActionCardEligible = true
let actionCard = try subject.inspect().find(actionCard: Localizations.exploreTheGenerator)

let button = try actionCard.find(asyncButton: Localizations.getStarted)
try await button.tap()
XCTAssertEqual(processor.effects, [.showLearnGeneratorGuidedTour])
}

/// Updating the email type dispatches the `.emailTypeChanged` action.
@MainActor
func test_menuEmailTypeChanged() throws {
Expand Down Expand Up @@ -295,4 +319,14 @@ class GeneratorViewTests: BitwardenTestCase {
as: .defaultPortrait
)
}

/// Tests the snapshot with the add state with the learn generator action card.
@MainActor
func test_snapshot_generatorView_learnGeneratorActionCard() throws {
processor.state.isLearnGeneratorActionCardEligible = true
assertSnapshots(
of: subject,
as: [.defaultPortrait, .defaultPortraitDark]
)
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5c6dbb1

Please sign in to comment.