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);
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);
23 it('should not add anything to the link', () => {
24 const link = '/myLink';
25 expect(addUpsellPath(link, undefined)).toEqual(link);
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}`
36 it('should generate expected upsell ref with app, feature and component', () => {
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}`);
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`
48 it('should generate expected upsell ref with app, feature, component and settings', () => {
51 app: APP_UPSELL_REF_PATH.MAIL_UPSELL_REF_PATH,
52 component: UPSELL_COMPONENT.BANNER,
56 ).toEqual(`${APP_UPSELL_REF_PATH.MAIL_UPSELL_REF_PATH}${UPSELL_COMPONENT.BANNER}${feature}_settings`);
60 describe('getUpsellRefFromApp', () => {
61 it('should generate the expected upsell ref', () => {
63 expect(getUpsellRefFromApp({ app: APPS.PROTONMAIL, feature })).toEqual(
64 `${APP_UPSELL_REF_PATH.MAIL_UPSELL_REF_PATH}${feature}`
67 expect(getUpsellRefFromApp({ app: APPS.PROTONCALENDAR, feature })).toEqual(
68 `${APP_UPSELL_REF_PATH.CALENDAR_UPSELL_REF_PATH}${feature}`
71 expect(getUpsellRefFromApp({ app: APPS.PROTONDRIVE, feature })).toEqual(
72 `${APP_UPSELL_REF_PATH.DRIVE_UPSELL_REF_PATH}${feature}`
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`
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`
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`
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`