mirror of
https://github.com/mediacms-io/mediacms.git
synced 2026-03-22 20:43:10 -04:00
chore: minor code enhancements
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
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
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import React from 'react';
|
||||
import { render } from '@testing-library/react';
|
||||
|
||||
import { useItem } from '../../../src/static/js/utils/hooks/useItem';
|
||||
|
||||
// Mock the item components
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import React, { createRef } from 'react';
|
||||
import { render } from '@testing-library/react';
|
||||
|
||||
import initItemsList from '../../../src/static/js/components/item-list/includes/itemLists/initItemsList';
|
||||
import { useItemList } from '../../../src/static/js/utils/hooks/useItemList';
|
||||
|
||||
// Stub style imports used by the hook so Jest doesn't try to parse SCSS
|
||||
jest.mock('../../../src/static/js/components/item-list/ItemList.scss', () => ({}), { virtual: true });
|
||||
|
||||
@@ -9,9 +12,6 @@ jest.mock('../../../src/static/js/components/item-list/includes/itemLists/initIt
|
||||
default: jest.fn((_lists: any[]) => [{ appendItems: jest.fn() }]),
|
||||
}));
|
||||
|
||||
import initItemsList from '../../../src/static/js/components/item-list/includes/itemLists/initItemsList';
|
||||
import { useItemList } from '../../../src/static/js/utils/hooks/useItemList';
|
||||
|
||||
function HookConsumer(props: any) {
|
||||
const listRef = createRef<HTMLDivElement>();
|
||||
const [items, countedItems, listHandler, setListHandler, onItemsLoad, onItemsCount, addListItems] = useItemList(
|
||||
@@ -32,7 +32,7 @@ function HookConsumer(props: any) {
|
||||
<button data-testid="count-call" onClick={() => onItemsCount(5)} />
|
||||
<button data-testid="add-call" onClick={() => addListItems()} />
|
||||
<button data-testid="set-handler" onClick={() => setListHandler({ foo: 'bar' })} />
|
||||
<div data-testid="has-handler">{listHandler ? 'yes' : 'no'}</div>
|
||||
<div data-testid="has-handler">{listHandler ? 'yes' : 'no'}</div>f
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,25 +1,21 @@
|
||||
import React from 'react';
|
||||
import { render, fireEvent, act } from '@testing-library/react';
|
||||
import { render, fireEvent } from '@testing-library/react';
|
||||
|
||||
import { useItemListInlineSlider } from '../../../src/static/js/utils/hooks/useItemListInlineSlider';
|
||||
|
||||
let mockListHandler: any;
|
||||
let mockInlineSliderInstance: any;
|
||||
let addListItemsSpy = jest.fn();
|
||||
|
||||
jest.mock('../../../src/static/js/utils/settings/config', () => ({
|
||||
config: jest.fn(() => jest.requireActual('../../tests-constants').sampleMediaCMSConfig),
|
||||
}));
|
||||
|
||||
jest.mock('../../../src/static/js/utils/classes/', () => ({
|
||||
BrowserCache: jest.fn().mockImplementation(() => ({
|
||||
get: jest.fn(),
|
||||
set: jest.fn(),
|
||||
})),
|
||||
BrowserCache: jest.fn().mockImplementation(() => ({ get: jest.fn(), set: jest.fn() })),
|
||||
}));
|
||||
|
||||
jest.mock('../../../src/static/js/utils/helpers/', () => ({
|
||||
addClassname: jest.fn(),
|
||||
removeClassname: jest.fn(),
|
||||
}));
|
||||
|
||||
let mockListHandler: any;
|
||||
let mockInlineSliderInstance: any;
|
||||
let addListItemsSpy = jest.fn();
|
||||
jest.mock('../../../src/static/js/utils/helpers/', () => ({ addClassname: jest.fn(), removeClassname: jest.fn() }));
|
||||
|
||||
jest.mock('../../../src/static/js/utils/hooks/useItemList', () => ({
|
||||
useItemList: (props: any, _ref: any) => {
|
||||
@@ -66,8 +62,6 @@ jest.mock('../../../src/static/js/components/_shared', () => ({
|
||||
),
|
||||
}));
|
||||
|
||||
import { useItemListInlineSlider } from '../../../src/static/js/utils/hooks/useItemListInlineSlider';
|
||||
|
||||
function HookConsumer(props: any) {
|
||||
const tuple = useItemListInlineSlider(props);
|
||||
const [
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
import React from 'react';
|
||||
import { render, fireEvent, waitFor } from '@testing-library/react';
|
||||
|
||||
const mockRemoveListener = jest.fn();
|
||||
|
||||
import { useItemListLazyLoad } from '../../../src/static/js/utils/hooks/useItemListLazyLoad';
|
||||
|
||||
let mockListHandler: any;
|
||||
let addListItemsSpy = jest.fn();
|
||||
|
||||
jest.mock('../../../src/static/js/utils/settings/config', () => ({
|
||||
config: jest.fn(() => jest.requireActual('../../tests-constants').sampleMediaCMSConfig),
|
||||
}));
|
||||
|
||||
jest.mock('../../../src/static/js/utils/classes/', () => ({
|
||||
BrowserCache: jest.fn().mockImplementation(() => ({
|
||||
get: jest.fn(),
|
||||
set: jest.fn(),
|
||||
})),
|
||||
BrowserCache: jest.fn().mockImplementation(() => ({ get: jest.fn(), set: jest.fn() })),
|
||||
}));
|
||||
|
||||
let mockListHandler: any;
|
||||
let addListItemsSpy = jest.fn();
|
||||
const mockRemoveListener = jest.fn();
|
||||
|
||||
jest.mock('../../../src/static/js/utils/hooks/useItemList', () => ({
|
||||
useItemList: (props: any, _ref: any) => {
|
||||
mockListHandler = {
|
||||
@@ -35,13 +35,7 @@ jest.mock('../../../src/static/js/utils/hooks/useItemList', () => ({
|
||||
},
|
||||
}));
|
||||
|
||||
jest.mock('../../../src/static/js/utils/stores/', () => ({
|
||||
PageStore: {
|
||||
removeListener: mockRemoveListener,
|
||||
},
|
||||
}));
|
||||
|
||||
import { useItemListLazyLoad } from '../../../src/static/js/utils/hooks/useItemListLazyLoad';
|
||||
jest.mock('../../../src/static/js/utils/stores/', () => ({ PageStore: { removeListener: mockRemoveListener } }));
|
||||
|
||||
function HookConsumer(props: any) {
|
||||
const tuple = useItemListLazyLoad(props);
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
import React from 'react';
|
||||
import { render, fireEvent } from '@testing-library/react';
|
||||
|
||||
import { useItemListSync } from '../../../src/static/js/utils/hooks/useItemListSync';
|
||||
|
||||
let mockListHandler: any;
|
||||
let mockOnItemsLoad = jest.fn();
|
||||
let mockOnItemsCount = jest.fn();
|
||||
let addListItemsSpy = jest.fn();
|
||||
|
||||
jest.mock('../../../src/static/js/utils/settings/config', () => ({
|
||||
config: jest.fn(() => jest.requireActual('../../tests-constants').sampleMediaCMSConfig),
|
||||
}));
|
||||
@@ -16,11 +23,6 @@ jest.mock('../../../src/static/js/utils/helpers/', () => ({
|
||||
translateString: (s: string) => s,
|
||||
}));
|
||||
|
||||
let mockListHandler: any;
|
||||
let mockOnItemsLoad = jest.fn();
|
||||
let mockOnItemsCount = jest.fn();
|
||||
let addListItemsSpy = jest.fn();
|
||||
|
||||
// Mock useItemList to control items, counts, and listHandler
|
||||
jest.mock('../../../src/static/js/utils/hooks/useItemList', () => ({
|
||||
useItemList: (props: any, _ref: any) => {
|
||||
@@ -41,8 +43,6 @@ jest.mock('../../../src/static/js/utils/hooks/useItemList', () => ({
|
||||
},
|
||||
}));
|
||||
|
||||
import { useItemListSync } from '../../../src/static/js/utils/hooks/useItemListSync';
|
||||
|
||||
function HookConsumer(props: any) {
|
||||
const tuple = useItemListSync(props);
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import React from 'react';
|
||||
import { render, fireEvent } from '@testing-library/react';
|
||||
|
||||
import { useManagementTableHeader } from '../../../src/static/js/utils/hooks/useManagementTableHeader';
|
||||
|
||||
function HookConsumer(props: {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import React from 'react';
|
||||
import { render } from '@testing-library/react';
|
||||
|
||||
import { useMediaFilter } from '../../../src/static/js/utils/hooks/useMediaFilter';
|
||||
|
||||
jest.mock('../../../src/static/js/components/_shared/popup/PopupContent', () => ({
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import React from 'react';
|
||||
import { render } from '@testing-library/react';
|
||||
|
||||
import { useMediaItem, itemClassname } from '../../../src/static/js/utils/hooks/useMediaItem';
|
||||
|
||||
// Mock dependencies used by useMediaItem
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import React from 'react';
|
||||
import { render } from '@testing-library/react';
|
||||
|
||||
import { usePopup } from '../../../src/static/js/utils/hooks/usePopup';
|
||||
|
||||
// Mock popup components to avoid SCSS imports breaking Jest
|
||||
jest.mock('../../../src/static/js/components/_shared/popup/Popup.jsx', () => {
|
||||
const React = require('react');
|
||||
@@ -16,8 +18,6 @@ jest.mock('../../../src/static/js/components/_shared/popup/PopupTrigger.jsx', ()
|
||||
PopupTrigger: (props: any) => React.createElement('div', props, props.children),
|
||||
}));
|
||||
|
||||
import { usePopup } from '../../../src/static/js/utils/hooks/usePopup';
|
||||
|
||||
describe('utils/hooks', () => {
|
||||
describe('usePopup', () => {
|
||||
test('Returns a 3-tuple: [ref, PopupContent, PopupTrigger]', () => {
|
||||
|
||||
@@ -2,7 +2,6 @@ import React from 'react';
|
||||
import { act, render } from '@testing-library/react';
|
||||
|
||||
import { useTheme as useThemeHook } from '../../../src/static/js/utils/hooks/useTheme';
|
||||
|
||||
import { sampleMediaCMSConfig } from '../../tests-constants';
|
||||
|
||||
jest.mock('../../../src/static/js/utils/classes/', () => ({
|
||||
|
||||
Reference in New Issue
Block a user