import React from 'react';
import { render, fireEvent, act } from '@testing-library/react';
import { useBulkActions } from '../../../src/static/js/utils/hooks/useBulkActions';
// Mock translateString to return the input for easier assertions
jest.mock('../../../src/static/js/utils/helpers', () => ({
translateString: (s: string) => s,
}));
// Component that exposes hook state/handlers to DOM for testing
function HookConsumer() {
const hook = useBulkActions();
return (
{Array.from(hook.selectedMedia).length}
{hook.availableMediaIds.length}
{String(hook.showConfirmModal)}
{hook.confirmMessage}
{hook.listKey}
{hook.notificationMessage}
{String(hook.showNotification)}
{/* @todo: It doesn't used */}
{/*
{hook.notificationType}
*/}
{String(hook.showPermissionModal)}
{hook.permissionType || ''}
{String(hook.showPlaylistModal)}
{String(hook.showChangeOwnerModal)}
{String(hook.showPublishStateModal)}
{String(hook.showCategoryModal)}
{String(hook.showTagModal)}
);
}
describe('useBulkActions', () => {
beforeEach(() => {
jest.clearAllMocks();
document.cookie.split(';').forEach((c) => {
document.cookie = c.replace(/^ +/, '').replace(/=.*/, '=;expires=' + new Date().toUTCString() + ';path=/');
});
global.fetch = jest.fn();
jest.useFakeTimers();
});
afterEach(() => {
jest.useRealTimers();
});
describe('Utility Functions', () => {
test('getCsrfToken reads csrftoken from cookies', () => {
document.cookie = 'csrftoken=abc123';
const { getByTestId } = render(