Skip to content
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

CIF-1398 - [My Account] Address book management #353

Merged
merged 99 commits into from
Aug 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
d419c7d
CIF-1444 - Add my account dropdown to header (#303)
Jun 24, 2020
682eab7
CIF-1444 - Add my account dropdown to header (#303)
Jun 24, 2020
5de378d
CIF-1444 - Add my account dropdown to header (#303)
Jun 24, 2020
90d658d
Merge branch 'master' into issues/CIF-1444
Jun 25, 2020
daab8b2
CIF-1444 - Add my account dropdown to header (#303)
Jun 25, 2020
5cba0c2
CIF-1444 - Add my account dropdown to header (#303)
Jun 25, 2020
26db79b
CIF-1444 - Fix prettier issue found in 'accountIconText.css' file (#303)
Jun 25, 2020
2aa4df5
Merge branch 'issues/CIF-1444' of https://github.com/adobe/aem-core-c…
Jun 25, 2020
89ebc38
CIF-1444 - Fix Java baseline check issue due to the change of interface
Jun 25, 2020
6a64f99
CIF-1444: Update translation by using npm script 'translation:scan'
Jun 25, 2020
c360d07
CIF-1444: Add new features to account dropdown (#303)
Jun 26, 2020
26494ea
CIF-1444: Add test suits for components (#303)
Jun 29, 2020
2705b21
CIF-1444: Rename '<Account>' component to '<AccountContainer>', remov…
Jun 30, 2020
460f3a5
CIF-1444: Add change password link to account dropdown (#303)
Jun 30, 2020
3578f8a
CIF-1444: Adjust layout and style of sign-in form (#303)
Jun 30, 2020
191628a
Merge branch 'master' into issues/CIF-1444
nettree Jun 30, 2020
63e2667
CIF-1444: Remove the account component definition from AEM as we're g…
Jul 1, 2020
168e89b
CIF-1444: Add test files for `<CreateAccountSuccess>` component, remo…
Jul 2, 2020
b771eec
CIF-1444: Refactor account dropdown related components, now we only c…
Jul 3, 2020
d09b112
CIF-1444: Move '<AccountTrigger>' and '<AccountDropdown>' components …
Jul 3, 2020
4ffa5e9
CIF-1444: Fix an issue that the account dropdown is closed even if th…
Jul 3, 2020
2d3b86c
Merge branch 'master' into CIF-1444
nettree Jul 6, 2020
0585974
CIF-1444: Add test for '<AccountTrigger>' component (#303)
Jul 6, 2020
4cef78b
Merge branch 'master' into CIF-1444
dplaton Jul 6, 2020
2a4afd4
CIF-1444: Add and update tests to improve test coverage (#303)
Jul 8, 2020
4722b4e
Merge branch 'CIF-1444' of https://github.com/adobe/aem-core-cif-comp…
Jul 8, 2020
e1a7b01
CIF-1444: Remove the unnecessary test for '<AccountDropdown>' (#303)
Jul 8, 2020
8b3b8bb
CIF-1444: Remove the unnessary mock from test suits (#303)
Jul 9, 2020
4b33f71
CIF-1444: Passing config object to '<CommerceApp>' (#303)
Jul 9, 2020
09f159a
Merge branch 'master' into CIF-1444
Jul 9, 2020
69d4a19
CIF-1444: Fix the format issue of 'config.js' (#303)
Jul 9, 2020
5615d75
CIF-1444: Use 'jest.spyOn' to mock 'ReactDOM.createPortal' (#303)
Jul 10, 2020
c3d4124
Merge branch 'master' into CIF-1444
Jul 10, 2020
3baa7f0
CIF-1444: Delete config.js as we will add it to Venia guides repo (#303)
Jul 10, 2020
ebd6e52
CIF-1398 - MyAccount - Address Book Page
Jul 13, 2020
95ae60d
Merge branch 'CIF-1444' into issues/CIF-1398
Jul 14, 2020
5298fe1
CIF-1398: Add and update graphql queries for address book component
Jul 20, 2020
100d9ae
CIF-1398: Remove the placeholder content from addressbook.html
Jul 20, 2020
6c2bfa9
CIF-1398: export '<AddressBook>' component so it can be used by other…
Jul 20, 2020
09e2ed8
CIF-1398: Modify the address form component so the label of submit bu…
Jul 20, 2020
aa2fc59
CIF-1398: Change the address book link in account dropdown
Jul 20, 2020
27f31f8
CIF-1398: Add translations for address book component
Jul 20, 2020
b1cb7f6
CIF-1398: Add address book related components
Jul 20, 2020
2fce367
Merge branch 'master' into issues/CIF-1398
Jul 20, 2020
1953c81
CIF-1398: Finish delete and edit address features
Jul 20, 2020
50348f2
CIF-1398: Add tranlsations for address book components
Jul 21, 2020
a0dfe34
CIF-1398: Change graphql queries for query, create, and update address
Jul 21, 2020
ae2ca0d
CIF-1398: Add deault_shipping checkbox to address form
Jul 21, 2020
85afca7
CIF-1398: Add new translation to checkout.json
Jul 21, 2020
8e5bbae
CIF-1398: Fix issues when closing address form and updating address
Jul 21, 2020
3653dac
CIF-1398: Update test of address form component to reflect the recent…
Jul 21, 2020
a03824b
CIF-1398: Change address item component to display region_code
Jul 21, 2020
2697b73
CIF-1398: Add grid CSS for address items container
Jul 21, 2020
66088c0
CIF-1398: Remove the unnecessary div from add address button component
Jul 21, 2020
819f615
CIF-1398: Add default tag for default shipping address and billing ad…
Jul 22, 2020
f65ee15
CIF-1398: Move <AddressForm> component to its own folder from checkou…
Jul 22, 2020
632e72e
CIF-1398: Copy the styles from flow.css so that addressForm.css won't…
Jul 22, 2020
11d77a2
Merge branch 'master' into issues/CIF-1398
Jul 22, 2020
f913786
CIF-1398: Change default labels of <AddressForm> component
Jul 22, 2020
e5508ba
CIF-1398: Adjust styles of address form so that it displays correctly…
Jul 23, 2020
c853531
CIF-1398: Add form error message render logic to '<AddressForm>' comp…
Jul 23, 2020
4bb7fb3
CIF-1398: Add translations to account.json and checkout.json
Jul 23, 2020
73affb1
CIF-1398: Fix the issue that 'region_code' can't be saved correctly
Jul 24, 2020
2bc6890
CIF-1398: Update the tests for query_countries request to include reg…
Jul 24, 2020
834827a
Merge branch 'master' into issues/CIF-1398
Jul 27, 2020
41ddea6
CIF-1398: Refactor <AddressDeleteModal> component
Jul 27, 2020
6dfd6e9
CIF-1398: Add delete customer address action and its tests
Jul 28, 2020
76eaae8
CIF-1398: Run prettier fix for the action test file
Jul 28, 2020
baae96b
CIF-1398: Rename action type of 'removeDeletedAddress' to 'postDelete…
Jul 28, 2020
ed0b21b
CIF-1398: Fix the typo for action type of 'postDeleteAddress'
Jul 28, 2020
c7371a0
CIF-1398: Use inline callback for buttons of address delete modal
Jul 28, 2020
88fc75d
CIF-1398: Replace 'getRegionId' with 'useRegionId' hook in addressFor…
Jul 28, 2020
0eef4d0
CIF-1398: Add test case for 'useRegionId' to cover the scenario when …
Jul 28, 2020
9f276ef
CIF-1398: Remove the custom hook 'useRegionId' and its test
Jul 28, 2020
1c4401f
CIF-1398: Add new hook 'useAddressForm' for providing data to '<Addre…
Jul 28, 2020
502aa9d
CIF-1398: Change '<AddressFormContainer>' to use new hook 'useAddress…
Jul 28, 2020
47068bb
CIF-1398: Expose 'countries' from 'useAddressForm', change '<AddressF…
Jul 28, 2020
b6ffe28
CIF-1398: Remove the unused hook import from test file of hooks.test.js
Jul 28, 2020
496ab04
CIF-1398: Change '<AddressItem>' component to use inline callback fun…
Jul 28, 2020
a3c63a8
CIF-1398: Add tests for address book related components and their sna…
Jul 28, 2020
41fcb81
CIF-1398: Create 'createAddress' and 'updateAddress' actions
Jul 29, 2020
947d5c8
CIF-1398: Finish tests for address book components and hook, correct …
Jul 29, 2020
5dca7ed
CIF-1398: Add tests for 'createAddress' and 'updateAddress' actions
Jul 29, 2020
1a70d9b
CIF-1398: Refactor the 'showAddressBook' function in navigation panel…
Jul 29, 2020
e4c0b17
CIF-1398: Fix the issue that can't delete address by clicking delete …
Jul 29, 2020
b921c25
CIF-1398: Format the addressDeleteModal.js
Jul 29, 2020
aeed727
Merge branch 'master' into issues/CIF-1398
nettree Jul 29, 2020
082b3a6
CIF-1398: Add test suits for account dropdown related code in UserCon…
Jul 29, 2020
1d124d4
CIF-1398: Increase test coverage rate for UserContext.js
Jul 30, 2020
346bc19
CIF-1398: Increase test coverage rate for NavigationContext.js, chang…
Jul 30, 2020
aa332fe
Merge branch 'master' into issues/CIF-1398
dplaton Jul 30, 2020
d9cda43
CIF-1398: Hide email input field from address form by default, update…
Jul 31, 2020
1bb3ff2
Merge branch 'issues/CIF-1398' of https://github.com/adobe/aem-core-c…
Jul 31, 2020
645c360
CIF-1398: Fix the issue when create or update an address to be the de…
Jul 31, 2020
65ef232
@trivial Exclude the `queries` folder from coverage
Aug 3, 2020
dd22d88
@trivial Configure Jest to exclude the `queries` folder from the test…
Aug 3, 2020
a639f48
Merge branch 'master' into issues/CIF-1398
cjelger Aug 3, 2020
13ce11b
Merge branch 'master' into issues/CIF-1398
laurentiumagureanu Aug 3, 2020
a3b2edf
Merge branch 'master' into issues/CIF-1398
dplaton Aug 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ flags:
- ui.apps/
jest:
paths:
- react-components/
- react-components/
11 changes: 10 additions & 1 deletion react-components/i18n/en/account.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,14 @@
"forgot-password-cancel": "Cancel",
"create-cancel": "Cancel",
"change-password-cancel": "Cancel",
"sign-in-form-title": "Sign-in to Your Account"
"sign-in-form-title": "Sign-in to Your Account",
"add-an-address": "Add an address",
"address-save": "Save",
"address-book-sign-in-text": "Please Sign in to see your address book.",
"address-delete-cancel": "Cancel",
"address-delete-confirm": "Delete",
"address-edit": "Edit",
"address-delete": "Delete",
"address-default-tag": "Default",
"address-form-heading": "Address"
}
4 changes: 3 additions & 1 deletion react-components/i18n/en/checkout.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@
"use-shipping-method": "Use Method",
"specify-shipping-method": "Specify Shipping Method",
"order-confirmation": "The order number is <1>{{orderId}}</1>. You will receive an order confirmation email with order status and other details.",
"add-shipping-information": "Add Shipping Information"
"add-shipping-information": "Add Shipping Information",
"address-default-address": "Make my default address",
"address-form-heading": "Shipping Address"
}
5 changes: 3 additions & 2 deletions react-components/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ module.exports = {
moduleDirectories: ['node_modules', 'src/utils'],
coverageDirectory: '<rootDir>/coverage',
coverageReporters: ['json', 'lcov'],
coveragePathIgnorePatterns: ['<rootDir>/src/queries'],
testPathIgnorePatterns: ['<rootDir>/node_modules/'],
reporters: ['default', ['jest-junit', { outputDirectory: './test-results'}]],
reporters: ['default', ['jest-junit', { outputDirectory: './test-results' }]],
transform: {
'\\.(gql|graphql)$': 'jest-transform-graphql',
".+\\.json": "./__mocks__/jsonTransform.js",
'.+\\.json': './__mocks__/jsonTransform.js',
'.+\\.(js|jsx|ts|tsx)$': 'babel-jest'
},
moduleNameMapper: {
Expand Down
121 changes: 120 additions & 1 deletion react-components/src/actions/user/__test__/actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* governing permissions and limitations under the License.
*
******************************************************************************/
import { resetCustomerCart, signOutUser } from '../actions';
import { resetCustomerCart, signOutUser, createAddress, updateAddress, deleteAddress } from '../actions';

const setCartCookie = jest.fn();
const setUserCookie = jest.fn();
Expand Down Expand Up @@ -67,4 +67,123 @@ describe('User actions', () => {
expect(dispatch).toHaveBeenCalledTimes(1);
expect(dispatch).toHaveBeenCalledWith({ type: 'error', error: 'Error: Failed to sign out' });
});

it('create the customer address', async () => {
const variables = {
region: {
region_code: 'LA'
},
street: ['14 Stamford Court'],
default_shipping: false,
default_billing: false
};

const createCustomerAddress = jest.fn(() => {
return { data: { createCustomerAddress: variables } };
});

await createAddress({ createCustomerAddress, variables, dispatch });

expect(createCustomerAddress).toHaveBeenCalledTimes(1);

expect(dispatch).toHaveBeenCalledTimes(1);
expect(dispatch).toHaveBeenCalledWith({ type: 'postCreateAddress', address: variables });
});

it('fails to create the customer address', async () => {
const variables = {
region: {
region_code: 'LA'
},
street: ['14 Stamford Court'],
default_shipping: false,
default_billing: false
};

const createCustomerAddress = jest.fn().mockRejectedValueOnce(new Error('Failed to create the address'));

await createAddress({ createCustomerAddress, variables, dispatch });

expect(createCustomerAddress).toHaveBeenCalledTimes(1);

expect(dispatch).toHaveBeenCalledTimes(1);
dispatch({ type: 'setAddressFormError', error: 'Error: Failed to create the address' });
});

it('update the customer address', async () => {
const variables = {
id: 'my-address-id',
region: {
region_code: 'LA'
},
street: ['14 Stamford Court'],
default_shipping: false,
default_billing: false
};

const updateCustomerAddress = jest.fn(() => {
return { data: { updateCustomerAddress: variables } };
});

await updateAddress({ updateCustomerAddress, variables, dispatch });

expect(updateCustomerAddress).toHaveBeenCalledTimes(1);

expect(dispatch).toHaveBeenCalledTimes(1);
expect(dispatch).toHaveBeenCalledWith({ type: 'postUpdateAddress', address: variables });
});

it('fails to update the customer address', async () => {
const variables = {
id: 'my-address-id',
region: {
region_code: 'LA'
},
street: ['14 Stamford Court'],
default_shipping: false,
default_billing: false
};

const updateCustomerAddress = jest.fn().mockRejectedValueOnce(new Error('Failed to update the address'));

await updateAddress({ updateCustomerAddress, variables, dispatch });

expect(updateCustomerAddress).toHaveBeenCalledTimes(1);

expect(dispatch).toHaveBeenCalledTimes(1);
dispatch({ type: 'setAddressFormError', error: 'Error: Failed to update the address' });
});

it('delete the customer address', async () => {
const address = {
id: 'my-address-id'
};

const deleteCustomerAddress = jest.fn();

await deleteAddress({ deleteCustomerAddress, address, dispatch });

expect(deleteCustomerAddress).toHaveBeenCalledTimes(1);

expect(dispatch).toHaveBeenCalledTimes(1);
expect(dispatch).toHaveBeenCalledWith({ type: 'postDeleteAddress', address });
});

it('fails to delete the customer address', async () => {
const address = {
id: 'my-address-id'
};

const deleteCustomerAddress = jest.fn().mockRejectedValueOnce(new Error('Failed to delete the address'));

await deleteAddress({ deleteCustomerAddress, address, dispatch });

expect(deleteCustomerAddress).toHaveBeenCalledTimes(1);

expect(dispatch).toHaveBeenCalledTimes(1);
expect(dispatch).toHaveBeenCalledWith({
type: 'deleteAddressError',
error: 'Error: Failed to delete the address'
});
});
});
30 changes: 30 additions & 0 deletions react-components/src/actions/user/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,33 @@ export const signOutUser = async ({ revokeCustomerToken, setCartCookie, setUserC
dispatch({ type: 'error', error: error.toString() });
}
};

export const createAddress = async ({ createCustomerAddress, variables, resetFields, dispatch }) => {
try {
const { data } = await createCustomerAddress({ variables: variables });
dispatch({ type: 'postCreateAddress', address: data.createCustomerAddress, resetFields });
} catch (error) {
console.error('An error occurred during creating customer address', error);
dispatch({ type: 'setAddressFormError', error: error.toString() });
}
};

export const updateAddress = async ({ updateCustomerAddress, variables, resetFields, dispatch }) => {
try {
const { data } = await updateCustomerAddress({ variables: variables });
dispatch({ type: 'postUpdateAddress', address: data.updateCustomerAddress, resetFields });
} catch (error) {
console.error('An error occurred during updating customer address', error);
dispatch({ type: 'setAddressFormError', error: error.toString() });
}
};

export const deleteAddress = async ({ deleteCustomerAddress, address, dispatch }) => {
try {
await deleteCustomerAddress({ variables: { id: address.id } });
dispatch({ type: 'postDeleteAddress', address });
} catch (error) {
console.error('An error occurred during deleting customer address', error);
dispatch({ type: 'deleteAddressError', error: error.toString() });
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@ import classes from './accountDropdown.css';
const AccountDropdown = () => {
const [
{ isAccountDropdownOpen, accountDropdownView },
{ showSignIn, showMyAccount, showForgotPassword, showCreateAccount, showAccountCreated, showChangePassword }
{
showSignIn,
showMyAccount,
showForgotPassword,
showCreateAccount,
showAccountCreated,
showChangePassword,
showAddressBook
}
] = useUserContext();

const [t] = useTranslation('account');
Expand All @@ -49,7 +57,7 @@ const AccountDropdown = () => {
child = (
<MyAccount
showChangePassword={showChangePassword}
showAddressBook={() => {}}
showAddressBook={showAddressBook}
showAccountInformation={() => {}}
/>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<AddAddressButton> renders the component 1`] = `
<DocumentFragment>
<button
aria-label="Add an address"
class="root"
>
<span
class="icon"
>
<svg
fill="none"
height="18"
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
viewBox="0 0 24 24"
width="18"
xmlns="http://www.w3.org/2000/svg"
>
<rect
height="18"
rx="2"
ry="2"
width="18"
x="3"
y="3"
/>
<line
x1="12"
x2="12"
y1="8"
y2="16"
/>
<line
x1="8"
x2="16"
y1="12"
y2="12"
/>
</svg>
</span>
<span
class="label"
>
Add an address
</span>
</button>
</DocumentFragment>
`;

exports[`<AddAddressButton> renders the component with list display type 1`] = `
<DocumentFragment>
<button
aria-label="Add an address"
class="list"
>
<span
class="icon"
>
<svg
fill="none"
height="18"
stroke="currentColor"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
viewBox="0 0 24 24"
width="18"
xmlns="http://www.w3.org/2000/svg"
>
<rect
height="18"
rx="2"
ry="2"
width="18"
x="3"
y="3"
/>
<line
x1="12"
x2="12"
y1="8"
y2="16"
/>
<line
x1="8"
x2="16"
y1="12"
y2="12"
/>
</svg>
</span>
<span
class="label"
>
Add an address
</span>
</button>
</DocumentFragment>
`;
Loading