-
Notifications
You must be signed in to change notification settings - Fork 121
[Woo POS] Coupons: Provide coupons to ItemList (happy path) #15417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4889ffa
fetch coupons and provide to ItemList
iamgabrielma c7e078c
Merge branch 'trunk' into task/15416-pos-provide-coupons-to-ui
iamgabrielma 3119db1
Render coupons with CouponRowView
iamgabrielma 0d53ccc
loadFirstPage of coupons on happy path
iamgabrielma 1c9aac6
initial happy-path PointOfSaleCouponsControllerTests
iamgabrielma 55b90c1
tests happy path for refreshitems, loadnextitems
iamgabrielma 38b15ce
lint
iamgabrielma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
137 changes: 137 additions & 0 deletions
137
WooCommerce/WooCommerceTests/POS/Controllers/PointOfSaleCouponsControllerTests.swift
This file contains hidden or 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,137 @@ | ||
| @testable import WooCommerce | ||
| import Testing | ||
| import Foundation | ||
|
|
||
| import protocol Yosemite.PointOfSaleItemServiceProtocol | ||
| import enum Yosemite.POSItem | ||
| import struct Yosemite.POSCoupon | ||
| import struct Yosemite.PagedItems | ||
| import struct Yosemite.POSVariableParentProduct | ||
|
|
||
| final class MockPointOfSaleCouponService: PointOfSaleItemServiceProtocol { | ||
| var shouldReturnZeroItems = false | ||
|
|
||
| func providePointOfSaleItems(pageNumber: Int) async throws -> PagedItems<POSItem> { | ||
| if shouldReturnZeroItems { | ||
| return .init(items: [], hasMorePages: false) | ||
| } else { | ||
| return .init(items: Self.makeInitialCoupons(), | ||
| hasMorePages: false) | ||
| } | ||
| } | ||
|
|
||
| func providePointOfSaleVariationItems(for parentProduct: POSVariableParentProduct, pageNumber: Int) async throws -> PagedItems<POSItem> { | ||
| return .init(items: [], hasMorePages: false) | ||
| } | ||
|
|
||
| static func makeInitialCoupons() -> [POSItem] { | ||
| let coupon1 = POSItem.coupon(POSCoupon(id: UUID(uuidString: ("DC55E3B9-9D83-4C07-82A7-4C300A50E84A")) ?? UUID(), code: "VALID1")) | ||
| let coupon2 = POSItem.coupon(POSCoupon(id: UUID(uuidString: ("DC55E3B9-9D83-4C07-82A7-4C300A50E84B")) ?? UUID(), code: "VALID2")) | ||
| let coupon3 = POSItem.coupon(POSCoupon(id: UUID(uuidString: ("DC55E3B9-9D83-4C07-82A7-4C300A50E84C")) ?? UUID(), code: "VALID3")) | ||
| return [coupon1, coupon2, coupon3] | ||
| } | ||
| } | ||
|
|
||
| struct PointOfSaleCouponsControllerTests { | ||
| @available(iOS 17.0, *) | ||
| @Test func loadItems_when_empty_coupons_then_results_in_empty_loaded_state() async throws { | ||
| // Given | ||
| let couponProvider = MockPointOfSaleCouponService() | ||
| couponProvider.shouldReturnZeroItems = true | ||
| let sut = PointOfSaleCouponsController(itemProvider: couponProvider) | ||
|
|
||
| let expectedItemStackState = ItemsStackState(root: .loaded([], hasMoreItems: false), itemStates: [:]) | ||
| let expectedViewState = ItemsViewState(containerState: .content, itemsStack: expectedItemStackState) | ||
|
|
||
| // When | ||
| await sut.loadItems(base: .root) | ||
|
|
||
| // Then | ||
| #expect(sut.itemsViewState == expectedViewState) | ||
| } | ||
|
|
||
| @available(iOS 17.0, *) | ||
| @Test func loadItems_when_some_coupons_then_results_in_coupons_loaded_state() async throws { | ||
| // Given | ||
| let couponProvider = MockPointOfSaleCouponService() | ||
| let expectedCoupons = MockPointOfSaleCouponService.makeInitialCoupons() | ||
| let sut = PointOfSaleCouponsController(itemProvider: couponProvider) | ||
|
|
||
| let expectedItemStackState = ItemsStackState(root: .loaded(expectedCoupons, hasMoreItems: false), itemStates: [:]) | ||
| let expectedViewState = ItemsViewState(containerState: .content, itemsStack: expectedItemStackState) | ||
|
|
||
| // When | ||
| await sut.loadItems(base: .root) | ||
|
|
||
| // Then | ||
| #expect(sut.itemsViewState == expectedViewState) | ||
| } | ||
|
|
||
| @available(iOS 17.0, *) | ||
| @Test func refreshItems_when_empty_coupons_then_results_in_empty_loaded_state() async throws { | ||
| // Given | ||
| let couponProvider = MockPointOfSaleCouponService() | ||
| couponProvider.shouldReturnZeroItems = true | ||
| let sut = PointOfSaleCouponsController(itemProvider: couponProvider) | ||
|
|
||
| let expectedItemStackState = ItemsStackState(root: .loaded([], hasMoreItems: false), itemStates: [:]) | ||
| let expectedViewState = ItemsViewState(containerState: .content, itemsStack: expectedItemStackState) | ||
|
|
||
| // When | ||
| await sut.refreshItems(base: .root) | ||
|
|
||
| // Then | ||
| #expect(sut.itemsViewState == expectedViewState) | ||
| } | ||
|
|
||
| @available(iOS 17.0, *) | ||
| @Test func refreshItems_when_some_coupons_then_results_in_coupons_loaded_state() async throws { | ||
| // Given | ||
| let couponProvider = MockPointOfSaleCouponService() | ||
| let expectedCoupons = MockPointOfSaleCouponService.makeInitialCoupons() | ||
| let sut = PointOfSaleCouponsController(itemProvider: couponProvider) | ||
|
|
||
| let expectedItemStackState = ItemsStackState(root: .loaded(expectedCoupons, hasMoreItems: false), itemStates: [:]) | ||
| let expectedViewState = ItemsViewState(containerState: .content, itemsStack: expectedItemStackState) | ||
|
|
||
| // When | ||
| await sut.refreshItems(base: .root) | ||
|
|
||
| // Then | ||
| #expect(sut.itemsViewState == expectedViewState) | ||
| } | ||
|
|
||
| @available(iOS 17.0, *) | ||
| @Test func loadNextItems_when_empty_coupons_then_results_in_empty_loaded_state() async throws { | ||
| // Given | ||
| let couponProvider = MockPointOfSaleCouponService() | ||
| couponProvider.shouldReturnZeroItems = true | ||
| let sut = PointOfSaleCouponsController(itemProvider: couponProvider) | ||
|
|
||
| let expectedItemStackState = ItemsStackState(root: .loaded([], hasMoreItems: false), itemStates: [:]) | ||
| let expectedViewState = ItemsViewState(containerState: .content, itemsStack: expectedItemStackState) | ||
|
|
||
| // When | ||
| await sut.loadNextItems(base: .root) | ||
|
|
||
| // Then | ||
| #expect(sut.itemsViewState == expectedViewState) | ||
| } | ||
|
|
||
| @available(iOS 17.0, *) | ||
| @Test func loadNextItems_when_some_coupons_then_results_in_coupons_loaded_state() async throws { | ||
| // Given | ||
| let couponProvider = MockPointOfSaleCouponService() | ||
| let expectedCoupons = MockPointOfSaleCouponService.makeInitialCoupons() | ||
| let sut = PointOfSaleCouponsController(itemProvider: couponProvider) | ||
|
|
||
| let expectedItemStackState = ItemsStackState(root: .loaded(expectedCoupons, hasMoreItems: false), itemStates: [:]) | ||
| let expectedViewState = ItemsViewState(containerState: .content, itemsStack: expectedItemStackState) | ||
|
|
||
| // When | ||
| await sut.loadNextItems(base: .root) | ||
|
|
||
| // Then | ||
| #expect(sut.itemsViewState == expectedViewState) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Great to see both list and cart functionality integrating so easily 👍