Skip to content

Commit

Permalink
Updated Profile page (#726)
Browse files Browse the repository at this point in the history
* Updated Profile page

* Updates in Profile page

* - test updates, bug fixes for empty elements

Co-authored-by: Shaun Maharaj <[email protected]>
  • Loading branch information
petro97 and Shaun Maharaj authored May 21, 2020
1 parent dc7f920 commit 5b98271
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/containers/ProfilePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class ProfilePage extends React.Component<RouteComponentProps, ProfilePageState>

renderShippingAddress() {
const { profileData } = this.state;
if (profileData && profileData._addresses[0]._shippingaddresses && profileData._addresses[0]._shippingaddresses[0]._selector[0]._chosen) {
if (profileData && profileData._addresses && profileData._addresses[0]._shippingaddresses && profileData._addresses[0]._shippingaddresses[0]._selector && profileData._addresses[0]._shippingaddresses[0]._selector[0]._chosen) {
const selectedAddress = profileData._addresses[0]._shippingaddresses[0]._selector[0]._chosen[0]._description[0].address;
const selectedAddressName = profileData._addresses[0]._shippingaddresses[0]._selector[0]._chosen[0]._description[0].name;
return (
Expand Down Expand Up @@ -189,7 +189,7 @@ class ProfilePage extends React.Component<RouteComponentProps, ProfilePageState>

renderBillingAddress() {
const { profileData } = this.state;
if (profileData && profileData._addresses[0]._billingaddresses && profileData._addresses[0]._billingaddresses[0]._selector[0]._chosen) {
if (profileData && profileData._addresses && profileData._addresses[0]._billingaddresses && profileData._addresses[0]._billingaddresses[0]._selector && profileData._addresses[0]._billingaddresses[0]._selector[0]._chosen) {
const selectedAddress = profileData._addresses[0]._billingaddresses[0]._selector[0]._chosen[0]._description[0].address;
const selectedAddressName = profileData._addresses[0]._billingaddresses[0]._selector[0]._chosen[0]._description[0].name;
return (
Expand Down
8 changes: 4 additions & 4 deletions src/containers/b2b/AddressBookPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ class AddressBookPage extends React.Component<AddressBookPageProps, AddressBookP
const profileData = await res.json();
if (profileData && profileData._defaultprofile) {
const addressData = profileData._defaultprofile[0]._addresses[0];
const chosenBillingAddress = addressData._billingaddresses[0]._selector[0]._chosen && addressData._billingaddresses[0]._selector[0]._chosen[0]._description[0].self.uri;
const chosenShippingAddress = addressData._shippingaddresses[0]._selector[0]._chosen && addressData._shippingaddresses[0]._selector[0]._chosen[0]._description[0].self.uri;
const chosenBillingAddress = addressData._billingaddresses[0]._selector && addressData._billingaddresses[0]._selector[0]._chosen && addressData._billingaddresses[0]._selector[0]._chosen[0]._description[0].self.uri;
const chosenShippingAddress = addressData._shippingaddresses[0]._selector && addressData._shippingaddresses[0]._selector[0]._chosen && addressData._shippingaddresses[0]._selector[0]._chosen[0]._description[0].self.uri;
this.setState({
profileData: addressData,
chosenBillingUri: chosenBillingAddress,
Expand Down Expand Up @@ -141,9 +141,9 @@ class AddressBookPage extends React.Component<AddressBookPageProps, AddressBookP
const newOrEdit = (addressData && addressData.addressUri) ? intl.get('edit') : intl.get('new');
const isChosenBilling = chosenBillingUri === (addressData && addressData.addressUri);
const isChosenShipping = chosenShippingUri === (addressData && addressData.addressUri);
let selectactionShippingUri = addressData && profileData._shippingaddresses[0]._selector[0]._choice
let selectactionShippingUri = addressData && profileData._shippingaddresses[0]._selector && profileData._shippingaddresses[0]._selector[0]._choice
&& profileData._shippingaddresses[0]._selector[0]._choice.find(el => addressData.addressUri === el._description[0].self.uri);
let selectactionBillingUri = addressData && profileData._billingaddresses[0]._selector[0]._choice
let selectactionBillingUri = addressData && profileData._billingaddresses[0]._selector && profileData._billingaddresses[0]._selector[0]._choice
&& profileData._billingaddresses[0]._selector[0]._choice.find(el => addressData.addressUri === el._description[0].self.uri);
selectactionShippingUri = selectactionShippingUri && selectactionShippingUri._selectaction[0].self.uri;
selectactionBillingUri = selectactionBillingUri && selectactionBillingUri._selectaction[0].self.uri;
Expand Down
3 changes: 3 additions & 0 deletions src/tests/e2e/profile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ describe('Profile', () => {
await page.click(MY_PROFILE);

// Then I can see my addresses
await page.waitFor(3000);
await page.waitForSelector(EDIT_ADDRESS_BUTTON);
await page.click(EDIT_ADDRESS_BUTTON);
await page.waitForSelector(ADDRESS_STREET_NAME);
const element = await page.$(ADDRESS_STREET_NAME);
const text = await page.evaluate(el => el.textContent, element);
Expand Down

0 comments on commit 5b98271

Please sign in to comment.