1 import localStorageWithExpiry from '@proton/shared/lib/api/helpers/localStorageWithExpiry';
4 PUBLIC_SHARE_REDIRECT_PASSWORD_STORAGE_KEY,
5 deleteStoredUrlPassword,
7 saveUrlPasswordForRedirection,
10 describe('URL Password Functions', () => {
12 deleteStoredUrlPassword();
16 describe('deleteStoredUrlPassword', () => {
17 it('should remove password from localStorage', () => {
18 localStorageWithExpiry.storeData(PUBLIC_SHARE_REDIRECT_PASSWORD_STORAGE_KEY, 'testPassword');
19 expect(getUrlPassword()).toBe('testPassword');
20 deleteStoredUrlPassword();
21 window.location.hash = '';
22 expect(getUrlPassword()).toBe('');
26 describe('saveUrlPasswordForRedirection', () => {
27 it('should save password for redirection', () => {
28 const password = 'testPassword123';
29 saveUrlPasswordForRedirection(password);
30 expect(getUrlPassword()).toBe('testPassword123');
34 describe('getUrlPassword', () => {
35 it('should return password from URL hash if present', () => {
36 window.location.hash = '#testPassword';
37 expect(getUrlPassword()).toBe('testPassword');
40 it('should return password from localStorage if URL hash is empty', () => {
41 window.location.hash = '';
42 localStorageWithExpiry.storeData(PUBLIC_SHARE_REDIRECT_PASSWORD_STORAGE_KEY, 'storedPassword');
43 expect(getUrlPassword()).toBe('storedPassword');
44 expect(window.location.hash).toBe('#storedPassword');
47 it('should return empty string if both URL hash and localStorage are empty', () => {
48 window.location.hash = '';
49 expect(getUrlPassword()).toBe('');
50 expect(window.location.hash).toBe('');