2026-04-21 14:51:38 -04:00
|
|
|
import '@testing-library/jest-dom';
|
2026-02-05 12:01:54 +01:00
|
|
|
import { getResizeObserverMock } from '$lib/__mocks__/resize-observer.mock';
|
2026-04-14 08:49:24 -04:00
|
|
|
import { authManager } from '$lib/managers/auth-manager.svelte';
|
2026-01-05 14:51:03 -05:00
|
|
|
import { renderWithTooltips } from '$tests/helpers';
|
2024-06-09 01:33:39 +05:30
|
|
|
import { assetFactory } from '@test-data/factories/asset-factory';
|
2025-05-28 15:57:36 -05:00
|
|
|
import { preferencesFactory } from '@test-data/factories/preferences-factory';
|
2024-06-09 01:33:39 +05:30
|
|
|
import { userAdminFactory } from '@test-data/factories/user-factory';
|
2026-04-21 17:29:42 +01:00
|
|
|
import AssetViewerNavBar from './AssetViewerNavBar.svelte';
|
2024-06-09 01:33:39 +05:30
|
|
|
|
2026-07-10 14:30:12 +02:00
|
|
|
vi.mock(import('$lib/managers/feature-flags-manager.svelte'), function () {
|
|
|
|
|
return {
|
|
|
|
|
featureFlagsManager: {
|
|
|
|
|
init: vi.fn(),
|
|
|
|
|
loadFeatureFlags: vi.fn(),
|
|
|
|
|
value: { smartSearch: true, trash: true },
|
|
|
|
|
} as never,
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
2024-06-09 01:33:39 +05:30
|
|
|
describe('AssetViewerNavBar component', () => {
|
|
|
|
|
const additionalProps = {
|
2025-05-17 22:57:08 -04:00
|
|
|
preAction: () => {},
|
2024-11-02 16:49:07 +01:00
|
|
|
onAction: () => {},
|
|
|
|
|
onPlaySlideshow: () => {},
|
|
|
|
|
onClose: () => {},
|
2026-01-05 14:51:03 -05:00
|
|
|
playOriginalVideo: false,
|
|
|
|
|
setPlayOriginalVideo: () => Promise.resolve(),
|
2024-06-09 01:33:39 +05:30
|
|
|
};
|
|
|
|
|
|
2024-11-02 16:49:07 +01:00
|
|
|
beforeAll(() => {
|
2026-03-04 15:19:13 +01:00
|
|
|
Element.prototype.animate = vi.fn().mockImplementation(function () {
|
|
|
|
|
return {
|
|
|
|
|
cancel: () => {},
|
|
|
|
|
};
|
|
|
|
|
});
|
2026-02-05 12:01:54 +01:00
|
|
|
vi.stubGlobal('ResizeObserver', getResizeObserverMock());
|
2024-11-02 16:49:07 +01:00
|
|
|
});
|
|
|
|
|
|
2024-06-09 01:33:39 +05:30
|
|
|
afterEach(() => {
|
2026-04-14 08:49:24 -04:00
|
|
|
authManager.reset();
|
2024-06-09 01:33:39 +05:30
|
|
|
});
|
|
|
|
|
|
2024-11-02 16:49:07 +01:00
|
|
|
afterAll(() => {
|
|
|
|
|
vi.restoreAllMocks();
|
|
|
|
|
});
|
|
|
|
|
|
2024-06-09 01:33:39 +05:30
|
|
|
it('shows back button', () => {
|
2026-04-14 08:49:24 -04:00
|
|
|
const preferences = preferencesFactory.build({ cast: { gCastEnabled: false } });
|
|
|
|
|
authManager.setPreferences(preferences);
|
2025-05-28 15:57:36 -05:00
|
|
|
|
2024-06-09 01:33:39 +05:30
|
|
|
const asset = assetFactory.build({ isTrashed: false });
|
2026-01-05 14:51:03 -05:00
|
|
|
const { getByLabelText } = renderWithTooltips(AssetViewerNavBar, { asset, ...additionalProps });
|
|
|
|
|
expect(getByLabelText('go_back')).toBeInTheDocument();
|
2024-06-09 01:33:39 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('if the current user owns the asset', () => {
|
|
|
|
|
it('shows delete button', () => {
|
|
|
|
|
const ownerId = 'id-of-the-user';
|
|
|
|
|
const user = userAdminFactory.build({ id: ownerId });
|
|
|
|
|
const asset = assetFactory.build({ ownerId, isTrashed: false });
|
2026-04-14 08:49:24 -04:00
|
|
|
authManager.setUser(user);
|
2025-05-28 15:57:36 -05:00
|
|
|
|
2026-04-14 08:49:24 -04:00
|
|
|
const preferences = preferencesFactory.build({ cast: { gCastEnabled: false } });
|
|
|
|
|
authManager.setPreferences(preferences);
|
2025-05-28 15:57:36 -05:00
|
|
|
|
2026-01-05 14:51:03 -05:00
|
|
|
const { getByLabelText } = renderWithTooltips(AssetViewerNavBar, { asset, ...additionalProps });
|
|
|
|
|
expect(getByLabelText('delete')).toBeInTheDocument();
|
2024-06-09 01:33:39 +05:30
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|