@capillarytech/creatives-library 8.0.248 → 8.0.249

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.
@@ -23,8 +23,9 @@ describe('createWebPushPayload', () => {
23
23
  brandIconSrc: '',
24
24
  brandIconUrl: '',
25
25
  buttons: [],
26
- onClickBehaviour: ON_CLICK_BEHAVIOUR_OPTIONS.OPEN_SITE,
26
+ onClickBehaviour: ON_CLICK_BEHAVIOUR_OPTIONS.SITE_URL,
27
27
  redirectUrl: '',
28
+ websiteLink: 'https://example.com',
28
29
  };
29
30
 
30
31
  describe('Basic Payload Structure', () => {
@@ -44,7 +45,8 @@ describe('createWebPushPayload', () => {
44
45
  title: 'Test Title',
45
46
  message: 'Test Message',
46
47
  onClickAction: {
47
- type: ACTION_TYPES.OPEN_SITE,
48
+ type: ACTION_TYPES.SITE_URL,
49
+ url: 'https://example.com',
48
50
  },
49
51
  },
50
52
  },
@@ -221,14 +223,16 @@ describe('createWebPushPayload', () => {
221
223
  expect(payload.versions.base.content.webpush.onClickAction.url).toBe('https://example.com');
222
224
  });
223
225
 
224
- it('should include onClickAction with OPEN_SITE type when OPEN_SITE is selected', () => {
226
+ it('should include onClickAction with SITE_URL type when SITE_URL is selected', () => {
225
227
  const payload = createWebPushPayload({
226
228
  ...defaultParams,
227
- onClickBehaviour: ON_CLICK_BEHAVIOUR_OPTIONS.OPEN_SITE,
229
+ onClickBehaviour: ON_CLICK_BEHAVIOUR_OPTIONS.SITE_URL,
230
+ websiteLink: 'https://example.com',
228
231
  });
229
232
 
230
233
  expect(payload.versions.base.content.webpush.onClickAction).toEqual({
231
- type: ACTION_TYPES.OPEN_SITE,
234
+ type: ACTION_TYPES.SITE_URL,
235
+ url: 'https://example.com',
232
236
  });
233
237
  });
234
238
 
@@ -370,8 +374,9 @@ describe('createWebPushPayload', () => {
370
374
  brandIconSrc: '',
371
375
  brandIconUrl: '',
372
376
  buttons: [],
373
- onClickBehaviour: ON_CLICK_BEHAVIOUR_OPTIONS.OPEN_SITE,
377
+ onClickBehaviour: ON_CLICK_BEHAVIOUR_OPTIONS.SITE_URL,
374
378
  redirectUrl: '',
379
+ websiteLink: 'https://example.com',
375
380
  });
376
381
 
377
382
  expect(payload.name).toBe('');
@@ -381,7 +386,8 @@ describe('createWebPushPayload', () => {
381
386
  expect(payload.versions.base.content.webpush.image).toBeUndefined();
382
387
  expect(payload.versions.base.content.webpush.brandIcon).toBeUndefined();
383
388
  expect(payload.versions.base.content.webpush.onClickAction).toEqual({
384
- type: ACTION_TYPES.OPEN_SITE,
389
+ type: ACTION_TYPES.SITE_URL,
390
+ url: 'https://example.com',
385
391
  });
386
392
  expect(payload.versions.base.content.webpush.ctas).toBeUndefined();
387
393
  });
@@ -79,14 +79,14 @@ export const WEBPUSH_BUTTON_TYPES = {
79
79
 
80
80
  // OnClick Behaviour Options
81
81
  export const ON_CLICK_BEHAVIOUR_OPTIONS = {
82
- OPEN_SITE: 'OPEN_SITE',
82
+ SITE_URL: 'SITE_URL',
83
83
  REDIRECT_TO_URL: 'REDIRECT_TO_URL',
84
84
  };
85
85
 
86
86
  // Action Types
87
87
  export const ACTION_TYPES = {
88
88
  URL: 'URL',
89
- OPEN_SITE: 'OPEN_SITE',
89
+ SITE_URL: 'SITE_URL',
90
90
  };
91
91
 
92
92
  // WebPush Content Field Names
@@ -126,3 +126,7 @@ export const TLD_PATTERN = /^https?:\/\/[^/?#:]+\.\w{2,}(?:\/|$|\?|#|:)/i;
126
126
  // Utility Constants
127
127
  // Stable empty array to prevent unnecessary re-renders when used as default prop values
128
128
  export const EMPTY_ARRAY = [];
129
+
130
+ export const EXTERNAL_URL = 'EXTERNAL_URL';
131
+ export const SITE_URL = 'SITE_URL';
132
+ export const URL = 'URL';
@@ -839,5 +839,122 @@ describe('WebPush selectors', () => {
839
839
  });
840
840
  });
841
841
  });
842
+
843
+ describe('accountData selector (from templates state)', () => {
844
+ // This tests the accountData selector logic used in mapStateToProps
845
+ const createAccountDataSelector = () => {
846
+ return (state) => {
847
+ const templatesState = state.get('templates');
848
+ if (!templatesState) {
849
+ return {};
850
+ }
851
+ const templates = templatesState.toJS();
852
+ return templates?.selectedWebPushAccount || {};
853
+ };
854
+ };
855
+
856
+ it.concurrent('should select selectedWebPushAccount from templates state', () => {
857
+ const mockTemplatesState = fromJS({
858
+ selectedWebPushAccount: {
859
+ id: 123,
860
+ accountId: 123,
861
+ name: 'Test WebPush Account',
862
+ configs: {
863
+ websiteLink: 'https://example.com',
864
+ },
865
+ },
866
+ });
867
+
868
+ const mockState = fromJS({
869
+ templates: mockTemplatesState,
870
+ });
871
+
872
+ const selector = createAccountDataSelector();
873
+ const result = selector(mockState);
874
+
875
+ expect(result).toEqual({
876
+ id: 123,
877
+ accountId: 123,
878
+ name: 'Test WebPush Account',
879
+ configs: {
880
+ websiteLink: 'https://example.com',
881
+ },
882
+ });
883
+ });
884
+
885
+ it.concurrent('should return empty object when templates state does not exist', () => {
886
+ const mockState = fromJS({
887
+ otherState: { value: 'test' },
888
+ });
889
+
890
+ const selector = createAccountDataSelector();
891
+ const result = selector(mockState);
892
+
893
+ expect(result).toEqual({});
894
+ });
895
+
896
+ it.concurrent('should return empty object when selectedWebPushAccount does not exist', () => {
897
+ const mockTemplatesState = fromJS({
898
+ weCrmAccounts: [],
899
+ templates: [],
900
+ });
901
+
902
+ const mockState = fromJS({
903
+ templates: mockTemplatesState,
904
+ });
905
+
906
+ const selector = createAccountDataSelector();
907
+ const result = selector(mockState);
908
+
909
+ expect(result).toEqual({});
910
+ });
911
+
912
+ it.concurrent('should handle selectedWebPushAccount with websiteLink in configs', () => {
913
+ const mockTemplatesState = fromJS({
914
+ selectedWebPushAccount: {
915
+ id: 456,
916
+ accountId: 456,
917
+ name: 'Account with Website',
918
+ configs: {
919
+ websiteLink: 'https://test.com',
920
+ otherConfig: 'value',
921
+ },
922
+ },
923
+ });
924
+
925
+ const mockState = fromJS({
926
+ templates: mockTemplatesState,
927
+ });
928
+
929
+ const selector = createAccountDataSelector();
930
+ const result = selector(mockState);
931
+
932
+ expect(result.configs.websiteLink).toBe('https://test.com');
933
+ expect(result.id).toBe(456);
934
+ });
935
+
936
+ it.concurrent('should handle selectedWebPushAccount without websiteLink', () => {
937
+ const mockTemplatesState = fromJS({
938
+ selectedWebPushAccount: {
939
+ id: 789,
940
+ accountId: 789,
941
+ name: 'Account without Website',
942
+ configs: {
943
+ otherConfig: 'value',
944
+ },
945
+ },
946
+ });
947
+
948
+ const mockState = fromJS({
949
+ templates: mockTemplatesState,
950
+ });
951
+
952
+ const selector = createAccountDataSelector();
953
+ const result = selector(mockState);
954
+
955
+ expect(result.configs.websiteLink).toBeUndefined();
956
+ expect(result.id).toBe(789);
957
+ });
958
+ });
842
959
  });
843
960