Skip to content

Commit

Permalink
Merge branch 'develop' into fix/storeCode-for-category-link
Browse files Browse the repository at this point in the history
  • Loading branch information
michasik committed Jul 9, 2019
2 parents 677bcce + 327db3e commit 998f36b
Show file tree
Hide file tree
Showing 68 changed files with 1,243 additions and 434 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Shipping address is saved as default when not logged in user chooses to create account during checkout - @iwonapiotrowska (#2636)
- Can set transition style for Modal content - @grimasod (#3146)
- Added stock to cart items - @cheeerd (#3166)
- Translation file improvements - @vishal-7037 (#3198)

## [1.10.0-rc.2] - UNRELEASED

### Fixed
- Fixed wrong meta description attribute by page overwrite - @przspa (#3091)
- Wrong meta description attribute by page overwrite - @przspa (#3091)
- The SSR Cms console errors fixed + `magento-2-cms` module removed - @pkarw (#3155)
- Cart unit tests throwing lots of type warnings - @lukeromanowicz (#3185)
- Lack of possibility to mock src modules and theme components - @lukeromanowicz (#3185)

## [1.10.0-rc.1] - 2019.06.19

Expand Down
16 changes: 3 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ If you're new and need some guidance feel free to visit out [forum](https://foru
- `@Filip Rakowski` (frontend, architecture and best practices related stuff)
- `@pkarw` (integrations and backend related stuff)
- `@ptomczyk` (frontend related stuff)
- `@Bartek Igielski`(frontend and magento-specific related stuff)

Want to invest some time in building the future of eCommerce? we are looking for core team members willing to help us make VS even more awesome. Interested - contact `@Filip Rakowski` on slack

Expand Down Expand Up @@ -268,15 +267,6 @@ Vue Storefront is a Community effort brought to You by our great Core Team and s
>
</a>
</td>
<td align="center" valign="middle">
<a href="https://snow.dog">
<img
src="docs/.vuepress/public/partners/snowdog.png"
alt="Snow.dog"
width="150"
>
</a>
</td>
<td align="center" valign="middle">
<a href="https://vendic.nl/">
<img
Expand Down Expand Up @@ -747,10 +737,10 @@ Vue Storefront is a Community effort brought to You by our great Core Team and s
</a>
</td>
<td align="center" valign="middle">
<a href="">
<a href="https://www.tam-tam.co.jp">
<img
src=""
alt=""
src="https://divante.co/partners/Vue-Storefront/tam%20logo.png"
alt="TAM"
height="40"
>
</a>
Expand Down
1 change: 1 addition & 0 deletions config/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
2 changes: 1 addition & 1 deletion core/modules/cart/test/unit/components/AddToCart.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('AddToCart', () => {
modules: {
cart: {
actions: {
addItem: jest.fn()
addItem: jest.fn(() => [])
},
namespaced: true
}
Expand Down
31 changes: 29 additions & 2 deletions core/modules/cart/test/unit/components/Product.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {mountMixin, mountMixinWithStore} from '@vue-storefront/unit-tests/utils'

import Product from '@vue-storefront/core/modules/catalog/types/Product';
import { productThumbnailPath } from '@vue-storefront/core/helpers';

import config from 'config'
import { MicrocartProduct } from '../../../components/Product';
import Mock = jest.Mock;

Expand All @@ -13,9 +13,23 @@ jest.mock('@vue-storefront/core/helpers', () => ({
describe('MicrocartProduct', () => {
beforeEach(() => {
jest.clearAllMocks();
Object.keys(config).forEach((key) => { delete config[key]; });
});

it('thumbnail in online mode returns thumbnail in lower size', () => {
config.products = {
thumbnails: {
width: 300,
height: 300
}
};
config.cart = {
thumbnails: {
width: 150,
height: 150
}
};

(productThumbnailPath as Mock).mockReturnValueOnce('thumbnail-path');

Object.defineProperty(navigator, 'onLine', { value: true, configurable: true });
Expand All @@ -31,6 +45,19 @@ describe('MicrocartProduct', () => {
});

it('thumbnail in offline mode returns thumbnail in greater size', () => {
config.products = {
thumbnails: {
width: 300,
height: 300
}
};
config.cart = {
thumbnails: {
width: 150,
height: 150
}
};

(productThumbnailPath as Mock).mockReturnValueOnce('thumbnail-path');

Object.defineProperty(navigator, 'onLine', { value: false, configurable: true });
Expand All @@ -42,7 +69,7 @@ describe('MicrocartProduct', () => {
wrapper.setMethods({ getThumbnail });

expect((wrapper.vm as any).thumbnail).toEqual('resized-thumbnail-path');
expect(getThumbnail).toBeCalledWith('thumbnail-path', 310, 300);
expect(getThumbnail).toBeCalledWith('thumbnail-path', 300, 300);
});

it('removeFromCart dispatches removeItem to remove product from cart', () => {
Expand Down
73 changes: 25 additions & 48 deletions core/modules/cart/test/unit/store/actions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,16 @@ describe('Cart actions', () => {
expect(contextMock.commit).toBeCalledWith(types.CART_LOAD_CART_SERVER_TOKEN, null);
});

it('clear deletes all cart products and token', () => {
it('clear deletes all cart products and token', async () => {
const contextMock = {
commit: jest.fn()
commit: jest.fn(),
getters: { isCartSyncEnabled: false }
};
const wrapper = (actions: any) => actions.clear(contextMock);

config.cart = { synchronize: false };

wrapper(cartActions);
await wrapper(cartActions);

expect(contextMock.commit).toBeCalledWith(types.CART_LOAD_CART, []);
});
Expand All @@ -87,7 +88,7 @@ describe('Cart actions', () => {
const contextMock = {
commit: jest.fn(),
dispatch: jest.fn(),
getters: { isCartSyncEnabled: () => true, isTotalsSyncRequired: () => true, isSyncRequired: () => true, isCartConnected: () => true }
getters: { isCartSyncEnabled: true, isTotalsSyncRequired: true, isSyncRequired: true, isCartConnected: true }
};

config.cart = { synchronize: true };
Expand All @@ -104,7 +105,7 @@ describe('Cart actions', () => {
const contextMock = {
commit: jest.fn(),
dispatch: jest.fn(),
getters: { isCartSyncEnabled: () => true, isTotalsSyncRequired: () => true, isSyncRequired: () => true, isCartConnected: () => true }
getters: { isCartSyncEnabled: true, isTotalsSyncRequired: true, isSyncRequired: true, isCartConnected: true }
};

config.cart = { synchronize: true };
Expand All @@ -121,7 +122,7 @@ describe('Cart actions', () => {
it('doesn\'t update shipping methods if cart is empty', async () => {
const contextMock = {
rootGetters: { checkout: { isUserInCheckout: () => false } },
getters: { isCartSyncEnabled: () => true, isTotalsSyncRequired: () => true, isSyncRequired: () => true, isCartConnected: () => true },
getters: { isCartSyncEnabled: true, isTotalsSyncRequired: true, isSyncRequired: true, isCartConnected: true },
dispatch: jest.fn(),
state: {
cartItems: [],
Expand Down Expand Up @@ -160,34 +161,34 @@ describe('Cart actions', () => {
);
});

it('does not do anything if synchronization is off', () => {
it('does not do anything if synchronization is off', async () => {
const contextMock = {
rootGetters: { checkout: { isUserInCheckout: () => false } },
getters: { isCartSyncEnabled: () => true, isTotalsSyncRequired: () => true, isSyncRequired: () => true, isCartConnected: () => true },
getters: { isCartSyncEnabled: true, isTotalsSyncRequired: true, isSyncRequired: true, isCartConnected: true },
dispatch: jest.fn()
};

config.cart = { synchronize: false };

const wrapper = (actions: any) => actions.serverPull(contextMock, {});

wrapper(cartActions);
await wrapper(cartActions);

expect(TaskQueue.execute).not.toBeCalled();
});

it('does not do anything in SSR environment', () => {
it('does not do anything in SSR environment', async () => {
const contextMock = {
rootGetters: { checkout: { isUserInCheckout: () => false } },
getters: { isCartSyncEnabled: () => true, isTotalsSyncRequired: () => true, isSyncRequired: () => true, isCartConnected: () => true },
getters: { isCartSyncEnabled: true, isTotalsSyncRequired: true, isSyncRequired: true, isCartConnected: true },
dispatch: jest.fn()
};

config.cart = { synchronize: true };

const wrapper = (actions: any) => actions.serverPull(contextMock, {});

wrapper(cartActions);
await wrapper(cartActions);

expect(TaskQueue.execute).not.toBeCalled();
});
Expand All @@ -197,7 +198,8 @@ describe('Cart actions', () => {
it('does not do anything if totals synchronization is off', () => {
const contextMock = {
rootGetters: { checkout: { isUserInCheckout: () => false } },
getters: { isCartSyncEnabled: () => false, isTotalsSyncEnabled: () => false, isTotalsSyncRequired: () => true, isSyncRequired: () => true, isCartConnected: () => true },
dispatch: jest.fn(),
getters: { isCartSyncEnabled: false, isTotalsSyncEnabled: false, isTotalsSyncRequired: true, isSyncRequired: true, isCartConnected: true },
state: {
cartServerToken: 'some-token'
}
Expand All @@ -213,7 +215,11 @@ describe('Cart actions', () => {
});

it('does not do anything in SSR environment', () => {
const contextMock = {};
const contextMock = {
getters: {
isTotalsSyncRequired: false
}
};

config.cart = { synchronize_totals: true };

Expand All @@ -228,10 +234,10 @@ describe('Cart actions', () => {
describe('connect', () => {
it('requests to backend for creation of a new cart', async () => {
const contextMock = {
getters: { isCartSyncEnabled: true, isTotalsSyncRequired: true, isSyncRequired: true, isCartConnected: true },
state: {
cartconnectdAt: 1000000000
},
getters: { isCartSyncEnabled: () => true, isTotalsSyncRequired: () => true, isSyncRequired: () => true, isCartConnected: () => true }
}
};

config.cart = { synchronize: true };
Expand All @@ -250,7 +256,7 @@ describe('Cart actions', () => {
it('requests to backend for creation of guest cart', async () => {
const contextMock = {
rootGetters: { checkout: { isUserInCheckout: () => false } },
getters: { isCartSyncEnabled: () => true, isTotalsSyncRequired: () => true, isSyncRequired: () => true, isCartConnected: () => true },
getters: { isCartSyncEnabled: true, isTotalsSyncRequired: true, isSyncRequired: true, isCartConnected: true },
state: {
cartconnectdAt: 1000000000
}
Expand All @@ -271,28 +277,11 @@ describe('Cart actions', () => {
expect(TaskQueue.execute).toBeCalledWith(expect.objectContaining({ url: 'http://example.url/guest-cart/' }))
});

it('does not do anything if last totals sync was done recently', () => {
it('does not do anything if totals synchronization is off', () => {
const contextMock = {
state: {
cartconnectdAt: 1000000000
}
getters: { isCartSyncEnabled: false }
};

config.cart = { synchronize: true };

isServerSpy.mockReturnValueOnce(false);
Date.now = jest.fn(() => 1000000050);

const wrapper = (actions: any) => actions.connect(contextMock, {});

wrapper(cartActions);

expect(TaskQueue.execute).not.toBeCalled();
});

it('does not do anything if totals synchronization is off', () => {
const contextMock = {};

config.cart = { synchronize: false };

const wrapper = (actions: any) => actions.connect(contextMock, {});
Expand All @@ -301,17 +290,5 @@ describe('Cart actions', () => {

expect(TaskQueue.execute).not.toBeCalled();
});

it('does not do anything in SSR environment', () => {
const contextMock = {};

config.cart = { synchronize: true };

const wrapper = (actions: any) => actions.connect(contextMock, {});

wrapper(cartActions);

expect(TaskQueue.execute).not.toBeCalled();
});
});
});
31 changes: 12 additions & 19 deletions core/modules/cart/test/unit/store/getters.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import cartGetters from '../../../store/getters';
import { onlineHelper } from '@vue-storefront/core/helpers'
import config from 'config'

jest.mock('@vue-storefront/i18n', () => ({ t: jest.fn(str => str) }));
jest.mock('@vue-storefront/core/helpers', () => ({
Expand All @@ -15,6 +16,7 @@ describe('Cart getters', () => {

beforeEach(() => {
jest.clearAllMocks();
Object.keys(config).forEach((key) => { delete config[key]; });
});

it('totals returns platform total segments if they has been saved in store and client is online', () => {
Expand Down Expand Up @@ -143,45 +145,36 @@ describe('Cart getters', () => {
});

it('totalQuantity returns total quantity of all products in cart if minicart configuration is set to quantities', () => {
config.cart = {
minicartCountType: 'quantities'
}
const stateMock = {
cartItems: [
{qty: 1},
{qty: 2}
]
};

const rootStoreMock = {
config: {
cart: {
minicartCountType: 'quantities'
}
}
};

const wrapper = (getters: any) => getters.getItemsTotalQuantity(stateMock, {}, rootStoreMock);
const wrapper = (getters: any) => getters.getItemsTotalQuantity(stateMock, {});

expect(wrapper(cartGetters)).toBe(3);
});

it('totalQuantity returns number of different products instead of their sum if minicart configuration is set to items', () => {
config.cart = {
minicartCountType: 'items'
}

const stateMock = {
cartItems: [
{qty: 1},
{qty: 2}
]
};

const rootStoreMock = {
config: {
cart: {
minicartCountType: 'items'
}
}
};

const wrapper = (getters: any) => getters.getItemsTotalQuantity(stateMock, {}, rootStoreMock);
const wrapper = (getters: any) => getters.getItemsTotalQuantity(stateMock, {});

expect(wrapper(cartGetters)).toBe(3);
expect(wrapper(cartGetters)).toBe(2);
});

it('coupon returns coupon information when coupon has been applied to the cart', () => {
Expand Down
6 changes: 5 additions & 1 deletion core/modules/catalog-next/helpers/filterHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ export const changeFilterQuery = ({currentQuery = {}, filterVariant}: {currentQu
if (!Array.isArray(queryFilter)) queryFilter = [queryFilter]
if (queryFilter.includes(filterVariant.id)) {
queryFilter = queryFilter.filter(value => value !== filterVariant.id)
} else if (filterVariant.single) {
queryFilter = [filterVariant.id]
} else {
queryFilter.push(filterVariant.id)
}
newQuery[filterVariant.type] = queryFilter
// delete or add filter variant to query
if (!queryFilter.length) delete newQuery[filterVariant.type]
else newQuery[filterVariant.type] = queryFilter
}
return newQuery
}
Expand Down
Loading

0 comments on commit 998f36b

Please sign in to comment.