@ordergroove/offers 2.27.13-alpha-PR-652-3.1 → 2.27.13

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ordergroove/offers",
3
- "version": "2.27.13-alpha-PR-652-3.1+5885ff1e",
3
+ "version": "2.27.13",
4
4
  "description": "offer state component",
5
5
  "author": "Eugenio Lattanzio <eugenio63@gmail.com>",
6
6
  "homepage": "https://github.com/ordergroove/plush-toys#readme",
@@ -43,7 +43,7 @@
43
43
  "throttle-debounce": "^2.1.0"
44
44
  },
45
45
  "devDependencies": {
46
- "@ordergroove/offers-templates": "^0.4.14"
46
+ "@ordergroove/offers-templates": "^0.4.15"
47
47
  },
48
- "gitHead": "5885ff1efc7aeb945e7b3bdbd3f9f13d943c6fbf"
48
+ "gitHead": "bfa13e68a501ae5898fe6aa8abaf745fcec9333d"
49
49
  }
@@ -36,7 +36,6 @@ export class FrequencyStatus extends withProduct(TemplateElement) {
36
36
  frequency: { type: String },
37
37
  defaultFrequency,
38
38
  productDefaultFrequency: { type: String },
39
- config: { type: Object },
40
39
  frequencies: {
41
40
  converter: {
42
41
  fromAttribute: parseFrequenciesList
@@ -94,7 +93,6 @@ export const mapStateToProps = (state, ownProps) => ({
94
93
  productDefaultFrequency: makeProductDefaultFrequencySelector((ownProps.product || {}).id)(state),
95
94
  configDefaultFrequency: state.config?.defaultFrequency,
96
95
  frequenciesText: state.config?.frequenciesText,
97
- config: state.config,
98
96
  ...configSelector(state, ownProps, 'frequencies'),
99
97
  ...configSelector(state, ownProps, 'defaultFrequency'),
100
98
  ...templatesSelector(state, ownProps)
@@ -16,11 +16,7 @@ export class OptinButton extends OptinStatus {
16
16
  }
17
17
 
18
18
  handleClick(ev) {
19
- this.optinProduct(
20
- resolveProduct(this),
21
- this.offer ? this.offer.defaultFrequency : this.defaultFrequency,
22
- this.offer
23
- );
19
+ this.optinProduct(resolveProduct(this), this.defaultFrequency, this.offer);
24
20
  ev.preventDefault();
25
21
  }
26
22
 
@@ -44,6 +44,7 @@ export class OptinStatus extends withProduct(TemplateElement) {
44
44
 
45
45
  .radio {
46
46
  text-indent: -9999px;
47
+ flex-shrink: 0;
47
48
  }
48
49
 
49
50
  .checkbox {
@@ -50,20 +50,13 @@ export class SelectFrequency extends withChildOptions(FrequencyStatus) {
50
50
 
51
51
  // default frequency comes from redux store first, then default option value, and then finally attribute value.
52
52
  get defaultFrequency() {
53
- const { options, isSelected } = this.childOptions;
54
-
55
- if (isSelected && this.frequencies?.length) {
56
- const ix = options.findIndex(it => it.value === isSelected) || 0;
57
- return this.frequencies[ix];
58
- }
59
-
60
53
  if (this.configDefaultFrequency) {
61
54
  return this.configDefaultFrequency;
62
55
  }
63
56
  if (this.productDefaultFrequency) {
64
57
  return this.productDefaultFrequency;
65
58
  }
66
-
59
+ const { options, isSelected } = this.childOptions;
67
60
  if (isSelected) {
68
61
  return isSelected;
69
62
  }
@@ -86,17 +79,14 @@ export class SelectFrequency extends withChildOptions(FrequencyStatus) {
86
79
 
87
80
  render() {
88
81
  let options;
89
- let defaultFrequency = this.defaultFrequency;
90
82
 
91
83
  if (this.frequencies?.length) {
92
- const { isSelected } = this.childOptions;
93
- if (isSelected && this.config.frequenciesEveryPeriod) {
94
- const index = this.config.frequenciesEveryPeriod.findIndex(it => it === isSelected);
95
- if (index >= 0) defaultFrequency = this.frequencies[index];
96
- }
97
84
  options = this.frequencies.map((value, ix) => ({
98
85
  value,
99
- text: frequencyText(this.config.frequenciesEveryPeriod[ix], defaultFrequency, this.defaultTest)
86
+ text:
87
+ this.frequenciesText && ix in this.frequenciesText
88
+ ? this.frequenciesText[ix]
89
+ : frequencyText(value, this.defaultFrequency)
100
90
  }));
101
91
  } else {
102
92
  ({ options } = this.childOptions);
@@ -105,17 +95,13 @@ export class SelectFrequency extends withChildOptions(FrequencyStatus) {
105
95
  if (!options.length) {
106
96
  options = (this.frequencies || []).map(value => ({
107
97
  value,
108
- text: frequencyText(value, defaultFrequency)
98
+ text: frequencyText(value, this.defaultFrequency)
109
99
  }));
110
100
  }
101
+ const defaultFrequency = this.defaultFrequency;
111
102
 
112
103
  options = options.map(({ text, value }) => ({
113
- text:
114
- value === defaultFrequency
115
- ? html`
116
- ${text} ${this.defaultText || ''}
117
- `
118
- : text,
104
+ text: value === defaultFrequency ? `${text} ${(this.defaultText || '').trim()}` : text,
119
105
  value
120
106
  }));
121
107
  return html`
@@ -52,7 +52,7 @@ export class UpsellModal extends withProduct(TemplateElement) {
52
52
  <slot name="every-label">
53
53
  <og-text key="offerEveryLabel"></og-text>
54
54
  </slot>
55
- <og-select-frequency default-frequency=${this.defaultFrequency}></og-select-frequency>
55
+ <og-select-frequency det{this.defaultFrequency}></og-select-frequency>
56
56
  </slot>
57
57
  </slot>
58
58
  </div>
@@ -1,4 +1,3 @@
1
- import { html, render } from 'lit-html';
2
1
  import { SelectFrequency, frequencyEquals } from '../SelectFrequency';
3
2
  import { simulateChange } from './utils';
4
3
 
@@ -16,26 +15,23 @@ describe('SelectFrequency', () => {
16
15
 
17
16
  it('should append default-text to selected frequency', async () => {
18
17
  const element = document.createElement(TAG_NAME_UNDER_TEST);
19
- element.setAttribute('default-text', ' (recommended)');
18
+ element.setAttribute('default-text', ' (recomended)');
20
19
  element.innerHTML = `
21
20
  <option value="optedOut">Buy one time</option>
22
21
  <option value="2w" selected>2 weeks</option>
23
22
  <option value="1m">1 month </option>
24
23
  `;
25
24
  document.body.appendChild(element);
25
+
26
26
  await element.updateComplete;
27
- await element.shadowRoot.querySelector('og-select').updateComplete;
28
27
  expect(element.shadowRoot.querySelector('og-select').shadowRoot.querySelector('select').value).toEqual('2_2');
29
28
  expect(element.shadowRoot.querySelector('og-select').shadowRoot.querySelector('select').selectedIndex).toEqual(1);
30
-
31
- // Comment this since returns [object Object] only in unit-test.
32
- // const result = element.shadowRoot
33
- // .querySelector('og-select')
34
- // .shadowRoot.querySelector('select')
35
- // .options[1].innerText.trim();
36
-
37
- // expect(result).toContain('2 weeks');
38
- // expect(result).toContain('(recommended)');
29
+ expect(
30
+ element.shadowRoot
31
+ .querySelector('og-select')
32
+ .shadowRoot.querySelector('select')
33
+ .options[1].innerText.trim()
34
+ ).toEqual('2 weeks (recomended)');
39
35
  });
40
36
 
41
37
  it('should use clicked frequency given default frequency and no product-specfic default frequency', () => {
@@ -8,8 +8,7 @@ import {
8
8
  offerId,
9
9
  optedin,
10
10
  productOffer,
11
- productPlans,
12
- textToFreq
11
+ productPlans
13
12
  } from '../shopifyReducer';
14
13
 
15
14
  describe('autoshipEligible', () => {
@@ -485,26 +484,3 @@ describe('productPlans', () => {
485
484
  expect(actual).toEqual({ 'yum existing key': 'yum existing value' });
486
485
  });
487
486
  });
488
-
489
- describe('textToFreq', () => {
490
- it('textToFreq should return freq', () => {
491
- expect(textToFreq('DAY')).toEqual('1_1');
492
- expect(textToFreq('DAYS')).toEqual('1_1');
493
- expect(textToFreq('DAYLY')).toEqual('1_1');
494
- expect(textToFreq('1 DAY')).toEqual('1_1');
495
- expect(textToFreq('2 DAYS')).toEqual('2_1');
496
- expect(textToFreq('2 day(s)')).toEqual('2_1');
497
-
498
- expect(textToFreq('week')).toEqual('1_2');
499
- expect(textToFreq('weekly')).toEqual('1_2');
500
- expect(textToFreq('1 week')).toEqual('1_2');
501
- expect(textToFreq('2 weeks')).toEqual('2_2');
502
- expect(textToFreq('2 week(s)')).toEqual('2_2');
503
-
504
- expect(textToFreq('MONTH')).toEqual('1_3');
505
- expect(textToFreq('MONTHLY')).toEqual('1_3');
506
- expect(textToFreq('1 month')).toEqual('1_3');
507
- expect(textToFreq('2 months')).toEqual('2_3');
508
- expect(textToFreq('2 month(s)')).toEqual('2_3');
509
- });
510
- });
@@ -99,15 +99,6 @@ 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
-
111
102
  export const config = (
112
103
  state = {
113
104
  frequencies: [],
@@ -134,15 +125,10 @@ export const config = (
134
125
  const sellingPlanGroup = getOGSellingPlanGroup(product);
135
126
  const frequencies = sellingPlanGroup?.selling_plans?.map(({ id }) => `${id}`);
136
127
  if (frequencies?.length) {
137
- const frequenciesEveryPeriod = sellingPlanGroup?.selling_plans
138
- ?.map(({ options }) => options || [])
139
- .flat()
140
- .map(({ value }) => textToFreq(value));
141
128
  const frequenciesText = sellingPlanGroup.options?.[0]?.values || frequencies;
142
129
  return {
143
130
  ...state,
144
131
  defaultFrequency: frequencies[0],
145
- frequenciesEveryPeriod,
146
132
  frequencies,
147
133
  frequenciesText
148
134
  };