-
Notifications
You must be signed in to change notification settings - Fork 121
Customer search: Fill customer fields on Order screen #7885
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
Changes from 10 commits
5869ec0
d7060dc
e05a33d
db2fb24
5419298
fae8db5
dff4aed
64cb6fe
c5fbc90
1733984
9cf8388
ed04317
5dffa97
7b58531
121ba8a
d343863
2b772b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import XCTest | ||
| @testable import WooCommerce | ||
| import Yosemite | ||
|
|
||
| final class CustomerSearchUICommandTests: XCTestCase { | ||
| private let sampleSiteID: Int64 = 123 | ||
|
|
||
| override func setUp() { | ||
| super.setUp() | ||
| } | ||
|
|
||
| override func tearDown() { | ||
| super.tearDown() | ||
| } | ||
|
||
|
|
||
| func test_searchResultsPredicate_includes_siteID_and_keyword_when_keyword() { | ||
| // Given | ||
| let command = CustomerSearchUICommand(siteID: sampleSiteID) { _ in } | ||
|
|
||
| // When | ||
| let predicate = command.searchResultsPredicate(keyword: "some") | ||
| let expectedQuery = "siteID == 123 AND ANY searchResults.keyword == \"some\"" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Double check if this actually filters down multiple sites.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confirmed 👍 , for 2 customers with the same name and customer ID, in two different sites, only one is shown. |
||
|
|
||
| // Then | ||
| XCTAssertEqual(predicate?.predicateFormat, expectedQuery) | ||
| } | ||
|
|
||
| func test_cellViewModel_display_correct_customer_details() { | ||
| let command = CustomerSearchUICommand(siteID: sampleSiteID) { _ in } | ||
| let customer = Customer( | ||
| siteID: sampleSiteID, | ||
| customerID: 1, | ||
| email: "[email protected]", | ||
| firstName: "John", | ||
| lastName: "W", | ||
| billing: nil, | ||
| shipping: nil | ||
| ) | ||
|
|
||
| let cellViewModel = command.createCellViewModel(model: customer) | ||
|
|
||
| XCTAssertEqual(cellViewModel.id, String(customer.customerID)) | ||
| XCTAssertEqual(cellViewModel.title, "\(customer.firstName ?? "") \(customer.lastName ?? "")") | ||
| XCTAssertEqual(cellViewModel.subtitle, String(customer.email)) | ||
| } | ||
| } | ||
iamgabrielma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -184,4 +184,23 @@ final class CustomerStoreTests: XCTestCase { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| XCTAssertEqual(storedCustomer?.customerID, dummyCustomerID) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| XCTAssertEqual(storedCustomer?.firstName, "John") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func test_searchCustomers_returns_no_customers_when_customer_is_not_registered() throws { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Given | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let customerID = 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| network.simulateResponse(requestUrlSuffix: "customers", filename: "wc-analytics-customers") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| network.simulateResponse(requestUrlSuffix: "customers/\(customerID)", filename: "customer") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // When | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let response: Result<[Networking.Customer], Error> = waitFor { promise in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let action = CustomerAction.searchCustomers(siteID: self.dummySiteID, keyword: self.dummyKeyword) { result in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| promise(result) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.dispatcher.dispatch(action) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let customers = try response.get() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| XCTAssertEqual(customers.count, 0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice test! This is business logic which is well worth checking. However... it doesn't really test what it looks like. I had a go at making it fail (by removing the The reason is that we don't have anyone in We can improve it further though... here's another way to do it, which more directly checks that the request is not sent, without needing to see what the customer response is: (N.B. This still needs an analytics customer with
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh that's nice! Made the changes on 7b58531 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
This can move to the view model too if you like? Can wait for a future PR