@magento/experience-platform-connector 1.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/intercept.js +24 -0
  2. package/package.json +30 -0
  3. package/src/__tests__/__snapshots__/utils.spec.js.snap +137 -0
  4. package/src/__tests__/utils.spec.js +52 -0
  5. package/src/config.js +31 -0
  6. package/src/handleEvent.js +9 -0
  7. package/src/handlers/__tests__/__mocks__/cartAddItem.js +36 -0
  8. package/src/handlers/__tests__/__mocks__/cartPageView.js +880 -0
  9. package/src/handlers/__tests__/__mocks__/categoryPageView.js +9 -0
  10. package/src/handlers/__tests__/__mocks__/checkoutPageView.js +138 -0
  11. package/src/handlers/__tests__/__mocks__/completeCheckout.js +156 -0
  12. package/src/handlers/__tests__/__mocks__/createAccount.js +9 -0
  13. package/src/handlers/__tests__/__mocks__/editAccount.js +9 -0
  14. package/src/handlers/__tests__/__mocks__/miniCartView.js +846 -0
  15. package/src/handlers/__tests__/__mocks__/orderConfirmationPageView.js +67 -0
  16. package/src/handlers/__tests__/__mocks__/pageView.js +7 -0
  17. package/src/handlers/__tests__/__mocks__/placeOrderButtonClicked.js +161 -0
  18. package/src/handlers/__tests__/__mocks__/productPageView.js +15 -0
  19. package/src/handlers/__tests__/__mocks__/searchPageRequest.js +22 -0
  20. package/src/handlers/__tests__/__mocks__/searchRequestSent.js +34 -0
  21. package/src/handlers/__tests__/__mocks__/searchResponseReceived.js +106 -0
  22. package/src/handlers/__tests__/__snapshots__/shoppingMiniCartView.spec.js.snap +137 -0
  23. package/src/handlers/__tests__/addToCart.spec.js +73 -0
  24. package/src/handlers/__tests__/categoryPageView.spec.js +55 -0
  25. package/src/handlers/__tests__/completeCheckout.spec.js +70 -0
  26. package/src/handlers/__tests__/createAccount.spec.js +43 -0
  27. package/src/handlers/__tests__/editAccount.spec.js +43 -0
  28. package/src/handlers/__tests__/pageView.spec.js +46 -0
  29. package/src/handlers/__tests__/placeOrder.spec.js +55 -0
  30. package/src/handlers/__tests__/productPageView.spec.js +64 -0
  31. package/src/handlers/__tests__/searchRequestSent.spec.js +119 -0
  32. package/src/handlers/__tests__/searchResponseReceived.spec.js +143 -0
  33. package/src/handlers/__tests__/shoppingCartPageView.spec.js +198 -0
  34. package/src/handlers/__tests__/shoppingMiniCartView.spec.js +36 -0
  35. package/src/handlers/__tests__/signIn.spec.js +73 -0
  36. package/src/handlers/__tests__/startCheckout.spec.js +193 -0
  37. package/src/handlers/addToCart.js +60 -0
  38. package/src/handlers/categoryPageView.js +34 -0
  39. package/src/handlers/completeCheckout.js +49 -0
  40. package/src/handlers/createAccount.js +25 -0
  41. package/src/handlers/editAccount.js +25 -0
  42. package/src/handlers/pageView.js +26 -0
  43. package/src/handlers/placeOrder.js +32 -0
  44. package/src/handlers/productPageView.js +41 -0
  45. package/src/handlers/searchRequestSent.js +38 -0
  46. package/src/handlers/searchResponseReceived.js +39 -0
  47. package/src/handlers/shoppingCartPageView.js +45 -0
  48. package/src/handlers/shoppingMiniCartView.js +31 -0
  49. package/src/handlers/signIn.js +29 -0
  50. package/src/handlers/startCheckout.js +45 -0
  51. package/src/hooks/useExtensionContext.js +21 -0
  52. package/src/main.js +116 -0
  53. package/src/queries/getExtensionContext.js +31 -0
  54. package/src/utils.js +101 -0
  55. package/src/wrappers/wrapUseAccountMenu.js +29 -0
  56. package/src/wrappers/wrapUseAutocomplete.js +48 -0
@@ -0,0 +1,67 @@
1
+ export default {
2
+ type: 'ORDER_CONFIRMATION_PAGE_VIEW',
3
+ payload: {
4
+ order_number: '000000267',
5
+ cart_id: 'I3XbPvRJhujwf2C2MWhevLgifr9xyXpL',
6
+ amount: {
7
+ grand_total: {
8
+ value: 84.53,
9
+ currency: 'USD',
10
+ __typename: 'Money'
11
+ },
12
+ discounts: null,
13
+ __typename: 'CartPrices'
14
+ },
15
+ shipping: [
16
+ {
17
+ amount: {
18
+ value: 0,
19
+ currency: 'USD',
20
+ __typename: 'Money'
21
+ },
22
+ carrier_title: 'Free Shipping',
23
+ method_title: 'Free',
24
+ __typename: 'SelectedShippingMethod'
25
+ }
26
+ ],
27
+ payment: {
28
+ purchase_order_number: null,
29
+ title: 'Credit Card',
30
+ __typename: 'SelectedPaymentMethod'
31
+ },
32
+ products: [
33
+ {
34
+ uid: 'MzA3NQ==',
35
+ product: {
36
+ uid: 'OQ==',
37
+ sku: 'VA19-GO-NA',
38
+ name: 'Gold Omni Bangle Set',
39
+ thumbnail: {
40
+ url:
41
+ 'https://master-7rqtwti-mfwmkrjfqvbjk.us-4.magentosite.cloud/media/catalog/product/cache/609faca36a4bc16a754bc2f43c184970/v/a/va19-go_main.jpg',
42
+ __typename: 'ProductImage'
43
+ },
44
+ __typename: 'SimpleProduct'
45
+ },
46
+ prices: {
47
+ price: {
48
+ currency: 'USD',
49
+ value: 78,
50
+ __typename: 'Money'
51
+ },
52
+ row_total: {
53
+ value: 78,
54
+ __typename: 'Money'
55
+ },
56
+ total_item_discount: {
57
+ value: 0,
58
+ __typename: 'Money'
59
+ },
60
+ __typename: 'CartItemPrices'
61
+ },
62
+ quantity: 1,
63
+ __typename: 'SimpleCartItem'
64
+ }
65
+ ]
66
+ }
67
+ };
@@ -0,0 +1,7 @@
1
+ export default {
2
+ type: 'CMS_PAGE_VIEW',
3
+ payload: {
4
+ title: 'Home Page - Venia',
5
+ url_key: 'venia-new-home'
6
+ }
7
+ };
@@ -0,0 +1,161 @@
1
+ export default {
2
+ type: 'CHECKOUT_PLACE_ORDER_BUTTON_CLICKED',
3
+ payload: {
4
+ cart_id: 'adaIGWl4UsoKOGIeX17FPrnMq3bXHVZA',
5
+ amount: {
6
+ grand_total: {
7
+ value: 466.01,
8
+ currency: 'USD',
9
+ __typename: 'Money'
10
+ },
11
+ discounts: null,
12
+ __typename: 'CartPrices'
13
+ },
14
+ shipping: [
15
+ {
16
+ amount: {
17
+ value: 0,
18
+ currency: 'USD',
19
+ __typename: 'Money'
20
+ },
21
+ carrier_title: 'Free Shipping',
22
+ method_title: 'Free',
23
+ __typename: 'SelectedShippingMethod'
24
+ }
25
+ ],
26
+ payment: {
27
+ purchase_order_number: null,
28
+ title: 'Credit Card',
29
+ __typename: 'SelectedPaymentMethod'
30
+ },
31
+ products: [
32
+ {
33
+ uid: 'Mjk3Nw==',
34
+ product: {
35
+ uid: 'MTEzNw==',
36
+ sku: 'VP08',
37
+ name: 'Bella Eyelet Capris',
38
+ thumbnail: {
39
+ url:
40
+ 'https://master-7rqtwti-mfwmkrjfqvbjk.us-4.magentosite.cloud/media/catalog/product/cache/609faca36a4bc16a754bc2f43c184970/v/p/vp08-rn_main_2.jpg',
41
+ __typename: 'ProductImage'
42
+ },
43
+ __typename: 'ConfigurableProduct'
44
+ },
45
+ prices: {
46
+ price: {
47
+ currency: 'USD',
48
+ value: 98,
49
+ __typename: 'Money'
50
+ },
51
+ row_total: {
52
+ value: 294,
53
+ __typename: 'Money'
54
+ },
55
+ total_item_discount: {
56
+ value: 0,
57
+ __typename: 'Money'
58
+ },
59
+ __typename: 'CartItemPrices'
60
+ },
61
+ quantity: 3,
62
+ configurable_options: [
63
+ {
64
+ configurable_product_option_uid:
65
+ 'Y29uZmlndXJhYmxlLzExMzcvMTU3',
66
+ option_label: 'Fashion Color',
67
+ configurable_product_option_value_uid:
68
+ 'Y29uZmlndXJhYmxlLzE1Ny8zNQ==',
69
+ value_label: 'Mint',
70
+ __typename: 'SelectedConfigurableOption'
71
+ },
72
+ {
73
+ configurable_product_option_uid:
74
+ 'Y29uZmlndXJhYmxlLzExMzcvMTkw',
75
+ option_label: 'Fashion Size',
76
+ configurable_product_option_value_uid:
77
+ 'Y29uZmlndXJhYmxlLzE5MC80OQ==',
78
+ value_label: '6',
79
+ __typename: 'SelectedConfigurableOption'
80
+ }
81
+ ],
82
+ __typename: 'ConfigurableCartItem'
83
+ },
84
+ {
85
+ uid: 'Mjk3OQ==',
86
+ product: {
87
+ uid: 'MTE1OA==',
88
+ sku: 'VA09',
89
+ name: 'Thin Leather Braided Belt',
90
+ thumbnail: {
91
+ url:
92
+ 'https://master-7rqtwti-mfwmkrjfqvbjk.us-4.magentosite.cloud/media/catalog/product/cache/609faca36a4bc16a754bc2f43c184970/v/a/va09-br_main_2.jpg',
93
+ __typename: 'ProductImage'
94
+ },
95
+ __typename: 'ConfigurableProduct'
96
+ },
97
+ prices: {
98
+ price: {
99
+ currency: 'USD',
100
+ value: 38,
101
+ __typename: 'Money'
102
+ },
103
+ row_total: {
104
+ value: 38,
105
+ __typename: 'Money'
106
+ },
107
+ total_item_discount: {
108
+ value: 0,
109
+ __typename: 'Money'
110
+ },
111
+ __typename: 'CartItemPrices'
112
+ },
113
+ quantity: 1,
114
+ configurable_options: [
115
+ {
116
+ configurable_product_option_uid:
117
+ 'Y29uZmlndXJhYmxlLzExNTgvMTkw',
118
+ option_label: 'Fashion Size',
119
+ configurable_product_option_value_uid:
120
+ 'Y29uZmlndXJhYmxlLzE5MC80NA==',
121
+ value_label: 'M',
122
+ __typename: 'SelectedConfigurableOption'
123
+ }
124
+ ],
125
+ __typename: 'ConfigurableCartItem'
126
+ },
127
+ {
128
+ uid: 'Mjk4Nw==',
129
+ product: {
130
+ uid: 'MTI=',
131
+ sku: 'VA22-SI-NA',
132
+ name: 'Silver Amor Bangle Set',
133
+ thumbnail: {
134
+ url:
135
+ 'https://master-7rqtwti-mfwmkrjfqvbjk.us-4.magentosite.cloud/media/catalog/product/cache/609faca36a4bc16a754bc2f43c184970/v/a/va22-si_main.jpg',
136
+ __typename: 'ProductImage'
137
+ },
138
+ __typename: 'SimpleProduct'
139
+ },
140
+ prices: {
141
+ price: {
142
+ currency: 'USD',
143
+ value: 98,
144
+ __typename: 'Money'
145
+ },
146
+ row_total: {
147
+ value: 98,
148
+ __typename: 'Money'
149
+ },
150
+ total_item_discount: {
151
+ value: 0,
152
+ __typename: 'Money'
153
+ },
154
+ __typename: 'CartItemPrices'
155
+ },
156
+ quantity: 1,
157
+ __typename: 'SimpleCartItem'
158
+ }
159
+ ]
160
+ }
161
+ };
@@ -0,0 +1,15 @@
1
+ export default {
2
+ type: 'PRODUCT_PAGE_VIEW',
3
+ payload: {
4
+ id: '234d',
5
+ name: 'Selena Pants',
6
+ sku: '343g3434t',
7
+ currency_code: 'USD',
8
+ price_range: {
9
+ maximum_price: {
10
+ final_price: 40
11
+ }
12
+ },
13
+ url_key: 'selena-pants'
14
+ }
15
+ };
@@ -0,0 +1,22 @@
1
+ export default {
2
+ type: 'SEARCH_REQUEST',
3
+ payload: {
4
+ query: 'belt',
5
+ refinements: [
6
+ {
7
+ attribute: 'category_id',
8
+ value: new Set(['Accessories,3']),
9
+ isRange: false
10
+ },
11
+ {
12
+ attribute: 'fashion_size',
13
+ value: new Set(['M,44']),
14
+ isRange: false
15
+ }
16
+ ],
17
+ sort: {
18
+ attribute: 'relevance',
19
+ order: 'DESC'
20
+ }
21
+ }
22
+ };
@@ -0,0 +1,34 @@
1
+ export const searchRequestEvent = {
2
+ type: 'SEARCH_REQUEST',
3
+ payload: {
4
+ query: 'selena',
5
+ refinements: [
6
+ {
7
+ attribute: 'category_id',
8
+ value: new Set(['Bottoms,11']),
9
+ isRange: false
10
+ },
11
+ {
12
+ attribute: 'fashion_color',
13
+ value: new Set(['Rain,34', 'Mint,25']),
14
+ isRange: false
15
+ }
16
+ ],
17
+ sort: {
18
+ attribute: 'relevance',
19
+ order: 'DESC'
20
+ },
21
+ pageSize: 12,
22
+ currentPage: 1
23
+ }
24
+ };
25
+
26
+ export const searchbarRequestEvent = {
27
+ type: 'SEARCHBAR_REQUEST',
28
+ payload: {
29
+ query: 'selena',
30
+ currentPage: 1,
31
+ pageSize: 3,
32
+ refinements: []
33
+ }
34
+ };
@@ -0,0 +1,106 @@
1
+ export const searchResponseEvent = {
2
+ type: 'SEARCH_RESPONSE',
3
+ payload: {
4
+ categories: [
5
+ {
6
+ __typename: 'AggregationOption',
7
+ label: 'Bottoms',
8
+ value: '11'
9
+ },
10
+ {
11
+ __typename: 'AggregationOption',
12
+ label: 'Pants & Shorts',
13
+ value: '12'
14
+ }
15
+ ],
16
+ facets: [],
17
+ page: 1,
18
+ perPage: 3,
19
+ products: [
20
+ {
21
+ __typename: 'ConfigurableProduct',
22
+ id: 1144,
23
+ uid: 'MTE0NA==',
24
+ sku: 'VP01',
25
+ name: 'Selena Pants',
26
+ small_image: {
27
+ __typename: 'ProductImage',
28
+ url:
29
+ 'https://beacon-rjroszy-vzsrtettsztvg.us-4.magentosite.cloud/media/catalog/product/cache/37f3b100da589f62b6681aad6ae5936f/v/p/vp01-ll_main_2.jpg'
30
+ },
31
+ url_key: 'selena-pants',
32
+ url_suffix: '.html',
33
+ price: {
34
+ __typename: 'ProductPrices',
35
+ regularPrice: {
36
+ __typename: 'Price',
37
+ amount: {
38
+ __typename: 'Money',
39
+ value: 108,
40
+ currency: 'USD'
41
+ }
42
+ }
43
+ },
44
+ price_range: {
45
+ __typename: 'PriceRange',
46
+ maximum_price: {
47
+ __typename: 'ProductPrice',
48
+ final_price: {
49
+ __typename: 'Money',
50
+ currency: 'USD',
51
+ value: 108
52
+ },
53
+ discount: {
54
+ __typename: 'ProductDiscount',
55
+ amount_off: 0
56
+ }
57
+ }
58
+ }
59
+ }
60
+ ],
61
+ searchRequestId: 'selena',
62
+ searchUnitId: 'search-bar',
63
+ suggestions: [
64
+ {
65
+ __typename: 'ConfigurableProduct',
66
+ id: 1144,
67
+ uid: 'MTE0NA==',
68
+ sku: 'VP01',
69
+ name: 'Selena Pants',
70
+ small_image: {
71
+ __typename: 'ProductImage',
72
+ url:
73
+ 'https://beacon-rjroszy-vzsrtettsztvg.us-4.magentosite.cloud/media/catalog/product/cache/37f3b100da589f62b6681aad6ae5936f/v/p/vp01-ll_main_2.jpg'
74
+ },
75
+ url_key: 'selena-pants',
76
+ url_suffix: '.html',
77
+ price: {
78
+ __typename: 'ProductPrices',
79
+ regularPrice: {
80
+ __typename: 'Price',
81
+ amount: {
82
+ __typename: 'Money',
83
+ value: 108,
84
+ currency: 'USD'
85
+ }
86
+ }
87
+ },
88
+ price_range: {
89
+ __typename: 'PriceRange',
90
+ maximum_price: {
91
+ __typename: 'ProductPrice',
92
+ final_price: {
93
+ __typename: 'Money',
94
+ currency: 'USD',
95
+ value: 108
96
+ },
97
+ discount: {
98
+ __typename: 'ProductDiscount',
99
+ amount_off: 0
100
+ }
101
+ }
102
+ }
103
+ }
104
+ ]
105
+ }
106
+ };
@@ -0,0 +1,137 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`handle() calls the correct sdk functions with the correct context value 1`] = `
4
+ Object {
5
+ "giftMessageSelected": false,
6
+ "giftWrappingSelected": false,
7
+ "id": "kAR5Gg6uPC6J5wGY0ebecyKfX905epmU",
8
+ "items": Array [
9
+ Object {
10
+ "configurableOptions": Array [
11
+ Object {
12
+ "id": undefined,
13
+ "optionLabel": "Fashion Color",
14
+ "valueId": "Y29uZmlndXJhYmxlLzE1Ny8zMQ==",
15
+ "valueLabel": "Peach",
16
+ },
17
+ Object {
18
+ "id": undefined,
19
+ "optionLabel": "Fashion Size",
20
+ "valueId": "Y29uZmlndXJhYmxlLzE5MC80Mw==",
21
+ "valueLabel": "L",
22
+ },
23
+ ],
24
+ "formattedPrice": "",
25
+ "id": "MjQ2Ng==",
26
+ "prices": Object {
27
+ "__typename": "CartItemPrices",
28
+ "price": Object {
29
+ "__typename": "Money",
30
+ "currency": "USD",
31
+ "value": 78,
32
+ },
33
+ "total_item_discount": Object {
34
+ "__typename": "Money",
35
+ "value": 0,
36
+ },
37
+ },
38
+ "product": Object {
39
+ "canonicalUrl": "rowena-skirt",
40
+ "mainImageUrl": "https://master-7rqtwti-mfwmkrjfqvbjk.us-4.magentosite.cloud/media/catalog/product/cache/609faca36a4bc16a754bc2f43c184970/v/s/vsk02-ll_main_2.jpg",
41
+ "name": "Rowena Skirt",
42
+ "pricing": Object {
43
+ "currencyCode": "USD",
44
+ "maximalPrice": 78,
45
+ "minimalPrice": 78,
46
+ "regularPrice": 78,
47
+ },
48
+ "productType": "ConfigurableProduct",
49
+ "sku": "VSK02",
50
+ },
51
+ "quantity": 1,
52
+ },
53
+ Object {
54
+ "configurableOptions": null,
55
+ "formattedPrice": "",
56
+ "id": "MjQ4Mg==",
57
+ "prices": Object {
58
+ "__typename": "CartItemPrices",
59
+ "price": Object {
60
+ "__typename": "Money",
61
+ "currency": "USD",
62
+ "value": 68,
63
+ },
64
+ "total_item_discount": Object {
65
+ "__typename": "Money",
66
+ "value": 0,
67
+ },
68
+ },
69
+ "product": Object {
70
+ "canonicalUrl": "silver-cirque-earrings",
71
+ "mainImageUrl": "https://master-7rqtwti-mfwmkrjfqvbjk.us-4.magentosite.cloud/media/catalog/product/cache/609faca36a4bc16a754bc2f43c184970/v/a/va17-si_main.jpg",
72
+ "name": "Silver Cirque Earrings",
73
+ "pricing": Object {
74
+ "currencyCode": "USD",
75
+ "maximalPrice": 68,
76
+ "minimalPrice": 68,
77
+ "regularPrice": 68,
78
+ },
79
+ "productType": "SimpleProduct",
80
+ "sku": "VA17-SI-NA",
81
+ },
82
+ "quantity": 2,
83
+ },
84
+ Object {
85
+ "configurableOptions": Array [
86
+ Object {
87
+ "id": undefined,
88
+ "optionLabel": "Fashion Color",
89
+ "valueId": "Y29uZmlndXJhYmxlLzE1Ny8zMQ==",
90
+ "valueLabel": "Peach",
91
+ },
92
+ Object {
93
+ "id": undefined,
94
+ "optionLabel": "Fashion Size",
95
+ "valueId": "Y29uZmlndXJhYmxlLzE5MC80NA==",
96
+ "valueLabel": "M",
97
+ },
98
+ ],
99
+ "formattedPrice": "",
100
+ "id": "MjQ4Mw==",
101
+ "prices": Object {
102
+ "__typename": "CartItemPrices",
103
+ "price": Object {
104
+ "__typename": "Money",
105
+ "currency": "USD",
106
+ "value": 48,
107
+ },
108
+ "total_item_discount": Object {
109
+ "__typename": "Money",
110
+ "value": 0,
111
+ },
112
+ },
113
+ "product": Object {
114
+ "canonicalUrl": "antonia-infinity-scarf",
115
+ "mainImageUrl": "https://master-7rqtwti-mfwmkrjfqvbjk.us-4.magentosite.cloud/media/catalog/product/cache/609faca36a4bc16a754bc2f43c184970/v/a/va04-ll_main_2.jpg",
116
+ "name": "Antonia Infinity Scarf",
117
+ "pricing": Object {
118
+ "currencyCode": "USD",
119
+ "maximalPrice": 48,
120
+ "minimalPrice": 48,
121
+ "regularPrice": 48,
122
+ },
123
+ "productType": "ConfigurableProduct",
124
+ "sku": "VA04",
125
+ },
126
+ "quantity": 3,
127
+ },
128
+ ],
129
+ "possibleOnepageCheckout": false,
130
+ "prices": Object {
131
+ "subtotalExcludingTax": Object {
132
+ "currency": "USD",
133
+ "value": 358,
134
+ },
135
+ },
136
+ }
137
+ `;
@@ -0,0 +1,73 @@
1
+ import handler from '../addToCart';
2
+ import {
3
+ addSimpleProductEvent,
4
+ addConfigurableProductEvent
5
+ } from './__mocks__/cartAddItem';
6
+
7
+ describe('canHandle()', () => {
8
+ it('returns true for the correct event type', () => {
9
+ expect(handler.canHandle(addSimpleProductEvent)).toBeTruthy();
10
+ });
11
+
12
+ it('returns false for non supported event types', () => {
13
+ const mockEvent = {
14
+ type: 'USER_SIGN_OUT',
15
+ payload: {}
16
+ };
17
+ expect(handler.canHandle(mockEvent)).toBeFalsy();
18
+ });
19
+ });
20
+
21
+ describe('handle()', () => {
22
+ it('calls the correct sdk functions with the correct context value', () => {
23
+ const mockSdk = {
24
+ context: {
25
+ setShoppingCart: jest.fn()
26
+ },
27
+ publish: {
28
+ addToCart: jest.fn()
29
+ }
30
+ };
31
+
32
+ handler.handle(mockSdk, addConfigurableProductEvent);
33
+
34
+ expect(mockSdk.context.setShoppingCart).toHaveBeenCalledTimes(1);
35
+ expect(mockSdk.context.setShoppingCart.mock.calls[0][0])
36
+ .toMatchInlineSnapshot(`
37
+ Object {
38
+ "giftMessageSelected": false,
39
+ "giftWrappingSelected": false,
40
+ "id": "kAR5Gg6uPC6J5wGY0ebecyKfX905epmU",
41
+ "items": Array [
42
+ Object {
43
+ "prices": Object {
44
+ "price": Object {
45
+ "currency": "USD",
46
+ "value": 78,
47
+ },
48
+ },
49
+ "product": Object {
50
+ "configurableOptions": Array [
51
+ Object {
52
+ "optionLabel": undefined,
53
+ "valueLabel": undefined,
54
+ },
55
+ ],
56
+ "name": "Johanna Skirt",
57
+ "sku": "VSK03",
58
+ },
59
+ },
60
+ ],
61
+ "possibleOnepageCheckout": false,
62
+ "prices": Object {
63
+ "subtotalExcludingTax": Object {
64
+ "currency": "USD",
65
+ "value": 78,
66
+ },
67
+ },
68
+ }
69
+ `);
70
+
71
+ expect(mockSdk.publish.addToCart).toHaveBeenCalledTimes(1);
72
+ });
73
+ });
@@ -0,0 +1,55 @@
1
+ import handler from '../categoryPageView';
2
+
3
+ import categoryPageViewEvent from './__mocks__/categoryPageView';
4
+ import miniCartViewEvent from './__mocks__/miniCartView';
5
+
6
+ describe('canHandle()', () => {
7
+ it('returns true for the correct event type', () => {
8
+ expect(handler.canHandle(categoryPageViewEvent)).toBeTruthy();
9
+ });
10
+
11
+ it('returns false for non supported event types', () => {
12
+ expect(handler.canHandle(miniCartViewEvent)).toBeFalsy();
13
+ });
14
+ });
15
+
16
+ describe('handle()', () => {
17
+ it('calls the correct sdk functions with the correct context value', () => {
18
+ const mockSdk = {
19
+ context: {
20
+ setCategory: jest.fn(),
21
+ setPage: jest.fn()
22
+ },
23
+ publish: {
24
+ pageView: jest.fn()
25
+ }
26
+ };
27
+
28
+ handler.handle(mockSdk, categoryPageViewEvent);
29
+
30
+ expect(mockSdk.context.setCategory).toHaveBeenCalledTimes(1);
31
+ expect(mockSdk.context.setCategory.mock.calls[0][0])
32
+ .toMatchInlineSnapshot(`
33
+ Object {
34
+ "name": "Dresses",
35
+ "urlKey": "venia-dresses",
36
+ "urlPath": "venia-dresses",
37
+ }
38
+ `);
39
+
40
+ expect(mockSdk.context.setPage).toHaveBeenCalledTimes(1);
41
+ expect(mockSdk.context.setPage.mock.calls[0][0]).toMatchInlineSnapshot(`
42
+ Object {
43
+ "eventType": "visibilityHidden",
44
+ "maxXOffset": 0,
45
+ "maxYOffset": 0,
46
+ "minXOffset": 0,
47
+ "minYOffset": 0,
48
+ "pageName": "Dresses",
49
+ "pageType": "Category",
50
+ }
51
+ `);
52
+
53
+ expect(mockSdk.publish.pageView).toHaveBeenCalledTimes(1);
54
+ });
55
+ });