1 import getBackLink from './getBackLink';
3 describe('getBackLink', () => {
4 test('throws error if href is not a valid url', () => {
8 hostname: 'account.proton.me',
13 test('throws error if href hostname is not the same as hostname', () => {
16 backHref: 'https://straightouttacrompton.dev',
17 hostname: 'account.proton.me',
22 describe('href', () => {
23 test('returns href if backHref has the same hostname as provided hostname', () => {
24 const result = getBackLink({
25 backHref: 'https://account.proton.me/asdf',
26 hostname: 'account.proton.me',
29 expect(result.href).toEqual('https://account.proton.me/asdf');
33 describe('to', () => {
34 test('returns no empty to if pathname is empty', () => {
35 const result = getBackLink({
36 backHref: 'https://account.proton.me',
37 hostname: 'account.proton.me',
40 expect(result.to).toEqual('/');
43 test('returns to if backHref has the same hostname as provided hostname', () => {
44 const result = getBackLink({
45 backHref: 'https://account.proton.me/asdf',
46 hostname: 'account.proton.me',
49 expect(result.to).toEqual('/asdf');
52 test('strips local basename from path', () => {
53 const result = getBackLink({
54 backHref: 'https://account.proton.me/u/0/asdf',
55 hostname: 'account.proton.me',
58 expect(result.to).toEqual('/asdf');
62 describe('appNameFromHostname', () => {
63 test('returns undefined appNameFromHostname for account hostname', () => {
64 const result = getBackLink({
65 backHref: 'https://account.proton.me',
66 hostname: 'account.proton.me',
69 expect(result.appNameFromHostname).toEqual(undefined);
72 test('returns undefined appNameFromHostname if hostname application is not in ALLOWED_APPS', () => {
73 const result = getBackLink({
74 backHref: 'https://verify.proton.me',
75 hostname: 'verify.proton.me',
78 expect(result.appNameFromHostname).toEqual(undefined);
81 test('returns correct appNameFromHostname if hostname application is in ALLOWED_APPS', () => {
82 const result = getBackLink({
83 backHref: 'https://mail.proton.me',
84 hostname: 'mail.proton.me',
87 expect(result.appNameFromHostname).toEqual('proton-mail');
91 describe('appName', () => {
92 test('returns undefined appName for account hostname', () => {
93 const result = getBackLink({
94 backHref: 'https://account.proton.me',
95 hostname: 'account.proton.me',
98 expect(result.appName).toEqual(undefined);
101 test('returns undefined appName if hostname application is not in ALLOWED_APPS', () => {
102 const result = getBackLink({
103 backHref: 'https://verify.proton.me',
104 hostname: 'verify.proton.me',
107 expect(result.appName).toEqual(undefined);
110 test('returns correct appName if hostname application is in ALLOWED_APPS', () => {
111 const result = getBackLink({
112 backHref: 'https://mail.proton.me',
113 hostname: 'mail.proton.me',
116 expect(result.appName).toEqual('proton-mail');
119 test('prioritises hostname app over pathname app', () => {
120 const result = getBackLink({
121 backHref: 'https://mail.proton.me/calendar',
122 hostname: 'mail.proton.me',
125 expect(result.appName).toEqual('proton-mail');
128 test('returns undefined appName if pathname application is not in ALLOWED_APPS', () => {
129 const result = getBackLink({
130 backHref: 'https://account.proton.me/verify',
131 hostname: 'account.proton.me',
134 expect(result.appName).toEqual(undefined);
137 test('returns correct appName if hostname application is in ALLOWED_APPS', () => {
138 const result = getBackLink({
139 backHref: 'https://account.proton.me/mail',
140 hostname: 'account.proton.me',
143 expect(result.appName).toEqual('proton-mail');
146 test('returns correct appName if local basename included', () => {
147 const result = getBackLink({
148 backHref: 'https://account.proton.me/u/0/mail',
149 hostname: 'account.proton.me',
152 expect(result.appName).toEqual('proton-mail');