1 import { act, renderHook } from '@testing-library/react-hooks';
3 import type { Share } from './interface';
4 import { ShareState, ShareType } from './interface';
5 import { useSharesStateProvider } from './useSharesState';
7 function createTestShare(
13 isVolumeSoftDeleted: false,
14 type: ShareType.standard,
15 state: ShareState.active,
24 possibleKeyPackets: [],
29 describe('useSharesState', () => {
31 current: ReturnType<typeof useSharesStateProvider>;
34 const mainShare1 = createTestShare('mainShare1', 'volume1', {
37 isVolumeSoftDeleted: false,
38 type: ShareType.default,
39 state: ShareState.active,
41 const device1 = createTestShare('device1', 'volume1', {
44 isVolumeSoftDeleted: false,
45 type: ShareType.device,
46 state: ShareState.active,
48 const device2 = createTestShare('device2', 'volume1', {
51 isVolumeSoftDeleted: false,
52 type: ShareType.device,
53 state: ShareState.active,
55 const share1 = createTestShare('share1', 'volume1', {
58 isVolumeSoftDeleted: false,
59 type: ShareType.standard,
60 state: ShareState.active,
62 const mainShare2 = createTestShare('mainShare2', 'volume2', {
65 isVolumeSoftDeleted: false,
66 type: ShareType.default,
67 state: ShareState.active,
69 const device3 = createTestShare('device3', 'volume2', {
72 isVolumeSoftDeleted: false,
73 type: ShareType.device,
74 state: ShareState.active,
76 const share2 = createTestShare('share2', 'volume2', {
79 isVolumeSoftDeleted: false,
80 type: ShareType.standard,
81 state: ShareState.active,
83 const mainShare3 = createTestShare('mainShare3', 'volume3', {
86 isVolumeSoftDeleted: false,
87 type: ShareType.default,
88 state: ShareState.active,
90 const device4 = createTestShare('device4', 'volume3', {
93 isVolumeSoftDeleted: false,
94 type: ShareType.device,
95 state: ShareState.active,
97 const mainShare4 = createTestShare('mainShare4', 'volume4', {
100 isVolumeSoftDeleted: true,
101 type: ShareType.default,
102 state: ShareState.active,
104 const device5 = createTestShare('device5', 'volume4', {
107 isVolumeSoftDeleted: true,
108 type: ShareType.device,
109 state: ShareState.active,
113 jest.resetAllMocks();
115 const { result } = renderHook(() => useSharesStateProvider());
119 hook.current.setShares([
135 it('returns only locked undeleted shares with its devices', async () => {
136 const lockedShares = hook.current.getLockedShares();
137 expect(lockedShares).toMatchObject([
139 defaultShare: mainShare1,
140 devices: [device1, device2],
143 defaultShare: mainShare2,