Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / packages / shared / test / upsell / upsell.spec.ts
blobff81ff2931c8e8bda6f52289c261e03c8af651d1
1 import { APPS, APP_UPSELL_REF_PATH, SHARED_UPSELL_PATHS, UPSELL_COMPONENT } from '@proton/shared/lib/constants';
2 import { addUpsellPath, getUpsellRef, getUpsellRefFromApp } from '@proton/shared/lib/helpers/upsell';
4 const feature = SHARED_UPSELL_PATHS.STORAGE;
6 describe('addUpsellPath', () => {
7     it('should add the upsell path to the link', () => {
8         const link = '/myLink';
9         const upsellPath = 'myUpsellPath';
11         const expected = `${link}?ref=${upsellPath}`;
12         expect(addUpsellPath(link, upsellPath)).toEqual(expected);
13     });
15     it('should add the upsell path in a new param to the link', function () {
16         const link = '/myLink?something=1';
17         const upsellPath = 'myUpsellPath';
19         const expected = `${link}&ref=${upsellPath}`;
20         expect(addUpsellPath(link, upsellPath)).toEqual(expected);
21     });
23     it('should not add anything to the link', () => {
24         const link = '/myLink';
25         expect(addUpsellPath(link, undefined)).toEqual(link);
26     });
27 });
29 describe('getUpsellRef', () => {
30     it('should generate expected upsell ref with app and feature', () => {
31         expect(getUpsellRef({ app: APP_UPSELL_REF_PATH.MAIL_UPSELL_REF_PATH, feature })).toEqual(
32             `${APP_UPSELL_REF_PATH.MAIL_UPSELL_REF_PATH}${feature}`
33         );
34     });
36     it('should generate expected upsell ref with app, feature and component', () => {
37         expect(
38             getUpsellRef({ app: APP_UPSELL_REF_PATH.MAIL_UPSELL_REF_PATH, component: UPSELL_COMPONENT.BANNER, feature })
39         ).toEqual(`${APP_UPSELL_REF_PATH.MAIL_UPSELL_REF_PATH}${UPSELL_COMPONENT.BANNER}${feature}`);
40     });
42     it('should generate expected upsell ref with app, feature and settings', () => {
43         expect(getUpsellRef({ app: APP_UPSELL_REF_PATH.MAIL_UPSELL_REF_PATH, feature, isSettings: true })).toEqual(
44             `${APP_UPSELL_REF_PATH.MAIL_UPSELL_REF_PATH}${feature}_settings`
45         );
46     });
48     it('should generate expected upsell ref with app, feature, component and settings', () => {
49         expect(
50             getUpsellRef({
51                 app: APP_UPSELL_REF_PATH.MAIL_UPSELL_REF_PATH,
52                 component: UPSELL_COMPONENT.BANNER,
53                 feature,
54                 isSettings: true,
55             })
56         ).toEqual(`${APP_UPSELL_REF_PATH.MAIL_UPSELL_REF_PATH}${UPSELL_COMPONENT.BANNER}${feature}_settings`);
57     });
58 });
60 describe('getUpsellRefFromApp', () => {
61     it('should generate the expected upsell ref', () => {
62         // Open from mail
63         expect(getUpsellRefFromApp({ app: APPS.PROTONMAIL, feature })).toEqual(
64             `${APP_UPSELL_REF_PATH.MAIL_UPSELL_REF_PATH}${feature}`
65         );
66         // Open from calendar
67         expect(getUpsellRefFromApp({ app: APPS.PROTONCALENDAR, feature })).toEqual(
68             `${APP_UPSELL_REF_PATH.CALENDAR_UPSELL_REF_PATH}${feature}`
69         );
70         // Open from drive
71         expect(getUpsellRefFromApp({ app: APPS.PROTONDRIVE, feature })).toEqual(
72             `${APP_UPSELL_REF_PATH.DRIVE_UPSELL_REF_PATH}${feature}`
73         );
74         // Open from mail settings
75         expect(getUpsellRefFromApp({ app: APPS.PROTONACCOUNT, feature, fromApp: APPS.PROTONMAIL })).toEqual(
76             `${APP_UPSELL_REF_PATH.MAIL_UPSELL_REF_PATH}${feature}_settings`
77         );
78         // Open from calendar settings
79         expect(getUpsellRefFromApp({ app: APPS.PROTONACCOUNT, feature, fromApp: APPS.PROTONCALENDAR })).toEqual(
80             `${APP_UPSELL_REF_PATH.CALENDAR_UPSELL_REF_PATH}${feature}_settings`
81         );
82         // Open from drive settings
83         expect(getUpsellRefFromApp({ app: APPS.PROTONACCOUNT, feature, fromApp: APPS.PROTONDRIVE })).toEqual(
84             `${APP_UPSELL_REF_PATH.DRIVE_UPSELL_REF_PATH}${feature}_settings`
85         );
86         // Open from vpn settings
87         expect(getUpsellRefFromApp({ app: APPS.PROTONACCOUNT, feature, fromApp: APPS.PROTONVPN_SETTINGS })).toEqual(
88             `${APP_UPSELL_REF_PATH.VPN_UPSELL_REF_PATH}${feature}_settings`
89         );
90     });
91 });