Skip to content

Commit

Permalink
Merge branch 'develop' into dev/ui-test-poc3
Browse files Browse the repository at this point in the history
  • Loading branch information
dpatil-magento authored May 11, 2021
2 parents 562b159 + e3815e1 commit e3a8e6c
Show file tree
Hide file tree
Showing 101 changed files with 3,580 additions and 735 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,5 @@ We would like to recognize the following community members for their efforts on
[#pwa slack channel]: https://magentocommeng.slack.com/messages/C71HNKYS2
[babel]: https://babeljs.io/
[venia]: https://venia.magento.com/
[public calendar]: https://calendar.google.com/calendar/embed?src=64ooaerhsq8ajsdtpgepc1h33k%40group.calendar.google.com&ctz=America%2FChicago
[add that calendar]: https://calendar.google.com/calendar/ical/64ooaerhsq8ajsdtpgepc1h33k%40group.calendar.google.com/public/basic.ics
[public calendar]: https://opensource.magento.com/community-calendar
[add that calendar]: https://calendar.google.com/calendar/ical/sn3me3pduhd92hhk9s7frkn57o%40group.calendar.google.com/public/basic.ics
3 changes: 2 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ const globals = {
store_name: 'French Store View'
}
],
DEFAULT_LOCALE: 'en-US'
DEFAULT_LOCALE: 'en-US',
DEFAULT_COUNTRY_CODE: 'US'
};

// Reusable test configuration for Venia UI and storefront packages.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@
"validation.hasLengthAtMost": "Ne doit pas dépasser {value} caractère(s).",
"validation.hasLengthExactly": "Doit contenir exactement {value} caractère(s).",
"validation.invalidAbbreviation": "L'état \"{value}\" n'est pas une abréviation d'état valide.",
"validation.invalidCountry": "Le pays \"US\" n'est pas un pays disponible.",
"validation.invalidRegions": "Le pays \"US\" ne contient aucune région disponible.",
"validation.invalidCountry": "Le pays \"{value}\" n'est pas un pays disponible.",
"validation.invalidRegions": "Le pays \"{value}\" ne contient aucune région disponible.",
"validation.isEqualToField": "{value} doit correspondre.",
"validation.isNotEqualToField": "{value} doit être différent",
"validation.isRequired": "Est requis.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ test('render carousel with default props and verify Slick is called correctly',
expect.objectContaining({
item: {
sku: 'TEST-1',
small_image: '/test/product/1.png'
small_image: {
url: '/test/product/1.png'
}
}
}),
expect.anything()
Expand All @@ -225,7 +227,9 @@ test('render carousel with default props and verify Slick is called correctly',
expect.objectContaining({
item: {
sku: 'TEST-2',
small_image: '/test/product/2.png'
small_image: {
url: '/test/product/2.png'
}
}
}),
expect.anything()
Expand Down
12 changes: 1 addition & 11 deletions packages/pagebuilder/lib/ContentTypes/Products/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@ const restoreSortOrder = (skus, products) => {
return skus.map(sku => productsBySku.get(sku)).filter(Boolean);
};

// map Magento 2.3.1 schema changes to Venia 2.0.0 proptype shape to maintain backwards compatibility
const mapGalleryItem = item => {
const { small_image } = item;
return {
...item,
small_image:
typeof small_image === 'object' ? small_image.url : small_image
};
};

/**
* Page Builder Products component.
*
Expand Down Expand Up @@ -106,7 +96,7 @@ const Products = props => {

if (appearance === 'carousel') {
const galleryItems = items.map((item, index) => {
return <GalleryItem key={index} item={mapGalleryItem(item)} />;
return <GalleryItem key={index} item={item} />;
});

//Settings conditions was made due to react-slick issues
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ test('clears customer data from cache', async () => {
});

cache.restore({
ROOT_QUERY: {
anotherLocalField: 'This entry should not get deleted',
customerLocalField: 'This entry should get deleted'
},
Customer: {
id: 'customerId',
firstName: 'Veronica'
Expand All @@ -53,9 +57,32 @@ test('clears customer data from cache', async () => {

expect(log).toHaveBeenCalledTimes(2);

const initialCacheDataKeys = Object.keys(log.mock.calls[0][0]);
expect(initialCacheDataKeys).toEqual(['Customer', 'AnotherCacheEntry']);
const initialCacheData = log.mock.calls[0][0];
expect(initialCacheData).toMatchInlineSnapshot(`
Object {
"AnotherCacheEntry": Object {
"value": "This entry should not get deleted",
},
"Customer": Object {
"firstName": "Veronica",
"id": "customerId",
},
"ROOT_QUERY": Object {
"anotherLocalField": "This entry should not get deleted",
"customerLocalField": "This entry should get deleted",
},
}
`);

const finalCacheDataKeys = Object.keys(log.mock.calls[1][0]);
expect(finalCacheDataKeys).toEqual(['AnotherCacheEntry']);
const finalCacheData = log.mock.calls[1][0];
expect(finalCacheData).toMatchInlineSnapshot(`
Object {
"AnotherCacheEntry": Object {
"value": "This entry should not get deleted",
},
"ROOT_QUERY": Object {
"anotherLocalField": "This entry should not get deleted",
},
}
`);
});
23 changes: 18 additions & 5 deletions packages/peregrine/lib/Apollo/__tests__/deleteCacheEntry.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ test('handle function call', async () => {
});

cache.restore({
ROOT_QUERY: {
CartLocalField: true
},
Cart: {
id: '12345',
total_quantity: '3'
Expand All @@ -118,11 +121,21 @@ test('handle function call', async () => {

expect(log).toHaveBeenCalledTimes(2);

const initialKeys = log.mock.calls[0][0];
expect(initialKeys).toEqual(['Cart', 'Test']);

const finalKeys = log.mock.calls[1][0];
expect(finalKeys).toEqual(['Test']);
const initialCacheKeys = log.mock.calls[0][0];
expect(initialCacheKeys).toMatchInlineSnapshot(`
Array [
"ROOT_QUERY",
"Cart",
"Test",
]
`);

const finalCacheKeys = log.mock.calls[1][0];
expect(finalCacheKeys).toMatchInlineSnapshot(`
Array [
"Test",
]
`);

expect(spy).toHaveBeenCalledTimes(1);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ import { deleteCacheEntry } from './deleteCacheEntry';
* @param {ApolloClient} client
*/
export const clearCustomerDataFromCache = async client => {
await deleteCacheEntry(client, key => key.match(/^\$?Customer/));
await deleteCacheEntry(client, key => key.match(/^\$?Customer/i));
};
9 changes: 9 additions & 0 deletions packages/peregrine/lib/Apollo/deleteCacheEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ const deleteActiveCacheEntry = async (client, predicate) => {
}
});

// Remove from ROOT_QUERY cache.
if (client.cache.data.data.ROOT_QUERY) {
Object.keys(client.cache.data.data.ROOT_QUERY).forEach(key => {
if (predicate(key)) {
client.cache.data.delete('ROOT_QUERY', key);
}
});
}

// Immediately persist the cache changes to the active cache storage.
if (client.persistor) {
await client.persistor.persist();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ Object {
"customerCart": Object {
"keyArgs": [Function],
},
"customerWishlistProducts": Object {
"read": [Function],
},
},
},
"SelectedConfigurableOption": Object {
Expand Down
11 changes: 11 additions & 0 deletions packages/peregrine/lib/Apollo/policies/__tests__/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,3 +394,14 @@ test('wishlist entities have correct keys', () => {
'CustomerGiftCardWishlistItem:1'
);
});

test('local customerWishlistProducts field returns expected data', () => {
const { read } = typePolicies.Query.fields.customerWishlistProducts;
const existing = jest.fn();

const defaultValue = read();
const existingValue = read(existing);

expect(defaultValue).toMatchInlineSnapshot(`Array []`);
expect(existingValue).toBe(existing);
});
4 changes: 4 additions & 0 deletions packages/peregrine/lib/Apollo/policies/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* https://www.apollographql.com/docs/react/caching/cache-configuration/#typepolicy-fields
* https://www.apollographql.com/docs/react/caching/cache-field-behavior/
*/

const typePolicies = {
// Query/Mutation are "types" just like "Cart".
Query: {
Expand All @@ -18,6 +19,9 @@ const typePolicies = {
},
customerCart: {
keyArgs: () => 'Cart'
},
customerWishlistProducts: {
read: existing => existing || []
}
}
},
Expand Down
7 changes: 4 additions & 3 deletions packages/peregrine/lib/store/actions/checkout/asyncActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,14 +334,15 @@ export const createAccount = ({ history }) => async (dispatch, getState) => {
*/
export const formatAddress = (address = {}, countries = []) => {
const { region_code } = address;
const countryCode = DEFAULT_COUNTRY_CODE;

const usa = countries.find(({ id }) => id === 'US');
const { available_regions: regions } = usa;
const country = countries.find(({ id }) => id === countryCode);
const { available_regions: regions } = country;

const region = regions.find(({ code }) => code === region_code);

return {
country_id: 'US',
country_id: countryCode,
region_id: region.id,
region_code: region.code,
region: region.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const useAddressBookPage = (props = {}) => {
setDisplayError(false);

setIsDialogEditMode(false);
setFormAddress({ country_code: 'US' });
setFormAddress({ country_code: DEFAULT_COUNTRY_CODE });
setIsDialogOpen(true);
}, []);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const useShippingMethods = props => {
let formattedShippingMethods = [];
let selectedShippingMethod = null;
let selectedShippingFields = {
country: 'US',
country: DEFAULT_COUNTRY_CODE,
region: '',
zip: ''
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const useBillingAddress = props => {

const shippingAddressCountry = shippingAddressData
? shippingAddressData.cart.shippingAddresses[0].country.code
: 'US';
: DEFAULT_COUNTRY_CODE;
const isBillingAddressSame = formState.values.isBillingAddressSame;

const initialValues = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export const useCreditCard = props => {

const shippingAddressCountry = shippingAddressData
? shippingAddressData.cart.shippingAddresses[0].country.code
: 'US';
: DEFAULT_COUNTRY_CODE;
const isBillingAddressSame = formState.values.isBillingAddressSame;

const initialValues = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ describe('#useFilterModal', () => {
filterState: expect.any(Object),
handleApply: expect.any(Function),
handleClose: expect.any(Function),
handleKeyDownActions: expect.any(Function),
handleOpen: expect.any(Function),
handleReset: expect.any(Function),
isApplying: expect.any(Boolean),
isOpen: expect.any(Boolean)
Expand Down
Loading

0 comments on commit e3a8e6c

Please sign in to comment.