Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / applications / drive / src / app / utils / url / password.test.ts
blob57caeab78c086533f865d3d2642b85908552d0ab
1 import localStorageWithExpiry from '@proton/shared/lib/api/helpers/localStorageWithExpiry';
3 import {
4     PUBLIC_SHARE_REDIRECT_PASSWORD_STORAGE_KEY,
5     deleteStoredUrlPassword,
6     getUrlPassword,
7     saveUrlPasswordForRedirection,
8 } from './password';
10 describe('URL Password Functions', () => {
11     afterEach(() => {
12         deleteStoredUrlPassword();
13         jest.clearAllMocks();
14     });
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('');
23         });
24     });
26     describe('saveUrlPasswordForRedirection', () => {
27         it('should save password for redirection', () => {
28             const password = 'testPassword123';
29             saveUrlPasswordForRedirection(password);
30             expect(getUrlPassword()).toBe('testPassword123');
31         });
32     });
34     describe('getUrlPassword', () => {
35         it('should return password from URL hash if present', () => {
36             window.location.hash = '#testPassword';
37             expect(getUrlPassword()).toBe('testPassword');
38         });
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');
45         });
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('');
51         });
52     });
53 });