mirror of
https://github.com/mediacms-io/mediacms.git
synced 2026-03-22 04:33:09 -04:00
chore: minor code enhancements
This commit is contained in:
@@ -3,9 +3,7 @@ import { config as mediacmsConfig } from '../settings/config';
|
|||||||
|
|
||||||
const notifications = mediacmsConfig(window.MediaCMS).notifications.messages;
|
const notifications = mediacmsConfig(window.MediaCMS).notifications.messages;
|
||||||
|
|
||||||
const texts = {
|
const texts = { notifications };
|
||||||
notifications,
|
|
||||||
};
|
|
||||||
|
|
||||||
export const TextsContext = createContext(texts);
|
export const TextsContext = createContext(texts);
|
||||||
|
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ export function memberConfig(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const mediaActions = features?.media?.actions;
|
const mediaActions = features?.media?.actions;
|
||||||
if (mediaActions !== undefined) {
|
if (mediaActions) {
|
||||||
ret.can.addComment = ret.can.addComment && mediaActions?.comment === true;
|
ret.can.addComment = ret.can.addComment && mediaActions?.comment === true;
|
||||||
ret.can.mentionComment = ret.can.mentionComment && mediaActions?.comment_mention === true;
|
ret.can.mentionComment = ret.can.mentionComment && mediaActions?.comment_mention === true;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { render, fireEvent, act } from '@testing-library/react';
|
import { render, fireEvent, act } from '@testing-library/react';
|
||||||
|
|
||||||
import { useBulkActions } from '../../../src/static/js/utils/hooks/useBulkActions';
|
import { useBulkActions } from '../../../src/static/js/utils/hooks/useBulkActions';
|
||||||
|
|
||||||
// Mock translateString to return the input for easier assertions
|
// Mock translateString to return the input for easier assertions
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { render } from '@testing-library/react';
|
import { render } from '@testing-library/react';
|
||||||
|
|
||||||
import { useItem } from '../../../src/static/js/utils/hooks/useItem';
|
import { useItem } from '../../../src/static/js/utils/hooks/useItem';
|
||||||
|
|
||||||
// Mock the item components
|
// Mock the item components
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import React, { createRef } from 'react';
|
import React, { createRef } from 'react';
|
||||||
import { render } from '@testing-library/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
|
// 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 });
|
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() }]),
|
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) {
|
function HookConsumer(props: any) {
|
||||||
const listRef = createRef<HTMLDivElement>();
|
const listRef = createRef<HTMLDivElement>();
|
||||||
const [items, countedItems, listHandler, setListHandler, onItemsLoad, onItemsCount, addListItems] = useItemList(
|
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="count-call" onClick={() => onItemsCount(5)} />
|
||||||
<button data-testid="add-call" onClick={() => addListItems()} />
|
<button data-testid="add-call" onClick={() => addListItems()} />
|
||||||
<button data-testid="set-handler" onClick={() => setListHandler({ foo: 'bar' })} />
|
<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>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,21 @@
|
|||||||
import React from 'react';
|
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', () => ({
|
jest.mock('../../../src/static/js/utils/settings/config', () => ({
|
||||||
config: jest.fn(() => jest.requireActual('../../tests-constants').sampleMediaCMSConfig),
|
config: jest.fn(() => jest.requireActual('../../tests-constants').sampleMediaCMSConfig),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
jest.mock('../../../src/static/js/utils/classes/', () => ({
|
jest.mock('../../../src/static/js/utils/classes/', () => ({
|
||||||
BrowserCache: jest.fn().mockImplementation(() => ({
|
BrowserCache: jest.fn().mockImplementation(() => ({ get: jest.fn(), set: jest.fn() })),
|
||||||
get: jest.fn(),
|
|
||||||
set: jest.fn(),
|
|
||||||
})),
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
jest.mock('../../../src/static/js/utils/helpers/', () => ({
|
jest.mock('../../../src/static/js/utils/helpers/', () => ({ addClassname: jest.fn(), removeClassname: jest.fn() }));
|
||||||
addClassname: jest.fn(),
|
|
||||||
removeClassname: jest.fn(),
|
|
||||||
}));
|
|
||||||
|
|
||||||
let mockListHandler: any;
|
|
||||||
let mockInlineSliderInstance: any;
|
|
||||||
let addListItemsSpy = jest.fn();
|
|
||||||
|
|
||||||
jest.mock('../../../src/static/js/utils/hooks/useItemList', () => ({
|
jest.mock('../../../src/static/js/utils/hooks/useItemList', () => ({
|
||||||
useItemList: (props: any, _ref: any) => {
|
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) {
|
function HookConsumer(props: any) {
|
||||||
const tuple = useItemListInlineSlider(props);
|
const tuple = useItemListInlineSlider(props);
|
||||||
const [
|
const [
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { render, fireEvent, waitFor } from '@testing-library/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', () => ({
|
jest.mock('../../../src/static/js/utils/settings/config', () => ({
|
||||||
config: jest.fn(() => jest.requireActual('../../tests-constants').sampleMediaCMSConfig),
|
config: jest.fn(() => jest.requireActual('../../tests-constants').sampleMediaCMSConfig),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
jest.mock('../../../src/static/js/utils/classes/', () => ({
|
jest.mock('../../../src/static/js/utils/classes/', () => ({
|
||||||
BrowserCache: jest.fn().mockImplementation(() => ({
|
BrowserCache: jest.fn().mockImplementation(() => ({ get: jest.fn(), set: jest.fn() })),
|
||||||
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', () => ({
|
jest.mock('../../../src/static/js/utils/hooks/useItemList', () => ({
|
||||||
useItemList: (props: any, _ref: any) => {
|
useItemList: (props: any, _ref: any) => {
|
||||||
mockListHandler = {
|
mockListHandler = {
|
||||||
@@ -35,13 +35,7 @@ jest.mock('../../../src/static/js/utils/hooks/useItemList', () => ({
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
jest.mock('../../../src/static/js/utils/stores/', () => ({
|
jest.mock('../../../src/static/js/utils/stores/', () => ({ PageStore: { removeListener: mockRemoveListener } }));
|
||||||
PageStore: {
|
|
||||||
removeListener: mockRemoveListener,
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
|
|
||||||
import { useItemListLazyLoad } from '../../../src/static/js/utils/hooks/useItemListLazyLoad';
|
|
||||||
|
|
||||||
function HookConsumer(props: any) {
|
function HookConsumer(props: any) {
|
||||||
const tuple = useItemListLazyLoad(props);
|
const tuple = useItemListLazyLoad(props);
|
||||||
|
|||||||
@@ -1,6 +1,13 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { render, fireEvent } from '@testing-library/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', () => ({
|
jest.mock('../../../src/static/js/utils/settings/config', () => ({
|
||||||
config: jest.fn(() => jest.requireActual('../../tests-constants').sampleMediaCMSConfig),
|
config: jest.fn(() => jest.requireActual('../../tests-constants').sampleMediaCMSConfig),
|
||||||
}));
|
}));
|
||||||
@@ -16,11 +23,6 @@ jest.mock('../../../src/static/js/utils/helpers/', () => ({
|
|||||||
translateString: (s: string) => s,
|
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
|
// Mock useItemList to control items, counts, and listHandler
|
||||||
jest.mock('../../../src/static/js/utils/hooks/useItemList', () => ({
|
jest.mock('../../../src/static/js/utils/hooks/useItemList', () => ({
|
||||||
useItemList: (props: any, _ref: any) => {
|
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) {
|
function HookConsumer(props: any) {
|
||||||
const tuple = useItemListSync(props);
|
const tuple = useItemListSync(props);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { render, fireEvent } from '@testing-library/react';
|
import { render, fireEvent } from '@testing-library/react';
|
||||||
|
|
||||||
import { useManagementTableHeader } from '../../../src/static/js/utils/hooks/useManagementTableHeader';
|
import { useManagementTableHeader } from '../../../src/static/js/utils/hooks/useManagementTableHeader';
|
||||||
|
|
||||||
function HookConsumer(props: {
|
function HookConsumer(props: {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { render } from '@testing-library/react';
|
import { render } from '@testing-library/react';
|
||||||
|
|
||||||
import { useMediaFilter } from '../../../src/static/js/utils/hooks/useMediaFilter';
|
import { useMediaFilter } from '../../../src/static/js/utils/hooks/useMediaFilter';
|
||||||
|
|
||||||
jest.mock('../../../src/static/js/components/_shared/popup/PopupContent', () => ({
|
jest.mock('../../../src/static/js/components/_shared/popup/PopupContent', () => ({
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { render } from '@testing-library/react';
|
import { render } from '@testing-library/react';
|
||||||
|
|
||||||
import { useMediaItem, itemClassname } from '../../../src/static/js/utils/hooks/useMediaItem';
|
import { useMediaItem, itemClassname } from '../../../src/static/js/utils/hooks/useMediaItem';
|
||||||
|
|
||||||
// Mock dependencies used by useMediaItem
|
// Mock dependencies used by useMediaItem
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { render } from '@testing-library/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
|
// Mock popup components to avoid SCSS imports breaking Jest
|
||||||
jest.mock('../../../src/static/js/components/_shared/popup/Popup.jsx', () => {
|
jest.mock('../../../src/static/js/components/_shared/popup/Popup.jsx', () => {
|
||||||
const React = require('react');
|
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),
|
PopupTrigger: (props: any) => React.createElement('div', props, props.children),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
import { usePopup } from '../../../src/static/js/utils/hooks/usePopup';
|
|
||||||
|
|
||||||
describe('utils/hooks', () => {
|
describe('utils/hooks', () => {
|
||||||
describe('usePopup', () => {
|
describe('usePopup', () => {
|
||||||
test('Returns a 3-tuple: [ref, PopupContent, PopupTrigger]', () => {
|
test('Returns a 3-tuple: [ref, PopupContent, PopupTrigger]', () => {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import React from 'react';
|
|||||||
import { act, render } from '@testing-library/react';
|
import { act, render } from '@testing-library/react';
|
||||||
|
|
||||||
import { useTheme as useThemeHook } from '../../../src/static/js/utils/hooks/useTheme';
|
import { useTheme as useThemeHook } from '../../../src/static/js/utils/hooks/useTheme';
|
||||||
|
|
||||||
import { sampleMediaCMSConfig } from '../../tests-constants';
|
import { sampleMediaCMSConfig } from '../../tests-constants';
|
||||||
|
|
||||||
jest.mock('../../../src/static/js/utils/classes/', () => ({
|
jest.mock('../../../src/static/js/utils/classes/', () => ({
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { apiConfig } from '../../../src/static/js/utils/settings/api';
|
import { apiConfig } from '../../../src/static/js/utils/settings/api';
|
||||||
|
|
||||||
const sampleGlobal = {
|
const sampleGlobal = {
|
||||||
site: { api: 'https://example.com/api///' },
|
site: { api: 'http://example.com/api///' },
|
||||||
// endpoints below intentionally contain leading slashes to ensure they are stripped
|
// endpoints below intentionally contain leading slashes to ensure they are stripped
|
||||||
api: {
|
api: {
|
||||||
media: '/v1/media/',
|
media: '/v1/media/',
|
||||||
@@ -20,43 +20,41 @@ const sampleGlobal = {
|
|||||||
|
|
||||||
describe('utils/settings', () => {
|
describe('utils/settings', () => {
|
||||||
describe('api', () => {
|
describe('api', () => {
|
||||||
test('trims trailing slashes on base and ensures single slash joins', () => {
|
test('Builds search endpoints with expected query fragments', () => {
|
||||||
const cfg = apiConfig(sampleGlobal.site.api as any, sampleGlobal.api as any);
|
const cfg = apiConfig(sampleGlobal.site.api, sampleGlobal.api as any);
|
||||||
expect(cfg.media).toBe('https://example.com/api/v1/media/');
|
|
||||||
// base should not end with a slash and endpoint leading slash stripped
|
expect(cfg).toStrictEqual({
|
||||||
expect(cfg.users).toBe('https://example.com/api/v1/users');
|
media: 'http://example.com/api/v1/media/',
|
||||||
|
featured: 'http://example.com/api/v1/media/?show=featured',
|
||||||
|
recommended: 'http://example.com/api/v1/media/?show=recommended',
|
||||||
|
playlists: 'http://example.com/api/v1/playlists',
|
||||||
|
users: 'http://example.com/api/v1/users',
|
||||||
|
user: {
|
||||||
|
liked: 'http://example.com/api/v1/user/liked',
|
||||||
|
history: 'http://example.com/api/v1/user/history',
|
||||||
|
playlists: 'http://example.com/api/v1/playlists?author=',
|
||||||
|
},
|
||||||
|
archive: {
|
||||||
|
tags: 'http://example.com/api/v1/tags',
|
||||||
|
categories: 'http://example.com/api/v1/categories',
|
||||||
|
},
|
||||||
|
manage: {
|
||||||
|
media: 'http://example.com/api/v1/manage/media',
|
||||||
|
users: 'http://example.com/api/v1/manage/users',
|
||||||
|
comments: 'http://example.com/api/v1/manage/comments',
|
||||||
|
},
|
||||||
|
search: {
|
||||||
|
query: 'http://example.com/api/v1/search?q=',
|
||||||
|
titles: 'http://example.com/api/v1/search?show=titles&q=',
|
||||||
|
tag: 'http://example.com/api/v1/search?t=',
|
||||||
|
category: 'http://example.com/api/v1/search?c=',
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('adds featured/recommended query to media variants', () => {
|
test('Handles base url with path and endpoint with existing query', () => {
|
||||||
const cfg = apiConfig(sampleGlobal.site.api as any, sampleGlobal.api as any);
|
const base = 'https://domain.com/base/';
|
||||||
expect(cfg.featured).toBe('https://example.com/api/v1/media/?show=featured');
|
|
||||||
expect(cfg.recommended).toBe('https://example.com/api/v1/media/?show=recommended');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('builds nested user, archive, manage maps', () => {
|
|
||||||
const cfg = apiConfig(sampleGlobal.site.api as any, sampleGlobal.api as any);
|
|
||||||
expect(cfg.user.liked).toBe('https://example.com/api/v1/user/liked');
|
|
||||||
expect(cfg.user.history).toBe('https://example.com/api/v1/user/history');
|
|
||||||
expect(cfg.user.playlists).toBe('https://example.com/api/v1/playlists?author=');
|
|
||||||
|
|
||||||
expect(cfg.archive.tags).toBe('https://example.com/api/v1/tags');
|
|
||||||
expect(cfg.archive.categories).toBe('https://example.com/api/v1/categories');
|
|
||||||
|
|
||||||
expect(cfg.manage.media).toBe('https://example.com/api/v1/manage/media');
|
|
||||||
expect(cfg.manage.users).toBe('https://example.com/api/v1/manage/users');
|
|
||||||
expect(cfg.manage.comments).toBe('https://example.com/api/v1/manage/comments');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('builds search endpoints with expected query fragments', () => {
|
|
||||||
const cfg = apiConfig(sampleGlobal.site.api as any, sampleGlobal.api as any);
|
|
||||||
expect(cfg.search.query).toBe('https://example.com/api/v1/search?q=');
|
|
||||||
expect(cfg.search.titles).toBe('https://example.com/api/v1/search?show=titles&q=');
|
|
||||||
expect(cfg.search.tag).toBe('https://example.com/api/v1/search?t=');
|
|
||||||
expect(cfg.search.category).toBe('https://example.com/api/v1/search?c=');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('handles base url with path and endpoint with existing query', () => {
|
|
||||||
const base = 'https://example.com/base/';
|
|
||||||
const endpoints = {
|
const endpoints = {
|
||||||
media: 'items?x=1',
|
media: 'items?x=1',
|
||||||
playlists: '/pls/',
|
playlists: '/pls/',
|
||||||
@@ -69,13 +67,37 @@ describe('utils/settings', () => {
|
|||||||
manage_users: 'm/users',
|
manage_users: 'm/users',
|
||||||
manage_comments: 'm/comments',
|
manage_comments: 'm/comments',
|
||||||
search: '/s',
|
search: '/s',
|
||||||
} as any;
|
};
|
||||||
const cfg = apiConfig(base as any, endpoints);
|
|
||||||
expect(cfg.media).toBe('https://example.com/base/items?x=1');
|
const cfg = apiConfig(base, endpoints as any);
|
||||||
expect(cfg.playlists).toBe('https://example.com/base/pls/');
|
|
||||||
expect(cfg.user.liked).toBe('https://example.com/base/me/liked');
|
expect(cfg).toStrictEqual({
|
||||||
expect(cfg.archive.categories).toBe('https://example.com/base/c');
|
media: 'https://domain.com/base/items?x=1',
|
||||||
expect(cfg.search.query).toBe('https://example.com/base/s?q=');
|
featured: 'https://domain.com/base/items?x=1?show=featured',
|
||||||
|
recommended: 'https://domain.com/base/items?x=1?show=recommended',
|
||||||
|
playlists: 'https://domain.com/base/pls/',
|
||||||
|
users: 'https://domain.com/base/users',
|
||||||
|
user: {
|
||||||
|
liked: 'https://domain.com/base/me/liked',
|
||||||
|
history: 'https://domain.com/base/me/history',
|
||||||
|
playlists: 'https://domain.com/base/pls/?author=',
|
||||||
|
},
|
||||||
|
archive: {
|
||||||
|
tags: 'https://domain.com/base/t',
|
||||||
|
categories: 'https://domain.com/base/c',
|
||||||
|
},
|
||||||
|
manage: {
|
||||||
|
media: 'https://domain.com/base/m/media',
|
||||||
|
users: 'https://domain.com/base/m/users',
|
||||||
|
comments: 'https://domain.com/base/m/comments',
|
||||||
|
},
|
||||||
|
search: {
|
||||||
|
query: 'https://domain.com/base/s?q=',
|
||||||
|
titles: 'https://domain.com/base/s?show=titles&q=',
|
||||||
|
tag: 'https://domain.com/base/s?t=',
|
||||||
|
category: 'https://domain.com/base/s?c=',
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -51,8 +51,8 @@ describe('utils/settings', () => {
|
|||||||
can: {
|
can: {
|
||||||
changePassword: true,
|
changePassword: true,
|
||||||
deleteProfile: true,
|
deleteProfile: true,
|
||||||
addComment: false,
|
addComment: true,
|
||||||
mentionComment: false,
|
mentionComment: true,
|
||||||
deleteComment: true,
|
deleteComment: true,
|
||||||
editMedia: true,
|
editMedia: true,
|
||||||
deleteMedia: true,
|
deleteMedia: true,
|
||||||
@@ -85,8 +85,8 @@ describe('utils/settings', () => {
|
|||||||
changePassword: true,
|
changePassword: true,
|
||||||
deleteProfile: true,
|
deleteProfile: true,
|
||||||
readComment: true,
|
readComment: true,
|
||||||
addComment: false,
|
addComment: true,
|
||||||
mentionComment: false,
|
mentionComment: true,
|
||||||
deleteComment: true,
|
deleteComment: true,
|
||||||
editMedia: true,
|
editMedia: true,
|
||||||
deleteMedia: true,
|
deleteMedia: true,
|
||||||
|
|||||||
@@ -56,10 +56,10 @@ describe('utils/settings', () => {
|
|||||||
const def = optionsPagesConfig();
|
const def = optionsPagesConfig();
|
||||||
expect(def.search.advancedFilters).toBe(false);
|
expect(def.search.advancedFilters).toBe(false);
|
||||||
|
|
||||||
const falsy = optionsPagesConfig(undefined, { advancedFilters: false } as any);
|
const falsy = optionsPagesConfig(undefined, { advancedFilters: false });
|
||||||
expect(falsy.search.advancedFilters).toBe(false);
|
expect(falsy.search.advancedFilters).toBe(false);
|
||||||
|
|
||||||
const truthy = optionsPagesConfig(undefined, { advancedFilters: true } as any);
|
const truthy = optionsPagesConfig(undefined, { advancedFilters: true });
|
||||||
expect(truthy.search.advancedFilters).toBe(true);
|
expect(truthy.search.advancedFilters).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ describe('utils/settings', () => {
|
|||||||
const cfg1 = optionsPagesConfig(undefined, undefined, { related: { initialSize: NaN } } as any);
|
const cfg1 = optionsPagesConfig(undefined, undefined, { related: { initialSize: NaN } } as any);
|
||||||
expect(cfg1.media.related.initialSize).toBe(10);
|
expect(cfg1.media.related.initialSize).toBe(10);
|
||||||
|
|
||||||
const cfg2 = optionsPagesConfig(undefined, undefined, { related: { initialSize: '12' as any } } as any);
|
const cfg2 = optionsPagesConfig(undefined, undefined, { related: { initialSize: '12' } } as any);
|
||||||
expect(cfg2.media.related.initialSize).toBe(10);
|
expect(cfg2.media.related.initialSize).toBe(10);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ describe('utils/settings', () => {
|
|||||||
const search = { advancedFilters: true };
|
const search = { advancedFilters: true };
|
||||||
const media = { hideViews: true, related: { initialSize: 5 } };
|
const media = { hideViews: true, related: { initialSize: 5 } };
|
||||||
const profile = { includeHistory: true };
|
const profile = { includeHistory: true };
|
||||||
const validPages: any = { latest: { title: 'L' }, featured: { title: 'F' }, recommended: { title: 'R' } };
|
const validPages = { latest: { title: 'L' }, featured: { title: 'F' }, recommended: { title: 'R' } };
|
||||||
|
|
||||||
const homeCopy = JSON.parse(JSON.stringify(home));
|
const homeCopy = JSON.parse(JSON.stringify(home));
|
||||||
const searchCopy = JSON.parse(JSON.stringify(search));
|
const searchCopy = JSON.parse(JSON.stringify(search));
|
||||||
@@ -120,7 +120,7 @@ describe('utils/settings', () => {
|
|||||||
const profileCopy = JSON.parse(JSON.stringify(profile));
|
const profileCopy = JSON.parse(JSON.stringify(profile));
|
||||||
const validPagesCopy = JSON.parse(JSON.stringify(validPages));
|
const validPagesCopy = JSON.parse(JSON.stringify(validPages));
|
||||||
|
|
||||||
optionsPagesConfig(home, search, media, profile, validPages);
|
optionsPagesConfig(home, search, media, profile, validPages as any);
|
||||||
|
|
||||||
expect(home).toStrictEqual(homeCopy);
|
expect(home).toStrictEqual(homeCopy);
|
||||||
expect(search).toStrictEqual(searchCopy);
|
expect(search).toStrictEqual(searchCopy);
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ describe('utils/settings', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Returns default when provided mediaTypes is non-array or undefined/null', () => {
|
test('Returns default when provided mediaTypes is non-array or undefined/null', () => {
|
||||||
expect(playlistsConfig({} as any).mediaTypes).toEqual(['audio', 'video']);
|
expect(playlistsConfig({}).mediaTypes).toEqual(['audio', 'video']);
|
||||||
expect(playlistsConfig({ mediaTypes: undefined } as any).mediaTypes).toEqual(['audio', 'video']);
|
expect(playlistsConfig({ mediaTypes: undefined }).mediaTypes).toEqual(['audio', 'video']);
|
||||||
expect(playlistsConfig({ mediaTypes: null as any }).mediaTypes).toEqual(['audio', 'video']);
|
expect(playlistsConfig({ mediaTypes: null as any }).mediaTypes).toEqual(['audio', 'video']);
|
||||||
expect(playlistsConfig({ mediaTypes: 'audio' as any }).mediaTypes).toEqual(['audio', 'video']);
|
expect(playlistsConfig({ mediaTypes: 'audio' as any }).mediaTypes).toEqual(['audio', 'video']);
|
||||||
expect(playlistsConfig({ mediaTypes: 123 as any }).mediaTypes).toEqual(['audio', 'video']);
|
expect(playlistsConfig({ mediaTypes: 123 as any }).mediaTypes).toEqual(['audio', 'video']);
|
||||||
|
|||||||
@@ -58,12 +58,12 @@ describe('utils/settings', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Does not mutate input objects', () => {
|
test('Does not mutate input objects', () => {
|
||||||
const themeIn: any = { mode: ' dark ', switch: { enabled: false, position: ' sidebar ' } };
|
const themeIn = { mode: ' dark ', switch: { enabled: false, position: ' sidebar ' } };
|
||||||
const logoIn = { lightMode: { img: ' x ', svg: ' y ' }, darkMode: { img: ' z ', svg: ' w ' } };
|
const logoIn = { lightMode: { img: ' x ', svg: ' y ' }, darkMode: { img: ' z ', svg: ' w ' } };
|
||||||
const themeCopy = JSON.parse(JSON.stringify(themeIn));
|
const themeCopy = JSON.parse(JSON.stringify(themeIn));
|
||||||
const logoCopy = JSON.parse(JSON.stringify(logoIn));
|
const logoCopy = JSON.parse(JSON.stringify(logoIn));
|
||||||
|
|
||||||
themeConfig(themeIn, logoIn);
|
themeConfig(themeIn as any, logoIn);
|
||||||
|
|
||||||
expect(themeIn).toStrictEqual(themeCopy);
|
expect(themeIn).toStrictEqual(themeCopy);
|
||||||
expect(logoIn).toStrictEqual(logoCopy);
|
expect(logoIn).toStrictEqual(logoCopy);
|
||||||
|
|||||||
Reference in New Issue
Block a user