@ordergroove/offers 2.27.13 → 2.27.15-alpha-PR-654-9.8

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.
@@ -99,6 +99,15 @@ export const autoshipEligible = (state = {}, action) => {
99
99
  return state;
100
100
  };
101
101
 
102
+ export function textToFreq(text) {
103
+ const period = ['day', 'week', 'month'].findIndex(it => text.toLowerCase().includes(it)) + 1;
104
+ const every = (text.match(/(\d+)/) || ['', 1])[1];
105
+ if (every && period) {
106
+ return `${every}_${period}`;
107
+ }
108
+ return null;
109
+ }
110
+
102
111
  export const config = (
103
112
  state = {
104
113
  frequencies: [],
@@ -125,10 +134,15 @@ export const config = (
125
134
  const sellingPlanGroup = getOGSellingPlanGroup(product);
126
135
  const frequencies = sellingPlanGroup?.selling_plans?.map(({ id }) => `${id}`);
127
136
  if (frequencies?.length) {
137
+ const frequenciesEveryPeriod = sellingPlanGroup?.selling_plans
138
+ ?.map(({ options }) => options || [])
139
+ .flat()
140
+ .map(({ value }) => textToFreq(value));
128
141
  const frequenciesText = sellingPlanGroup.options?.[0]?.values || frequencies;
129
142
  return {
130
143
  ...state,
131
144
  defaultFrequency: frequencies[0],
145
+ frequenciesEveryPeriod,
132
146
  frequencies,
133
147
  frequenciesText
134
148
  };
@@ -154,6 +168,10 @@ export const inStock = (state = {}, action) => {
154
168
 
155
169
  return [product, ...product?.variants]?.reduce(productOrVariantInStockReducer, state) || state;
156
170
  }
171
+ // force offer to refresh when requesting a new one
172
+ if (constants.REQUEST_OFFER === action.type && action.payload.product === null) {
173
+ return { ...state };
174
+ }
157
175
 
158
176
  return state;
159
177
  };
@@ -1,43 +0,0 @@
1
- const og = window.og;
2
-
3
- async function simulateChange(element, value) {
4
- const evt = new Event('change', { bubbles: true });
5
- element.value = value;
6
- element.dispatchEvent(evt, { target: { value } });
7
- await new Promise(r => setTimeout(r, 1));
8
- }
9
-
10
- describe('Select Frequency', function() {
11
- let element;
12
- beforeEach(async () => {
13
- og.offers.clear();
14
- document.body.innerHTML = `
15
- <og-offer product="123" preview-standard-offer>
16
- <og-select-frequency default-text=" (recomended)">
17
- <option value="optedOut">Buy one time</option>
18
- <option value="2w" selected="selected">2 weeks</option>
19
- <option value="1m">1 month </option>
20
- </og-select-frequency>
21
- </og-offer>
22
- `;
23
- element = document.querySelector('og-select-frequency');
24
- await element.updateComplete;
25
- });
26
-
27
- it('it should have default frequency as value', async () => {
28
- const htmlSelectElement = element.shadowRoot.querySelector('og-select').shadowRoot.querySelector('select');
29
- expect(htmlSelectElement.value).toEqual('2_2');
30
- });
31
-
32
- it('should append recomended text to default frequency', async () => {
33
- const htmlSelectElement = element.shadowRoot.querySelector('og-select').shadowRoot.querySelector('select');
34
- expect(htmlSelectElement.innerText).toEqual('Buy one time\n2 weeks (recomended)\n1 month');
35
- });
36
-
37
- it('should not append recomended text to clicked frequency', async () => {
38
- const htmlSelectElement = element.shadowRoot.querySelector('og-select').shadowRoot.querySelector('select');
39
- await simulateChange(htmlSelectElement, '1_3');
40
- expect(htmlSelectElement.value).toEqual('1_3');
41
- expect(htmlSelectElement.innerText).toEqual('Buy one time\n2 weeks (recomended)\n1 month');
42
- });
43
- });
@@ -1,44 +0,0 @@
1
- const og = window.og;
2
-
3
- async function simulateChange(element, value) {
4
- const evt = new Event('change', { bubbles: true });
5
- element.value = value;
6
- element.dispatchEvent(evt, { target: { value } });
7
- await new Promise(r => setTimeout(r, 1));
8
- }
9
-
10
- describe('Select Frequency', function() {
11
- let element;
12
- beforeEach(async () => {
13
- og.offers.clear();
14
- document.body.innerHTML = `
15
- <og-offer product="123" preview-standard-offer>
16
- <og-select-frequency default-text=" (recomended)">
17
- <option value="optedOut">Buy one time</option>
18
- <option value="2w" selected="selected">2 weeks</option>
19
- <option value="1m">1 month </option>
20
- </og-select-frequency>
21
- </og-offer>
22
- `;
23
- element = document.querySelector('og-select-frequency');
24
- await element.updateComplete;
25
- await new Promise(r => setTimeout(r, 1000));
26
- });
27
-
28
- it('it should have default frequency as value', async () => {
29
- const htmlSelectElement = element.shadowRoot.querySelector('og-select').shadowRoot.querySelector('select');
30
- expect(htmlSelectElement.value).toEqual('2_2');
31
- });
32
-
33
- it('should append recomended text to default frequency', async () => {
34
- const htmlSelectElement = element.shadowRoot.querySelector('og-select').shadowRoot.querySelector('select');
35
- expect(htmlSelectElement.innerText).toEqual('Buy one time\n2 weeks (recomended)\n1 month');
36
- });
37
-
38
- it('should not append recomended text to clicked frequency', async () => {
39
- const htmlSelectElement = element.shadowRoot.querySelector('og-select').shadowRoot.querySelector('select');
40
- await simulateChange(htmlSelectElement, '1_3');
41
- expect(htmlSelectElement.value).toEqual('1_3');
42
- expect(htmlSelectElement.innerText).toEqual('Buy one time\n2 weeks (recomended)\n1 month');
43
- });
44
- });