mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-19 22:46:20 -05:00
Moving form fields.
This commit is contained in:
parent
a6314bb71c
commit
42bb1711a9
10 changed files with 576 additions and 983 deletions
|
|
@ -67,26 +67,10 @@ describe('DirectorySearch Integration Tests', () => {
|
|||
}
|
||||
}).as('getDomain');
|
||||
|
||||
cy.intercept('GET', '/api/collections?kind=domain', {
|
||||
statusCode: 200,
|
||||
body: {
|
||||
collections: [],
|
||||
totals: {collections: 0},
|
||||
metadata: {
|
||||
kind: 'domain',
|
||||
columns: [],
|
||||
fields: [
|
||||
{key: 'directory', label: 'Directory', type: 'text', required: false}
|
||||
],
|
||||
routes: {},
|
||||
messages: {}
|
||||
}
|
||||
}
|
||||
}).as('getMetadata');
|
||||
|
||||
cy.visit('/archive/domain/1/edit');
|
||||
cy.wait('@getDomain');
|
||||
cy.wait('@getMetadata');
|
||||
// Wait for initial directory search API call (component makes call on mount)
|
||||
cy.wait('@searchDirectories');
|
||||
});
|
||||
|
||||
it('types in search box and sees results', () => {
|
||||
|
|
@ -182,26 +166,10 @@ describe('DirectorySearch Integration Tests', () => {
|
|||
}
|
||||
}).as('getDomain');
|
||||
|
||||
cy.intercept('GET', '/api/collections?kind=domain', {
|
||||
statusCode: 200,
|
||||
body: {
|
||||
collections: [],
|
||||
totals: {collections: 0},
|
||||
metadata: {
|
||||
kind: 'domain',
|
||||
columns: [],
|
||||
fields: [
|
||||
{key: 'directory', label: 'Directory', type: 'text', required: true}
|
||||
],
|
||||
routes: {},
|
||||
messages: {}
|
||||
}
|
||||
}
|
||||
}).as('getMetadata');
|
||||
|
||||
cy.visit('/archive/domain/2/edit');
|
||||
cy.wait('@getDomain');
|
||||
cy.wait('@getMetadata');
|
||||
// Wait for initial directory search API call (component makes call on mount)
|
||||
cy.wait('@searchDirectories');
|
||||
});
|
||||
|
||||
it('starts with existing directory value', () => {
|
||||
|
|
@ -262,26 +230,10 @@ describe('DirectorySearch Integration Tests', () => {
|
|||
}
|
||||
}).as('getDomain');
|
||||
|
||||
cy.intercept('GET', '/api/collections?kind=domain', {
|
||||
statusCode: 200,
|
||||
body: {
|
||||
collections: [],
|
||||
totals: {collections: 0},
|
||||
metadata: {
|
||||
kind: 'domain',
|
||||
columns: [],
|
||||
fields: [
|
||||
{key: 'directory', label: 'Directory', type: 'text', required: false}
|
||||
],
|
||||
routes: {},
|
||||
messages: {}
|
||||
}
|
||||
}
|
||||
}).as('getMetadata');
|
||||
|
||||
cy.visit('/archive/domain/3/edit');
|
||||
cy.wait('@getDomain');
|
||||
cy.wait('@getMetadata');
|
||||
// Wait for initial directory search API call (component makes call on mount)
|
||||
cy.wait('@searchDirectories');
|
||||
|
||||
// Type path that returns empty results
|
||||
cy.contains('label', 'Directory')
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ Cypress.Commands.add('mountWithRouter', (component, options) => {
|
|||
<QueryProvider>
|
||||
<Routes>
|
||||
<Route path='/videos/channels/new' element={component}/>
|
||||
<Route path='/videos/channel/:channelId/edit' element={component}/>
|
||||
<Route path='/videos/channels/:channelId' element={component}/>
|
||||
<Route path='*' element={component}/>
|
||||
</Routes>
|
||||
|
|
|
|||
|
|
@ -5,11 +5,13 @@ import {
|
|||
CardHeader,
|
||||
CardMeta,
|
||||
Container,
|
||||
Form,
|
||||
GridColumn,
|
||||
GridRow,
|
||||
Image,
|
||||
Input,
|
||||
TableCell,
|
||||
TextArea,
|
||||
} from "semantic-ui-react";
|
||||
import {
|
||||
APIButton,
|
||||
|
|
@ -56,6 +58,7 @@ import {API_ARCHIVE_UPLOAD_URI, Downloaders} from "./Vars";
|
|||
import {CollectionTable} from "./collections/CollectionTable";
|
||||
import {CollectionEditForm} from "./collections/CollectionEditForm";
|
||||
import {RecurringDownloadsTable} from "./admin/Downloads";
|
||||
import {DestinationForm} from "./Download";
|
||||
|
||||
function archiveFileLink(path, directory = false) {
|
||||
if (path) {
|
||||
|
|
@ -429,18 +432,6 @@ export function DomainsPage() {
|
|||
</>;
|
||||
}
|
||||
|
||||
// Domain form field configuration
|
||||
const DOMAIN_FIELDS = [
|
||||
{key: 'directory', label: 'Directory', type: 'directory', placeholder: 'Optional directory path'},
|
||||
// tag_name field is handled via modal button, not inline in form
|
||||
{key: 'description', label: 'Description', type: 'textarea', placeholder: 'Optional description'}
|
||||
];
|
||||
|
||||
const DOMAIN_MESSAGES = {
|
||||
no_directory: 'Set a directory to enable tagging',
|
||||
tag_will_move: 'Tagging will move files to a new directory'
|
||||
};
|
||||
|
||||
export function DomainEditPage() {
|
||||
const {domainId} = useParams();
|
||||
const navigate = useNavigate();
|
||||
|
|
@ -561,17 +552,41 @@ export function DomainEditPage() {
|
|||
{tagButton}
|
||||
</>;
|
||||
|
||||
const [descriptionProps] = form.getCustomProps({name: 'description', path: 'description'});
|
||||
|
||||
return <>
|
||||
<BackButton/>
|
||||
<CollectionEditForm
|
||||
form={form}
|
||||
fields={DOMAIN_FIELDS}
|
||||
messages={DOMAIN_MESSAGES}
|
||||
title={`Edit Domain: ${domain?.domain || '...'}`}
|
||||
wrolModeContent='Domain editing is disabled while in WROL Mode.'
|
||||
actionButtons={actionButtons}
|
||||
appliedTagName={domain?.tag_name}
|
||||
/>
|
||||
>
|
||||
<GridRow>
|
||||
<GridColumn>
|
||||
<DestinationForm
|
||||
form={form}
|
||||
label='Directory'
|
||||
name='directory'
|
||||
path='directory'
|
||||
/>
|
||||
</GridColumn>
|
||||
</GridRow>
|
||||
<GridRow>
|
||||
<GridColumn>
|
||||
<Form.Field>
|
||||
<label>Description</label>
|
||||
<TextArea
|
||||
placeholder='Optional description'
|
||||
{...descriptionProps}
|
||||
onChange={(e, {value}) => descriptionProps.onChange(value)}
|
||||
rows={3}
|
||||
/>
|
||||
</Form.Field>
|
||||
</GridColumn>
|
||||
</GridRow>
|
||||
</CollectionEditForm>
|
||||
|
||||
{/* Tag Modal */}
|
||||
<CollectionTagModal
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import React from "react";
|
||||
import {ChannelPage} from "./Channels";
|
||||
import {ChannelEditPage, ChannelNewPage} from "./Channels";
|
||||
|
||||
describe('Channels Page', () => {
|
||||
beforeEach(() => {
|
||||
|
|
@ -15,7 +15,7 @@ describe('Channels Page', () => {
|
|||
|
||||
it('New Channel page can be rendered', () => {
|
||||
cy.mountWithTags(
|
||||
<ChannelPage create={true}/>,
|
||||
<ChannelNewPage/>,
|
||||
{initialEntries: ['/videos/channels/new']}
|
||||
);
|
||||
cy.get('input[name="name"]').should('be.visible');
|
||||
|
|
@ -45,8 +45,8 @@ describe('Channels Page', () => {
|
|||
}).as('channelFetch');
|
||||
|
||||
cy.mountWithTags(
|
||||
<ChannelPage create={false}/>,
|
||||
{initialEntries: ['/videos/channels/1']}
|
||||
<ChannelEditPage/>,
|
||||
{initialEntries: ['/videos/channel/1/edit']}
|
||||
);
|
||||
cy.wait('@channelFetch');
|
||||
cy.wait('@searchDirectories'); // Needed for CircleCi.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import React, {useState} from "react";
|
||||
import {Grid, StatisticLabel, StatisticValue, TableCell, TableRow,} from "semantic-ui-react";
|
||||
import {createChannel, deleteChannel, refreshChannel, tagChannel, tagChannelInfo, updateChannel} from "../api";
|
||||
import {createChannel, deleteChannel, refreshChannel, tagChannel, tagChannelInfo} from "../api";
|
||||
import {CollectionTagModal} from "./collections/CollectionTagModal";
|
||||
import {
|
||||
APIButton,
|
||||
|
|
@ -31,13 +31,12 @@ import {
|
|||
Statistic
|
||||
} from "./Theme";
|
||||
import {Media, ThemeContext} from "../contexts/contexts";
|
||||
import {SortableTable} from "./SortableTable";
|
||||
import {toast} from "react-semantic-toasts-2";
|
||||
import {RecurringDownloadsTable} from "./admin/Downloads";
|
||||
import {TagsContext} from "../Tags";
|
||||
import {InputForm, ToggleForm} from "../hooks/useForm";
|
||||
import {ChannelDownloadForm, DestinationForm, DownloadTagsSelector} from "./Download";
|
||||
import {CollectionTable} from "./collections/CollectionTable";
|
||||
import {CollectionEditForm} from "./collections/CollectionEditForm";
|
||||
|
||||
// Channel table column configuration
|
||||
const CHANNEL_COLUMNS = [
|
||||
|
|
@ -87,118 +86,21 @@ function ChannelStatistics({statistics}) {
|
|||
}
|
||||
|
||||
|
||||
export function ChannelPage({create, header}) {
|
||||
// Used to display messages to maintainer.
|
||||
const [error, setError] = useState(false);
|
||||
const [success, setSuccess] = useState(false);
|
||||
const [messageHeader, setMessageHeader] = useState();
|
||||
const [messageContent, setMessageContent] = useState();
|
||||
|
||||
const [downloadModalOpen, setDownloadModalOpen] = useState(false);
|
||||
|
||||
export function ChannelEditPage() {
|
||||
const navigate = useNavigate();
|
||||
const {channelId} = useParams();
|
||||
const {SingleTag} = React.useContext(TagsContext);
|
||||
|
||||
const [tagEditModalOpen, setTagEditModalOpen] = useState(false);
|
||||
const [downloadModalOpen, setDownloadModalOpen] = useState(false);
|
||||
|
||||
const {channel, form, fetchChannel} = useChannel(channelId);
|
||||
|
||||
useTitle(_.isEmpty(channel) ? null : `${channel.name} Channel`);
|
||||
|
||||
if (!create && !form.ready) {
|
||||
// Waiting for editing Channel to be fetched.
|
||||
if (!form.ready) {
|
||||
return <Loader active/>;
|
||||
}
|
||||
|
||||
const setErrorMessage = (header, message) => {
|
||||
setError(true);
|
||||
setSuccess(false);
|
||||
setMessageHeader(header);
|
||||
setMessageContent(message);
|
||||
}
|
||||
|
||||
const setSuccessMessage = (header, message) => {
|
||||
setError(false);
|
||||
setSuccess(true);
|
||||
setMessageHeader(header);
|
||||
setMessageContent(message);
|
||||
}
|
||||
|
||||
const handleSubmit = async () => {
|
||||
const body = {
|
||||
name: channel.name,
|
||||
directory: channel.directory,
|
||||
url: channel.url,
|
||||
download_missing_data: channel.download_missing_data,
|
||||
};
|
||||
|
||||
let response = null;
|
||||
try {
|
||||
if (create !== undefined) {
|
||||
// Can create a Channel with a Tag.
|
||||
body.tag_name = _.isEmpty(channel.tag_name) ? null : channel.tag_name[0];
|
||||
response = await createChannel(body);
|
||||
} else {
|
||||
response = await updateChannel(channelId, body);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
toast({
|
||||
type: 'error',
|
||||
title: 'Unexpected server response',
|
||||
description: 'Could not save channel',
|
||||
time: 5000,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (response && response.ok) {
|
||||
let location = response.headers.get('Location');
|
||||
let channelResponse = await fetch(location);
|
||||
let data = await channelResponse.json();
|
||||
let channel = data['channel'];
|
||||
|
||||
if (response.status === 201) {
|
||||
setSuccessMessage(
|
||||
'Channel created',
|
||||
<span>
|
||||
Your channel was created. View it <Link to={`/videos/channel/${channel.id}/edit`}>here</Link>
|
||||
</span>
|
||||
);
|
||||
} else {
|
||||
await fetchChannel();
|
||||
toast({
|
||||
type: 'success',
|
||||
title: 'Channel updated',
|
||||
description: 'The channel was updated',
|
||||
})
|
||||
}
|
||||
|
||||
} else if (response) {
|
||||
// Some error occurred.
|
||||
let error = await response.json();
|
||||
let cause = error.cause;
|
||||
if (cause && cause.code === 'CHANNEL_DIRECTORY_CONFLICT') {
|
||||
setErrorMessage(
|
||||
'Invalid directory',
|
||||
'This directory is already used by another channel',
|
||||
'directory',
|
||||
);
|
||||
} else if (cause && cause.code === 'CHANNEL_NAME_CONFLICT') {
|
||||
setErrorMessage(
|
||||
'Invalid name',
|
||||
'This channel name is already taken',
|
||||
'name',
|
||||
);
|
||||
} else {
|
||||
setErrorMessage('Invalid channel', error.message || error.error || 'Unable to save channel. See logs.');
|
||||
}
|
||||
} else {
|
||||
console.error('Did not get a response for channel!');
|
||||
}
|
||||
}
|
||||
|
||||
const handleRefreshChannel = async (e) => {
|
||||
if (e) {
|
||||
e.preventDefault();
|
||||
|
|
@ -213,11 +115,33 @@ export function ChannelPage({create, header}) {
|
|||
navigate('/videos/channel');
|
||||
}
|
||||
} catch (e) {
|
||||
setErrorMessage('Failed to delete', 'Failed to delete this channel, check logs.');
|
||||
console.error('Failed to delete channel', e);
|
||||
}
|
||||
}
|
||||
|
||||
let downloads = channel && channel.downloads ? channel.downloads : null;
|
||||
// Handler for tag modal save
|
||||
const handleTagSave = async (tagName, directory) => {
|
||||
try {
|
||||
await tagChannel(channelId, tagName, directory);
|
||||
toast({
|
||||
type: 'success',
|
||||
title: 'Channel Tagged',
|
||||
description: `Channel has been tagged with "${tagName}"`,
|
||||
time: 3000,
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('Failed to tag channel', e);
|
||||
} finally {
|
||||
setTimeout(async () => {
|
||||
await fetchChannel();
|
||||
}, 500);
|
||||
}
|
||||
};
|
||||
|
||||
// Handler for fetching tag info
|
||||
const handleGetTagInfo = async (tagName) => {
|
||||
return await tagChannelInfo(channelId, tagName);
|
||||
};
|
||||
|
||||
const afterNewDownloadSave = async () => {
|
||||
setDownloadModalOpen(false);
|
||||
|
|
@ -229,29 +153,126 @@ export function ChannelPage({create, header}) {
|
|||
setDownloadModalOpen(false);
|
||||
}
|
||||
|
||||
// Handler for tag modal save
|
||||
const handleTagSave = async (tagName, directory) => {
|
||||
const handleSubmit = async (e) => {
|
||||
if (e) e.preventDefault();
|
||||
try {
|
||||
await tagChannel(channelId, tagName, directory);
|
||||
await form.onSubmit();
|
||||
toast({
|
||||
type: 'success',
|
||||
title: 'Channel Updated',
|
||||
description: 'Channel was successfully updated',
|
||||
time: 3000,
|
||||
});
|
||||
await fetchChannel();
|
||||
} catch (e) {
|
||||
console.error('Failed to tag channel', e);
|
||||
} finally {
|
||||
setTimeout(async () => {
|
||||
// Delay fetch because config needs to be written.
|
||||
await fetchChannel();
|
||||
}, 500);
|
||||
console.error('Failed to update channel:', e);
|
||||
}
|
||||
};
|
||||
|
||||
// Handler for fetching tag info
|
||||
const handleGetTagInfo = async (tagName) => {
|
||||
return await tagChannelInfo(channelId, tagName);
|
||||
};
|
||||
const deleteButton = <APIButton
|
||||
color='red'
|
||||
size='small'
|
||||
confirmContent='Are you sure you want to delete this channel? No video files will be deleted.'
|
||||
confirmButton='Delete'
|
||||
confirmHeader='Delete Channel?'
|
||||
onClick={handleDelete}
|
||||
obeyWROLMode={true}
|
||||
style={{marginTop: '1em'}}
|
||||
>Delete</APIButton>;
|
||||
|
||||
let tagEditModal;
|
||||
if (!create) {
|
||||
// User is editing the Tag of the Channel.
|
||||
tagEditModal = <CollectionTagModal
|
||||
const refreshButton = <APIButton
|
||||
color='blue'
|
||||
size='small'
|
||||
onClick={handleRefreshChannel}
|
||||
obeyWROLMode={true}
|
||||
style={{marginTop: '1em'}}
|
||||
>Refresh</APIButton>;
|
||||
|
||||
const tagButton = <Button
|
||||
type="button"
|
||||
size='small'
|
||||
onClick={() => setTagEditModalOpen(true)}
|
||||
color='green'
|
||||
style={{marginTop: '1em'}}
|
||||
>Tag</Button>;
|
||||
|
||||
const actionButtons = <>
|
||||
{deleteButton}
|
||||
{refreshButton}
|
||||
{tagButton}
|
||||
</>;
|
||||
|
||||
const downloadMissingDataInfo = 'Automatically download missing comments, etc, in the background.';
|
||||
const downloadMissingDataLabel = <>Download Missing Data<InfoPopup content={downloadMissingDataInfo}/></>;
|
||||
|
||||
return <>
|
||||
<BackButton/>
|
||||
<Link to={`/videos/channel/${channel.id}/video`}>
|
||||
<Button>Videos</Button>
|
||||
</Link>
|
||||
|
||||
<CollectionEditForm
|
||||
form={form}
|
||||
title="Edit Channel"
|
||||
wrolModeContent='Channel editing is disabled while in WROL Mode.'
|
||||
actionButtons={actionButtons}
|
||||
appliedTagName={channel?.tag_name}
|
||||
onSubmit={handleSubmit}
|
||||
>
|
||||
<Grid.Row>
|
||||
<Grid.Column width={8}>
|
||||
<InputForm
|
||||
form={form}
|
||||
label="Channel Name"
|
||||
name="name"
|
||||
placeholder="Short Channel Name"
|
||||
required={true}
|
||||
/>
|
||||
</Grid.Column>
|
||||
<Grid.Column width={8}>
|
||||
<DestinationForm
|
||||
form={form}
|
||||
label='Directory'
|
||||
name='directory'
|
||||
path='directory'
|
||||
required={true}
|
||||
/>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
<Grid.Row>
|
||||
<Grid.Column>
|
||||
<ToggleForm
|
||||
form={form}
|
||||
label={downloadMissingDataLabel}
|
||||
path='download_missing_data'
|
||||
/>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
{(channel.url || channel.rss_url) &&
|
||||
<Grid.Row>
|
||||
<Grid.Column>
|
||||
<SimpleAccordion title='Details'>
|
||||
<Grid>
|
||||
{channel.url && <Grid.Row columns={1}>
|
||||
<Grid.Column>
|
||||
<Header as='h4'>URL</Header>
|
||||
<a href={channel.url}>{channel.url}</a>
|
||||
</Grid.Column>
|
||||
</Grid.Row>}
|
||||
{channel.rss_url && <Grid.Row columns={1}>
|
||||
<Grid.Column>
|
||||
<Header as='h4'>RSS URL</Header>
|
||||
<a href={channel.rss_url}>{channel.rss_url}</a>
|
||||
</Grid.Column>
|
||||
</Grid.Row>}
|
||||
</Grid>
|
||||
</SimpleAccordion>
|
||||
</Grid.Column>
|
||||
</Grid.Row>}
|
||||
</CollectionEditForm>
|
||||
|
||||
{/* Tag Modal */}
|
||||
<CollectionTagModal
|
||||
open={tagEditModalOpen}
|
||||
onClose={() => setTagEditModalOpen(false)}
|
||||
currentTagName={channel.tag_name}
|
||||
|
|
@ -259,169 +280,10 @@ export function ChannelPage({create, header}) {
|
|||
getTagInfo={handleGetTagInfo}
|
||||
onSave={handleTagSave}
|
||||
collectionName="Channel"
|
||||
/>;
|
||||
}
|
||||
|
||||
let channelUrlRow;
|
||||
if (channel && channel.url) {
|
||||
channelUrlRow = <Grid.Row columns={1}>
|
||||
<Grid.Column>
|
||||
<Header as='h4'>URL</Header>
|
||||
<a href={channel.url}>{channel.url}</a>
|
||||
</Grid.Column>
|
||||
</Grid.Row>;
|
||||
}
|
||||
|
||||
let channelRssUrlRow;
|
||||
if (channel && channel.rss_url) {
|
||||
channelRssUrlRow = <Grid.Row columns={1}>
|
||||
<Grid.Column>
|
||||
<Header as='h4'>RSS URL</Header>
|
||||
<a href={channel.rss_url}>{channel.rss_url}</a>
|
||||
</Grid.Column>
|
||||
</Grid.Row>;
|
||||
}
|
||||
|
||||
let channelTagRow;
|
||||
if (channel && channel.tag_name) {
|
||||
channelTagRow = <Grid.Row columns={1}>
|
||||
<Grid.Column>
|
||||
{channel.tag_name && !create && <SingleTag name={channel.tag_name}/>}
|
||||
</Grid.Column>
|
||||
</Grid.Row>;
|
||||
}
|
||||
|
||||
const downloadMissingDataInfo = 'Automatically download missing comments, etc, in the background.';
|
||||
const downloadMissingDataLabel = <>Download Missing Data<InfoPopup content={downloadMissingDataInfo}/></>;
|
||||
const downloadMissingDataRow = <Grid.Row>
|
||||
<Grid.Column>
|
||||
<ToggleForm
|
||||
form={form}
|
||||
label={downloadMissingDataLabel}
|
||||
path='download_missing_data'
|
||||
/>
|
||||
</Grid.Column>
|
||||
</Grid.Row>;
|
||||
|
||||
let messageRow;
|
||||
if (error || success) {
|
||||
messageRow = <Grid.Row columns={1}>
|
||||
<Grid.Column>
|
||||
{error &&
|
||||
<Message negative
|
||||
header={messageHeader}
|
||||
content={messageContent}
|
||||
/>}
|
||||
{success &&
|
||||
<Message positive
|
||||
header={messageHeader}
|
||||
content={messageContent}
|
||||
/>}
|
||||
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
}
|
||||
|
||||
return <>
|
||||
<BackButton/>
|
||||
{!create &&
|
||||
<Link to={`/videos/channel/${channel.id}/video`}>
|
||||
<Button>Videos</Button>
|
||||
</Link>}
|
||||
/>
|
||||
|
||||
{/* Downloads Segment */}
|
||||
<Segment>
|
||||
<Header as="h1">{header}</Header>
|
||||
<WROLModeMessage content='Channel page is disabled while WROL Mode is enabled.'/>
|
||||
<Form
|
||||
id="editChannel"
|
||||
error={error}
|
||||
success={success}
|
||||
autoComplete="off"
|
||||
>
|
||||
<Grid stackable columns={2}>
|
||||
<Grid.Row>
|
||||
<Grid.Column>
|
||||
<InputForm
|
||||
form={form}
|
||||
label="Channel Name"
|
||||
name="name"
|
||||
placeholder="Short Channel Name"
|
||||
required={true}
|
||||
/>
|
||||
</Grid.Column>
|
||||
<Grid.Column>
|
||||
<DestinationForm
|
||||
form={form}
|
||||
label='Directory'
|
||||
name='directory'
|
||||
path='directory'
|
||||
required={true}
|
||||
/>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
{channelTagRow}
|
||||
{downloadMissingDataRow}
|
||||
{!create && (channel.url || channel.rss_url) &&
|
||||
<SimpleAccordion title='Details'>
|
||||
<Grid>
|
||||
{channelUrlRow}
|
||||
{channelRssUrlRow}
|
||||
</Grid>
|
||||
</SimpleAccordion>}
|
||||
{messageRow}
|
||||
<Grid.Row>
|
||||
<Grid.Column width={8}>
|
||||
{!create ?
|
||||
<>
|
||||
<APIButton
|
||||
color='red'
|
||||
size='small'
|
||||
confirmContent='Are you sure you want to delete this channel? No video files will be deleted.'
|
||||
confirmButton='Delete'
|
||||
confirmHeader='Delete Channel?'
|
||||
onClick={handleDelete}
|
||||
obeyWROLMode={true}
|
||||
style={{marginTop: '1em'}}
|
||||
>Delete</APIButton>
|
||||
<APIButton
|
||||
color='blue'
|
||||
size='small'
|
||||
onClick={handleRefreshChannel}
|
||||
obeyWROLMode={true}
|
||||
style={{marginTop: '1em'}}
|
||||
>Refresh</APIButton>
|
||||
<Button
|
||||
size='small'
|
||||
onClick={() => setTagEditModalOpen(true)}
|
||||
color='green'
|
||||
>Tag</Button>
|
||||
{tagEditModal}
|
||||
</>
|
||||
: <DownloadTagsSelector
|
||||
form={form}
|
||||
limit={1}
|
||||
path='tag_name'
|
||||
name='tag_name'
|
||||
/>
|
||||
}
|
||||
</Grid.Column>
|
||||
<Grid.Column>
|
||||
<APIButton
|
||||
color='violet'
|
||||
size='big'
|
||||
floated='right'
|
||||
onClick={handleSubmit}
|
||||
disabled={form.disabled}
|
||||
obeyWROLMode={true}
|
||||
>Save</APIButton>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
</Grid>
|
||||
|
||||
</Form>
|
||||
</Segment>
|
||||
|
||||
{!create && <Segment>
|
||||
<Grid columns={2}>
|
||||
<Grid.Row>
|
||||
<Grid.Column>
|
||||
|
|
@ -448,20 +310,182 @@ export function ChannelPage({create, header}) {
|
|||
</ModalContent>
|
||||
</Modal>
|
||||
|
||||
<RecurringDownloadsTable downloads={downloads} fetchDownloads={fetchChannel} onDelete={onDelete}/>
|
||||
</Segment>}
|
||||
<RecurringDownloadsTable downloads={channel?.downloads} fetchDownloads={fetchChannel} onDelete={onDelete}/>
|
||||
</Segment>
|
||||
|
||||
{channel && channel.statistics && <ChannelStatistics statistics={channel.statistics}/>}
|
||||
</>
|
||||
</>;
|
||||
}
|
||||
|
||||
export function ChannelEditPage(props) {
|
||||
return <ChannelPage header="Edit Channel" {...props}/>;
|
||||
}
|
||||
|
||||
export function ChannelNewPage(props) {
|
||||
export function ChannelNewPage() {
|
||||
useTitle('New Channel');
|
||||
return <ChannelPage header='New Channel' {...props} create/>
|
||||
|
||||
// Used to display messages to maintainer.
|
||||
const [error, setError] = useState(false);
|
||||
const [success, setSuccess] = useState(false);
|
||||
const [messageHeader, setMessageHeader] = useState();
|
||||
const [messageContent, setMessageContent] = useState();
|
||||
|
||||
const {channel, form} = useChannel(null);
|
||||
|
||||
const setErrorMessage = (header, message) => {
|
||||
setError(true);
|
||||
setSuccess(false);
|
||||
setMessageHeader(header);
|
||||
setMessageContent(message);
|
||||
}
|
||||
|
||||
const setSuccessMessage = (header, message) => {
|
||||
setError(false);
|
||||
setSuccess(true);
|
||||
setMessageHeader(header);
|
||||
setMessageContent(message);
|
||||
}
|
||||
|
||||
const handleSubmit = async () => {
|
||||
const body = {
|
||||
name: channel.name,
|
||||
directory: channel.directory,
|
||||
url: channel.url,
|
||||
download_missing_data: channel.download_missing_data,
|
||||
tag_name: _.isEmpty(channel.tag_name) ? null : channel.tag_name[0],
|
||||
};
|
||||
|
||||
let response = null;
|
||||
try {
|
||||
response = await createChannel(body);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
toast({
|
||||
type: 'error',
|
||||
title: 'Unexpected server response',
|
||||
description: 'Could not save channel',
|
||||
time: 5000,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (response && response.ok) {
|
||||
let location = response.headers.get('Location');
|
||||
let channelResponse = await fetch(location);
|
||||
let data = await channelResponse.json();
|
||||
let newChannel = data['channel'];
|
||||
|
||||
setSuccessMessage(
|
||||
'Channel created',
|
||||
<span>
|
||||
Your channel was created. View it <Link to={`/videos/channel/${newChannel.id}/edit`}>here</Link>
|
||||
</span>
|
||||
);
|
||||
} else if (response) {
|
||||
let error = await response.json();
|
||||
let cause = error.cause;
|
||||
if (cause && cause.code === 'CHANNEL_DIRECTORY_CONFLICT') {
|
||||
setErrorMessage(
|
||||
'Invalid directory',
|
||||
'This directory is already used by another channel',
|
||||
);
|
||||
} else if (cause && cause.code === 'CHANNEL_NAME_CONFLICT') {
|
||||
setErrorMessage(
|
||||
'Invalid name',
|
||||
'This channel name is already taken',
|
||||
);
|
||||
} else {
|
||||
setErrorMessage('Invalid channel', error.message || error.error || 'Unable to save channel. See logs.');
|
||||
}
|
||||
} else {
|
||||
console.error('Did not get a response for channel!');
|
||||
}
|
||||
}
|
||||
|
||||
const downloadMissingDataInfo = 'Automatically download missing comments, etc, in the background.';
|
||||
const downloadMissingDataLabel = <>Download Missing Data<InfoPopup content={downloadMissingDataInfo}/></>;
|
||||
|
||||
let messageRow;
|
||||
if (error || success) {
|
||||
messageRow = <Grid.Row columns={1}>
|
||||
<Grid.Column>
|
||||
{error &&
|
||||
<Message negative
|
||||
header={messageHeader}
|
||||
content={messageContent}
|
||||
/>}
|
||||
{success &&
|
||||
<Message positive
|
||||
header={messageHeader}
|
||||
content={messageContent}
|
||||
/>}
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
}
|
||||
|
||||
return <>
|
||||
<BackButton/>
|
||||
|
||||
<Segment>
|
||||
<Header as="h1">New Channel</Header>
|
||||
<WROLModeMessage content='Channel creation is disabled while WROL Mode is enabled.'/>
|
||||
<Form
|
||||
id="newChannel"
|
||||
error={error}
|
||||
success={success}
|
||||
autoComplete="off"
|
||||
>
|
||||
<Grid stackable columns={2}>
|
||||
<Grid.Row>
|
||||
<Grid.Column>
|
||||
<InputForm
|
||||
form={form}
|
||||
label="Channel Name"
|
||||
name="name"
|
||||
placeholder="Short Channel Name"
|
||||
required={true}
|
||||
/>
|
||||
</Grid.Column>
|
||||
<Grid.Column>
|
||||
<DestinationForm
|
||||
form={form}
|
||||
label='Directory'
|
||||
name='directory'
|
||||
path='directory'
|
||||
required={true}
|
||||
/>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
<Grid.Row>
|
||||
<Grid.Column>
|
||||
<ToggleForm
|
||||
form={form}
|
||||
label={downloadMissingDataLabel}
|
||||
path='download_missing_data'
|
||||
/>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
{messageRow}
|
||||
<Grid.Row>
|
||||
<Grid.Column width={8}>
|
||||
<DownloadTagsSelector
|
||||
form={form}
|
||||
limit={1}
|
||||
path='tag_name'
|
||||
name='tag_name'
|
||||
/>
|
||||
</Grid.Column>
|
||||
<Grid.Column>
|
||||
<APIButton
|
||||
color='violet'
|
||||
size='big'
|
||||
floated='right'
|
||||
onClick={handleSubmit}
|
||||
disabled={form.disabled}
|
||||
obeyWROLMode={true}
|
||||
>Save</APIButton>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
</Grid>
|
||||
</Form>
|
||||
</Segment>
|
||||
</>;
|
||||
}
|
||||
|
||||
export function ChannelsPage() {
|
||||
|
|
|
|||
|
|
@ -1191,7 +1191,7 @@ export function DirectorySearch({onSelect, value, disabled, required, ...props})
|
|||
isDir,
|
||||
loading,
|
||||
} = useSearchDirectories(value);
|
||||
const [results, setResults] = useState();
|
||||
const [results, setResults] = useState({});
|
||||
|
||||
useEffect(() => {
|
||||
if (directories && directories.length >= 0) {
|
||||
|
|
|
|||
|
|
@ -332,6 +332,29 @@ describe('DirectorySearch', () => {
|
|||
});
|
||||
|
||||
describe('Edge Cases', () => {
|
||||
it('renders without error when directories are null (initial state)', async () => {
|
||||
// Simulate the initial state before API call completes
|
||||
setMockHookState({
|
||||
directories: null,
|
||||
channelDirectories: null,
|
||||
domainDirectories: null,
|
||||
isDir: false,
|
||||
directoryName: '',
|
||||
loading: true,
|
||||
});
|
||||
|
||||
// This should not throw an error
|
||||
render(<DirectorySearch onSelect={mockOnSelect} value="" />);
|
||||
|
||||
const input = screen.getByPlaceholderText(/search directory names/i);
|
||||
|
||||
// Clicking input should not throw "Cannot read properties of null"
|
||||
await userEvent.click(input);
|
||||
|
||||
// Component should still be rendered
|
||||
expect(input).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('handles null/undefined initial value', () => {
|
||||
setMockHookState({
|
||||
...mockSearchResults,
|
||||
|
|
|
|||
|
|
@ -2,20 +2,10 @@ import React from 'react';
|
|||
import {render, screen, createTestForm} from '../test-utils';
|
||||
import {CollectionEditForm} from './collections/CollectionEditForm';
|
||||
import {DomainsPage} from './Archive';
|
||||
import {createMockDomain, createMockDomains} from '../test-utils';
|
||||
import {createMockDomain} from '../test-utils';
|
||||
|
||||
// Mock the TagsSelector component and TagsContext
|
||||
// Mock the TagsContext
|
||||
jest.mock('../Tags', () => ({
|
||||
TagsSelector: ({selectedTagNames, onChange, disabled}) => (
|
||||
<div data-testid="tags-selector" data-disabled={disabled}>
|
||||
<input
|
||||
data-testid="tags-input"
|
||||
value={selectedTagNames?.join(',') || ''}
|
||||
onChange={(e) => onChange(e.target.value ? [e.target.value] : [])}
|
||||
disabled={disabled}
|
||||
/>
|
||||
</div>
|
||||
),
|
||||
TagsContext: {
|
||||
_currentValue: {
|
||||
SingleTag: ({name}) => <span data-testid="applied-tag">{name}</span>
|
||||
|
|
@ -90,99 +80,76 @@ jest.mock('./collections/CollectionTable', () => ({
|
|||
),
|
||||
}));
|
||||
|
||||
// Test field configurations
|
||||
const DOMAIN_FIELDS = [
|
||||
{key: 'directory', label: 'Directory', type: 'directory', placeholder: 'Optional directory path'},
|
||||
{key: 'tag_name', label: 'Tag', type: 'tag', placeholder: 'Select or create tag', depends_on: 'directory'},
|
||||
{key: 'description', label: 'Description', type: 'textarea', placeholder: 'Optional description'}
|
||||
];
|
||||
|
||||
const DOMAIN_MESSAGES = {
|
||||
no_directory: 'Set a directory to enable tagging',
|
||||
tag_will_move: 'Tagging will move files to a new directory'
|
||||
};
|
||||
|
||||
describe('Domain Tagging Logic', () => {
|
||||
describe('Tag Field Dependency on Directory', () => {
|
||||
it('prevents tagging domain without directory', () => {
|
||||
const domainWithoutDirectory = createMockDomain({
|
||||
directory: '',
|
||||
tag_name: null,
|
||||
can_be_tagged: false
|
||||
describe('CollectionEditForm with children', () => {
|
||||
it('renders children and appliedTagName', () => {
|
||||
const mockDomain = createMockDomain({
|
||||
directory: 'archive/example.com',
|
||||
tag_name: 'News',
|
||||
});
|
||||
|
||||
const form = createTestForm(domainWithoutDirectory);
|
||||
const form = createTestForm(mockDomain);
|
||||
|
||||
render(
|
||||
<CollectionEditForm
|
||||
form={form}
|
||||
fields={DOMAIN_FIELDS}
|
||||
messages={DOMAIN_MESSAGES}
|
||||
/>
|
||||
title="Edit Domain: example.com"
|
||||
appliedTagName="News"
|
||||
>
|
||||
<div data-testid="child-content">Child content</div>
|
||||
</CollectionEditForm>
|
||||
);
|
||||
|
||||
// Should show dependency warning
|
||||
expect(screen.getByText(/set a directory to enable tagging/i)).toBeInTheDocument();
|
||||
// Should render title
|
||||
expect(screen.getByRole('heading', {level: 1})).toHaveTextContent('Edit Domain: example.com');
|
||||
|
||||
// Tag selector should be disabled
|
||||
const tagSelector = screen.getByTestId('tags-selector');
|
||||
expect(tagSelector).toHaveAttribute('data-disabled', 'true');
|
||||
// Should render children
|
||||
expect(screen.getByTestId('child-content')).toBeInTheDocument();
|
||||
|
||||
const tagInput = screen.getByTestId('tags-input');
|
||||
expect(tagInput).toBeDisabled();
|
||||
// Should render applied tag
|
||||
expect(screen.getByTestId('applied-tag')).toHaveTextContent('News');
|
||||
|
||||
// Should render Save button
|
||||
expect(screen.getByRole('button', {name: /save/i})).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('enables tagging when directory is set', () => {
|
||||
const domainWithDirectory = createMockDomain({
|
||||
it('renders action buttons', () => {
|
||||
const mockDomain = createMockDomain({
|
||||
directory: 'archive/example.com',
|
||||
tag_name: null,
|
||||
can_be_tagged: true
|
||||
});
|
||||
|
||||
const form = createTestForm(domainWithDirectory);
|
||||
const form = createTestForm(mockDomain);
|
||||
|
||||
render(
|
||||
<CollectionEditForm
|
||||
form={form}
|
||||
fields={DOMAIN_FIELDS}
|
||||
messages={DOMAIN_MESSAGES}
|
||||
/>
|
||||
title="Edit Domain"
|
||||
actionButtons={<button data-testid="action-button">Action</button>}
|
||||
>
|
||||
<div>Form content</div>
|
||||
</CollectionEditForm>
|
||||
);
|
||||
|
||||
// Dependency warning should not be shown
|
||||
expect(screen.queryByText(/set a directory to enable tagging/i)).not.toBeInTheDocument();
|
||||
|
||||
// Tag selector should be enabled
|
||||
const tagSelector = screen.getByTestId('tags-selector');
|
||||
expect(tagSelector).toHaveAttribute('data-disabled', 'false');
|
||||
|
||||
const tagInput = screen.getByTestId('tags-input');
|
||||
expect(tagInput).not.toBeDisabled();
|
||||
expect(screen.getByTestId('action-button')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows warning when directory is set (enabling tagging)', () => {
|
||||
const domainWithDirectory = createMockDomain({
|
||||
it('does not render appliedTagName when not provided', () => {
|
||||
const mockDomain = createMockDomain({
|
||||
directory: 'archive/example.com',
|
||||
tag_name: null,
|
||||
can_be_tagged: true
|
||||
});
|
||||
|
||||
const form = createTestForm(domainWithDirectory);
|
||||
const form = createTestForm(mockDomain);
|
||||
|
||||
render(
|
||||
<CollectionEditForm
|
||||
form={form}
|
||||
fields={DOMAIN_FIELDS}
|
||||
messages={DOMAIN_MESSAGES}
|
||||
/>
|
||||
title="Edit Domain"
|
||||
>
|
||||
<div>Form content</div>
|
||||
</CollectionEditForm>
|
||||
);
|
||||
|
||||
// Tag selector should be available (not disabled)
|
||||
const tagSelector = screen.getByTestId('tags-selector');
|
||||
expect(tagSelector).toHaveAttribute('data-disabled', 'false');
|
||||
|
||||
// Dependency message should not appear
|
||||
expect(screen.queryByText(/set a directory to enable tagging/i)).not.toBeInTheDocument();
|
||||
expect(screen.queryByTestId('applied-tag')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -265,50 +232,6 @@ describe('Domain Tagging Logic', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('Tag Warning Messages', () => {
|
||||
it('shows "tagging will move files" warning when tag is set', () => {
|
||||
const domainWithTag = createMockDomain({
|
||||
directory: 'archive/example.com',
|
||||
tag_name: 'News',
|
||||
can_be_tagged: true
|
||||
});
|
||||
|
||||
const form = createTestForm(domainWithTag);
|
||||
|
||||
render(
|
||||
<CollectionEditForm
|
||||
form={form}
|
||||
fields={DOMAIN_FIELDS}
|
||||
messages={DOMAIN_MESSAGES}
|
||||
/>
|
||||
);
|
||||
|
||||
// Should show move warning when tag is present
|
||||
expect(screen.getByText(/tagging will move files/i)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('does not show move warning when no tag is set', () => {
|
||||
const domainWithoutTag = createMockDomain({
|
||||
directory: 'archive/example.com',
|
||||
tag_name: null,
|
||||
can_be_tagged: true
|
||||
});
|
||||
|
||||
const form = createTestForm(domainWithoutTag);
|
||||
|
||||
render(
|
||||
<CollectionEditForm
|
||||
form={form}
|
||||
fields={DOMAIN_FIELDS}
|
||||
messages={DOMAIN_MESSAGES}
|
||||
/>
|
||||
);
|
||||
|
||||
// Should not show move warning when tag is absent
|
||||
expect(screen.queryByText(/tagging will move files/i)).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Tag Clearing Submission Bug', () => {
|
||||
it('should send empty string (not null) when clearing tag', async () => {
|
||||
// Create a domain with a tag
|
||||
|
|
|
|||
|
|
@ -1,138 +1,42 @@
|
|||
import React from 'react';
|
||||
import {Button, Form, Grid, Message, TextArea} from 'semantic-ui-react';
|
||||
import {Button, Form, Grid, Message} from 'semantic-ui-react';
|
||||
import {Header, Segment} from '../Theme';
|
||||
import {TagsSelector, TagsContext} from '../../Tags';
|
||||
import {TagsContext} from '../../Tags';
|
||||
import {WROLModeMessage} from '../Common';
|
||||
import {DestinationForm} from '../Download';
|
||||
import {InputForm} from '../../hooks/useForm';
|
||||
|
||||
/**
|
||||
* Renders a single form field based on field configuration.
|
||||
*
|
||||
* @param {Object} field - Field configuration
|
||||
* @param {Object} form - Form object from useForm hook
|
||||
* @param {Object} messages - Messages for UI hints (optional)
|
||||
*/
|
||||
function renderField(field, form, messages = {}) {
|
||||
const disabled = field.depends_on && !form.formData[field.depends_on];
|
||||
|
||||
switch (field.type) {
|
||||
case 'directory':
|
||||
return <DestinationForm
|
||||
form={form}
|
||||
label={field.label}
|
||||
name={field.key}
|
||||
path={field.key}
|
||||
required={field.required}
|
||||
/>;
|
||||
|
||||
case 'text':
|
||||
return <InputForm
|
||||
form={form}
|
||||
label={field.label}
|
||||
name={field.key}
|
||||
placeholder={field.placeholder}
|
||||
required={field.required}
|
||||
/>;
|
||||
|
||||
case 'textarea':
|
||||
const [textareaProps] = form.getCustomProps({name: field.key, path: field.key, required: field.required});
|
||||
return <Form.Field>
|
||||
<label>
|
||||
{field.label}
|
||||
{field.required && <span className="required-indicator"> *</span>}
|
||||
</label>
|
||||
<TextArea
|
||||
placeholder={field.placeholder}
|
||||
{...textareaProps}
|
||||
onChange={(e, {value}) => textareaProps.onChange(value)}
|
||||
rows={3}
|
||||
/>
|
||||
</Form.Field>;
|
||||
|
||||
case 'tag':
|
||||
const [tagProps] = form.getCustomProps({name: field.key, path: field.key, required: field.required});
|
||||
return <Form.Field disabled={disabled}>
|
||||
<label>
|
||||
{field.label}
|
||||
{field.required && <span className="required-indicator"> *</span>}
|
||||
</label>
|
||||
{disabled && <Message info size='small'>
|
||||
{messages.no_directory || 'Set a directory to enable tagging'}
|
||||
</Message>}
|
||||
<TagsSelector
|
||||
selectedTagNames={tagProps.value ? [tagProps.value] : []}
|
||||
onChange={(tagNames) => tagProps.onChange(tagNames[0] || null)}
|
||||
single={true}
|
||||
disabled={disabled || tagProps.disabled}
|
||||
/>
|
||||
{!disabled && tagProps.value && messages.tag_will_move && <Message warning size='small'>
|
||||
{messages.tag_will_move}
|
||||
</Message>}
|
||||
</Form.Field>;
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loading skeleton component for the form.
|
||||
*/
|
||||
function FormSkeleton({fieldCount = 3}) {
|
||||
return (
|
||||
<div>
|
||||
{Array.from({length: fieldCount}).map((_, i) => (
|
||||
<div key={i} className="form-skeleton-field">
|
||||
<div className="form-skeleton-label"/>
|
||||
<div className={i === fieldCount - 1 ? "form-skeleton-textarea" : "form-skeleton-input"}/>
|
||||
</div>
|
||||
))}
|
||||
<div style={{display: 'flex', justifyContent: 'flex-end', marginTop: '1em'}}>
|
||||
<div className="form-skeleton-button"/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reusable form component for editing collections (Domains, Channels, etc).
|
||||
*
|
||||
* @param {Object} form - Form object from useForm hook
|
||||
* @param {Array} fields - Array of field configurations
|
||||
* @param {Object} messages - Messages for UI hints (optional)
|
||||
* @param {Function} onCancel - Optional callback when cancel is clicked
|
||||
* @param {Function} onSubmit - Optional custom submit handler (defaults to form.onSubmit)
|
||||
* @param {String} title - Page title to display in header
|
||||
* @param {String} wrolModeContent - Content to show in WROL mode message (optional)
|
||||
* @param {React.ReactNode} actionButtons - Optional additional action buttons to display in the button row
|
||||
* @param {String} appliedTagName - Optional tag name to display (similar to ChannelEditPage pattern)
|
||||
* @param {React.ReactNode} children - Form fields to render
|
||||
*/
|
||||
export function CollectionEditForm({
|
||||
form,
|
||||
fields,
|
||||
messages = {},
|
||||
onCancel,
|
||||
onSubmit,
|
||||
title,
|
||||
wrolModeContent,
|
||||
actionButtons,
|
||||
appliedTagName
|
||||
appliedTagName,
|
||||
children
|
||||
}) {
|
||||
const {SingleTag} = React.useContext(TagsContext);
|
||||
|
||||
if (!fields || fields.length === 0) {
|
||||
return <Message warning>
|
||||
<Message.Header>No fields configured</Message.Header>
|
||||
</Message>;
|
||||
}
|
||||
|
||||
const handleSubmit = (e) => {
|
||||
e.preventDefault();
|
||||
form.onSubmit();
|
||||
if (onSubmit) {
|
||||
onSubmit(e);
|
||||
} else {
|
||||
form.onSubmit();
|
||||
}
|
||||
};
|
||||
|
||||
// Show skeleton when loading and no form data yet
|
||||
const showSkeleton = form.loading && Object.keys(form.formData).length === 0;
|
||||
|
||||
return <Segment>
|
||||
{title && <Header as="h1">{title}</Header>}
|
||||
{wrolModeContent && <WROLModeMessage content={wrolModeContent}/>}
|
||||
|
|
@ -143,51 +47,41 @@ export function CollectionEditForm({
|
|||
<p>{form.error}</p>
|
||||
</Message>}
|
||||
|
||||
{showSkeleton ? (
|
||||
<FormSkeleton fieldCount={fields.length}/>
|
||||
) : (
|
||||
<Form onSubmit={handleSubmit} loading={form.loading} autoComplete="off">
|
||||
<Grid stackable>
|
||||
{fields.map(field => (
|
||||
<Grid.Row key={field.key}>
|
||||
<Grid.Column>
|
||||
{renderField(field, form, messages)}
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
))}
|
||||
<Form onSubmit={handleSubmit} loading={form.loading} autoComplete="off">
|
||||
<Grid stackable>
|
||||
{children}
|
||||
|
||||
{appliedTagName && <Grid.Row>
|
||||
<Grid.Column>
|
||||
<SingleTag name={appliedTagName}/>
|
||||
</Grid.Column>
|
||||
</Grid.Row>}
|
||||
{appliedTagName && <Grid.Row>
|
||||
<Grid.Column>
|
||||
<SingleTag name={appliedTagName}/>
|
||||
</Grid.Column>
|
||||
</Grid.Row>}
|
||||
|
||||
<Grid.Row columns={2}>
|
||||
<Grid.Column>
|
||||
{actionButtons}
|
||||
{onCancel && <Button
|
||||
type='button'
|
||||
onClick={onCancel}
|
||||
disabled={form.disabled}
|
||||
className="action-button-spacing"
|
||||
>
|
||||
Cancel
|
||||
</Button>}
|
||||
</Grid.Column>
|
||||
<Grid.Column>
|
||||
<Button
|
||||
type='submit'
|
||||
color='violet'
|
||||
size='big'
|
||||
floated='right'
|
||||
disabled={form.disabled}
|
||||
>
|
||||
Save
|
||||
</Button>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
</Grid>
|
||||
</Form>
|
||||
)}
|
||||
<Grid.Row columns={2}>
|
||||
<Grid.Column>
|
||||
{actionButtons}
|
||||
{onCancel && <Button
|
||||
type='button'
|
||||
onClick={onCancel}
|
||||
disabled={form.disabled}
|
||||
className="action-button-spacing"
|
||||
>
|
||||
Cancel
|
||||
</Button>}
|
||||
</Grid.Column>
|
||||
<Grid.Column>
|
||||
<Button
|
||||
type='submit'
|
||||
color='violet'
|
||||
size='big'
|
||||
floated='right'
|
||||
disabled={form.disabled}
|
||||
>
|
||||
Save
|
||||
</Button>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
</Grid>
|
||||
</Form>
|
||||
</Segment>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,10 @@
|
|||
import React from 'react';
|
||||
import {render, renderInDarkMode, renderInLightMode, hasInvertedStyling, screen, waitFor, createTestForm} from '../../test-utils';
|
||||
import {render, renderInDarkMode, renderInLightMode, hasInvertedStyling, screen, createTestForm} from '../../test-utils';
|
||||
import {CollectionEditForm} from './CollectionEditForm';
|
||||
import {createMockDomain} from '../../test-utils';
|
||||
|
||||
// Mock the TagsSelector component and TagsContext
|
||||
// Mock the TagsContext
|
||||
jest.mock('../../Tags', () => ({
|
||||
TagsSelector: ({selectedTagNames, onChange, disabled}) => (
|
||||
<div data-testid="tags-selector" data-disabled={disabled}>
|
||||
<input
|
||||
data-testid="tags-input"
|
||||
value={selectedTagNames?.join(',') || ''}
|
||||
onChange={(e) => onChange(e.target.value ? [e.target.value] : [])}
|
||||
disabled={disabled}
|
||||
/>
|
||||
</div>
|
||||
),
|
||||
TagsContext: {
|
||||
_currentValue: {
|
||||
SingleTag: ({name}) => <span data-testid="applied-tag">{name}</span>
|
||||
|
|
@ -25,226 +15,90 @@ jest.mock('../../Tags', () => ({
|
|||
// Mock Common components
|
||||
jest.mock('../Common', () => ({
|
||||
...jest.requireActual('../Common'),
|
||||
WROLModeMessage: () => <div data-testid="wrol-mode-message" />,
|
||||
WROLModeMessage: ({content}) => <div data-testid="wrol-mode-message">{content}</div>,
|
||||
}));
|
||||
|
||||
// Mock DestinationForm (used for directory field)
|
||||
jest.mock('../Download', () => ({
|
||||
DestinationForm: ({form, label, name}) => (
|
||||
<div data-testid="directory-search">
|
||||
<label>{label}</label>
|
||||
<input
|
||||
value={form.formData[name] || ''}
|
||||
onChange={(e) => form.setValue(name, e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
),
|
||||
}));
|
||||
|
||||
// Mock InputForm (used for text fields)
|
||||
jest.mock('../../hooks/useForm', () => ({
|
||||
...jest.requireActual('../../hooks/useForm'),
|
||||
InputForm: ({form, label, name}) => (
|
||||
<div data-testid={`input-${name}`}>
|
||||
<label>{label}</label>
|
||||
<input
|
||||
value={form.formData[name] || ''}
|
||||
onChange={(e) => form.setValue(name, e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
),
|
||||
}));
|
||||
|
||||
// Test field configurations
|
||||
const DOMAIN_FIELDS = [
|
||||
{key: 'directory', label: 'Directory', type: 'directory', placeholder: 'Optional directory path'},
|
||||
{key: 'tag_name', label: 'Tag', type: 'tag', placeholder: 'Select or create tag', depends_on: 'directory'},
|
||||
{key: 'description', label: 'Description', type: 'textarea', placeholder: 'Optional description'}
|
||||
];
|
||||
|
||||
const DOMAIN_MESSAGES = {
|
||||
no_directory: 'Set a directory to enable tagging',
|
||||
tag_will_move: 'Tagging will move files to a new directory'
|
||||
};
|
||||
|
||||
describe('CollectionEditForm', () => {
|
||||
const mockCollection = createMockDomain();
|
||||
|
||||
describe('Form Rendering', () => {
|
||||
it('renders all configured fields', () => {
|
||||
it('renders children and Save button', () => {
|
||||
const form = createTestForm(mockCollection);
|
||||
|
||||
render(
|
||||
<CollectionEditForm
|
||||
form={form}
|
||||
fields={DOMAIN_FIELDS}
|
||||
messages={DOMAIN_MESSAGES}
|
||||
/>
|
||||
<CollectionEditForm form={form}>
|
||||
<div data-testid="child-content">Form fields here</div>
|
||||
</CollectionEditForm>
|
||||
);
|
||||
|
||||
// Check that all fields from config are rendered
|
||||
expect(screen.getByTestId('directory-search')).toBeInTheDocument();
|
||||
expect(screen.getByTestId('tags-selector')).toBeInTheDocument();
|
||||
expect(screen.getByPlaceholderText(/optional description/i)).toBeInTheDocument();
|
||||
|
||||
// Verify Save button exists
|
||||
expect(screen.getByTestId('child-content')).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', {name: /save/i})).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('loads initial values into form', () => {
|
||||
const collectionWithData = createMockDomain({
|
||||
description: 'Test description',
|
||||
directory: 'archive/example.com'
|
||||
});
|
||||
|
||||
const form = createTestForm(collectionWithData);
|
||||
it('renders title when provided', () => {
|
||||
const form = createTestForm(mockCollection);
|
||||
|
||||
render(
|
||||
<CollectionEditForm
|
||||
form={form}
|
||||
fields={DOMAIN_FIELDS}
|
||||
messages={DOMAIN_MESSAGES}
|
||||
/>
|
||||
<CollectionEditForm form={form} title="Edit Domain: example.com">
|
||||
<div>Form content</div>
|
||||
</CollectionEditForm>
|
||||
);
|
||||
|
||||
// Check description is loaded
|
||||
expect(screen.getByPlaceholderText(/optional description/i)).toHaveValue('Test description');
|
||||
// Check directory field is rendered with the value
|
||||
const directoryField = screen.getByTestId('directory-search');
|
||||
expect(directoryField).toBeInTheDocument();
|
||||
// The mocked DestinationForm renders an input inside the container
|
||||
const directoryInput = directoryField.querySelector('input');
|
||||
expect(directoryInput).toHaveValue('archive/example.com');
|
||||
expect(screen.getByRole('heading', {level: 1})).toHaveTextContent('Edit Domain: example.com');
|
||||
});
|
||||
|
||||
it('renders without errors when form is provided', () => {
|
||||
it('renders WROL mode message when provided', () => {
|
||||
const form = createTestForm(mockCollection);
|
||||
|
||||
render(
|
||||
<CollectionEditForm
|
||||
form={form}
|
||||
fields={DOMAIN_FIELDS}
|
||||
messages={DOMAIN_MESSAGES}
|
||||
/>
|
||||
wrolModeContent="Editing disabled in WROL Mode"
|
||||
>
|
||||
<div>Form content</div>
|
||||
</CollectionEditForm>
|
||||
);
|
||||
|
||||
expect(screen.getByRole('button', {name: /save/i})).toBeInTheDocument();
|
||||
expect(screen.getByTestId('wrol-mode-message')).toHaveTextContent('Editing disabled in WROL Mode');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Field Types', () => {
|
||||
it('renders textarea for description field', () => {
|
||||
it('renders action buttons when provided', () => {
|
||||
const form = createTestForm(mockCollection);
|
||||
|
||||
render(
|
||||
<CollectionEditForm
|
||||
form={form}
|
||||
fields={DOMAIN_FIELDS}
|
||||
messages={DOMAIN_MESSAGES}
|
||||
/>
|
||||
actionButtons={<button data-testid="delete-button">Delete</button>}
|
||||
>
|
||||
<div>Form content</div>
|
||||
</CollectionEditForm>
|
||||
);
|
||||
|
||||
const descriptionField = screen.getByPlaceholderText(/optional description/i);
|
||||
expect(descriptionField.tagName).toBe('TEXTAREA');
|
||||
expect(screen.getByTestId('delete-button')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders directory field using DestinationForm for type=directory', () => {
|
||||
it('renders appliedTagName when provided', () => {
|
||||
const form = createTestForm(mockCollection);
|
||||
|
||||
render(
|
||||
<CollectionEditForm
|
||||
form={form}
|
||||
fields={DOMAIN_FIELDS}
|
||||
messages={DOMAIN_MESSAGES}
|
||||
/>
|
||||
<CollectionEditForm form={form} appliedTagName="News">
|
||||
<div>Form content</div>
|
||||
</CollectionEditForm>
|
||||
);
|
||||
|
||||
expect(screen.getByTestId('directory-search')).toBeInTheDocument();
|
||||
expect(screen.getByTestId('applied-tag')).toHaveTextContent('News');
|
||||
});
|
||||
|
||||
it('renders tag selector for tag_name field', () => {
|
||||
it('does not render appliedTagName when not provided', () => {
|
||||
const form = createTestForm(mockCollection);
|
||||
|
||||
render(
|
||||
<CollectionEditForm
|
||||
form={form}
|
||||
fields={DOMAIN_FIELDS}
|
||||
messages={DOMAIN_MESSAGES}
|
||||
/>
|
||||
<CollectionEditForm form={form}>
|
||||
<div>Form content</div>
|
||||
</CollectionEditForm>
|
||||
);
|
||||
|
||||
expect(screen.getByTestId('tags-selector')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Field Dependencies (tag requires directory)', () => {
|
||||
it('disables tag field when directory is empty', () => {
|
||||
const collectionWithoutDirectory = createMockDomain({
|
||||
directory: '',
|
||||
can_be_tagged: false
|
||||
});
|
||||
|
||||
const form = createTestForm(collectionWithoutDirectory);
|
||||
|
||||
render(
|
||||
<CollectionEditForm
|
||||
form={form}
|
||||
fields={DOMAIN_FIELDS}
|
||||
messages={DOMAIN_MESSAGES}
|
||||
/>
|
||||
);
|
||||
|
||||
// Should show dependency warning
|
||||
expect(screen.getByText(/set a directory to enable tagging/i)).toBeInTheDocument();
|
||||
|
||||
// Tag selector should be disabled
|
||||
const tagSelector = screen.getByTestId('tags-selector');
|
||||
expect(tagSelector).toHaveAttribute('data-disabled', 'true');
|
||||
});
|
||||
|
||||
it('enables tag field when directory is set', () => {
|
||||
const collectionWithDirectory = createMockDomain({
|
||||
directory: 'archive/example.com',
|
||||
can_be_tagged: true
|
||||
});
|
||||
|
||||
const form = createTestForm(collectionWithDirectory);
|
||||
|
||||
render(
|
||||
<CollectionEditForm
|
||||
form={form}
|
||||
fields={DOMAIN_FIELDS}
|
||||
messages={DOMAIN_MESSAGES}
|
||||
/>
|
||||
);
|
||||
|
||||
// Dependency warning should not be shown
|
||||
expect(screen.queryByText(/set a directory to enable tagging/i)).not.toBeInTheDocument();
|
||||
|
||||
// Tag selector should not be disabled
|
||||
const tagSelector = screen.getByTestId('tags-selector');
|
||||
expect(tagSelector).toHaveAttribute('data-disabled', 'false');
|
||||
});
|
||||
|
||||
it('shows warning when tag is set with directory', () => {
|
||||
const collectionWithDirectoryAndTag = createMockDomain({
|
||||
directory: 'archive/example.com',
|
||||
tag_name: 'News',
|
||||
can_be_tagged: true
|
||||
});
|
||||
|
||||
const form = createTestForm(collectionWithDirectoryAndTag);
|
||||
|
||||
render(
|
||||
<CollectionEditForm
|
||||
form={form}
|
||||
fields={DOMAIN_FIELDS}
|
||||
messages={DOMAIN_MESSAGES}
|
||||
/>
|
||||
);
|
||||
|
||||
// Should show tag warning
|
||||
expect(screen.getByText(/tagging will move files/i)).toBeInTheDocument();
|
||||
expect(screen.queryByTestId('applied-tag')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -254,139 +108,97 @@ describe('CollectionEditForm', () => {
|
|||
const mockOnCancel = jest.fn();
|
||||
|
||||
render(
|
||||
<CollectionEditForm
|
||||
form={form}
|
||||
fields={DOMAIN_FIELDS}
|
||||
messages={DOMAIN_MESSAGES}
|
||||
onCancel={mockOnCancel}
|
||||
/>
|
||||
<CollectionEditForm form={form} onCancel={mockOnCancel}>
|
||||
<div>Form content</div>
|
||||
</CollectionEditForm>
|
||||
);
|
||||
|
||||
expect(screen.getByRole('button', {name: /cancel/i})).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('disables form during loading', () => {
|
||||
it('does not show Cancel button when onCancel not provided', () => {
|
||||
const form = createTestForm(mockCollection);
|
||||
|
||||
render(
|
||||
<CollectionEditForm form={form}>
|
||||
<div>Form content</div>
|
||||
</CollectionEditForm>
|
||||
);
|
||||
|
||||
expect(screen.queryByRole('button', {name: /cancel/i})).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('disables Save button when form is disabled', () => {
|
||||
const form = createTestForm(mockCollection, {
|
||||
overrides: {loading: true, disabled: true}
|
||||
overrides: {disabled: true}
|
||||
});
|
||||
|
||||
render(
|
||||
<CollectionEditForm
|
||||
form={form}
|
||||
fields={DOMAIN_FIELDS}
|
||||
messages={DOMAIN_MESSAGES}
|
||||
/>
|
||||
<CollectionEditForm form={form}>
|
||||
<div>Form content</div>
|
||||
</CollectionEditForm>
|
||||
);
|
||||
|
||||
// Save button should be disabled during loading
|
||||
const saveButton = screen.getByRole('button', {name: /save/i});
|
||||
expect(saveButton).toBeDisabled();
|
||||
expect(screen.getByRole('button', {name: /save/i})).toBeDisabled();
|
||||
});
|
||||
|
||||
it('disables Cancel button when form is disabled', () => {
|
||||
const form = createTestForm(mockCollection, {
|
||||
overrides: {disabled: true}
|
||||
});
|
||||
const mockOnCancel = jest.fn();
|
||||
|
||||
render(
|
||||
<CollectionEditForm form={form} onCancel={mockOnCancel}>
|
||||
<div>Form content</div>
|
||||
</CollectionEditForm>
|
||||
);
|
||||
|
||||
expect(screen.getByRole('button', {name: /cancel/i})).toBeDisabled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Error States', () => {
|
||||
it('handles missing fields gracefully', () => {
|
||||
const form = createTestForm(mockCollection);
|
||||
|
||||
render(
|
||||
<CollectionEditForm
|
||||
form={form}
|
||||
fields={null}
|
||||
messages={DOMAIN_MESSAGES}
|
||||
/>
|
||||
);
|
||||
|
||||
// Should show warning about missing fields
|
||||
expect(screen.getByText(/no fields configured/i)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('handles empty fields array gracefully', () => {
|
||||
const form = createTestForm(mockCollection);
|
||||
|
||||
render(
|
||||
<CollectionEditForm
|
||||
form={form}
|
||||
fields={[]}
|
||||
messages={DOMAIN_MESSAGES}
|
||||
/>
|
||||
);
|
||||
|
||||
// Should show warning about missing fields
|
||||
expect(screen.getByText(/no fields configured/i)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('displays form-level errors', () => {
|
||||
const form = createTestForm(mockCollection, {
|
||||
overrides: {error: 'Something went wrong'}
|
||||
});
|
||||
|
||||
render(
|
||||
<CollectionEditForm
|
||||
form={form}
|
||||
fields={DOMAIN_FIELDS}
|
||||
messages={DOMAIN_MESSAGES}
|
||||
/>
|
||||
<CollectionEditForm form={form}>
|
||||
<div>Form content</div>
|
||||
</CollectionEditForm>
|
||||
);
|
||||
|
||||
// Should display the error message
|
||||
expect(screen.getByText(/something went wrong/i)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('does not display error message when no error', () => {
|
||||
const form = createTestForm(mockCollection);
|
||||
|
||||
render(
|
||||
<CollectionEditForm form={form}>
|
||||
<div>Form content</div>
|
||||
</CollectionEditForm>
|
||||
);
|
||||
|
||||
expect(screen.queryByText(/error/i)).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Loading Skeleton', () => {
|
||||
it('shows skeleton when loading with empty form data', () => {
|
||||
const form = createTestForm({}, {
|
||||
overrides: {loading: true}
|
||||
});
|
||||
describe('Form Submission', () => {
|
||||
it('calls form.onSubmit when Save button is clicked', () => {
|
||||
const form = createTestForm(mockCollection);
|
||||
form.onSubmit = jest.fn();
|
||||
|
||||
const {container} = render(
|
||||
<CollectionEditForm
|
||||
form={form}
|
||||
fields={DOMAIN_FIELDS}
|
||||
messages={DOMAIN_MESSAGES}
|
||||
/>
|
||||
render(
|
||||
<CollectionEditForm form={form}>
|
||||
<div>Form content</div>
|
||||
</CollectionEditForm>
|
||||
);
|
||||
|
||||
// Should show skeleton elements
|
||||
expect(container.querySelector('.form-skeleton-label')).toBeInTheDocument();
|
||||
expect(container.querySelector('.form-skeleton-input')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows form (not skeleton) when loading with existing form data', () => {
|
||||
const form = createTestForm(mockCollection, {
|
||||
overrides: {loading: true}
|
||||
});
|
||||
|
||||
const {container} = render(
|
||||
<CollectionEditForm
|
||||
form={form}
|
||||
fields={DOMAIN_FIELDS}
|
||||
messages={DOMAIN_MESSAGES}
|
||||
/>
|
||||
);
|
||||
|
||||
// Should NOT show skeleton when there's form data
|
||||
expect(container.querySelector('.form-skeleton-label')).not.toBeInTheDocument();
|
||||
// Should show actual form fields
|
||||
expect(screen.getByTestId('directory-search')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders correct number of skeleton fields based on fields config', () => {
|
||||
const form = createTestForm({}, {
|
||||
overrides: {loading: true}
|
||||
});
|
||||
|
||||
const {container} = render(
|
||||
<CollectionEditForm
|
||||
form={form}
|
||||
fields={DOMAIN_FIELDS}
|
||||
messages={DOMAIN_MESSAGES}
|
||||
/>
|
||||
);
|
||||
|
||||
// Should have skeleton fields equal to fields.length (3)
|
||||
const skeletonFields = container.querySelectorAll('.form-skeleton-field');
|
||||
expect(skeletonFields).toHaveLength(DOMAIN_FIELDS.length);
|
||||
screen.getByRole('button', {name: /save/i}).click();
|
||||
expect(form.onSubmit).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -395,14 +207,11 @@ describe('CollectionEditForm', () => {
|
|||
const form = createTestForm(mockCollection);
|
||||
|
||||
const {container} = renderInDarkMode(
|
||||
<CollectionEditForm
|
||||
form={form}
|
||||
fields={DOMAIN_FIELDS}
|
||||
messages={DOMAIN_MESSAGES}
|
||||
/>
|
||||
<CollectionEditForm form={form}>
|
||||
<div>Form content</div>
|
||||
</CollectionEditForm>
|
||||
);
|
||||
|
||||
// Segment should have inverted class in dark mode
|
||||
const segment = container.querySelector('.ui.segment');
|
||||
expect(segment).toBeInTheDocument();
|
||||
expect(hasInvertedStyling(segment)).toBe(true);
|
||||
|
|
@ -412,14 +221,11 @@ describe('CollectionEditForm', () => {
|
|||
const form = createTestForm(mockCollection);
|
||||
|
||||
const {container} = renderInLightMode(
|
||||
<CollectionEditForm
|
||||
form={form}
|
||||
fields={DOMAIN_FIELDS}
|
||||
messages={DOMAIN_MESSAGES}
|
||||
/>
|
||||
<CollectionEditForm form={form}>
|
||||
<div>Form content</div>
|
||||
</CollectionEditForm>
|
||||
);
|
||||
|
||||
// Segment should NOT have inverted class in light mode
|
||||
const segment = container.querySelector('.ui.segment');
|
||||
expect(segment).toBeInTheDocument();
|
||||
expect(hasInvertedStyling(segment)).toBe(false);
|
||||
|
|
@ -429,71 +235,26 @@ describe('CollectionEditForm', () => {
|
|||
const form = createTestForm(mockCollection);
|
||||
|
||||
const {container} = renderInDarkMode(
|
||||
<CollectionEditForm
|
||||
form={form}
|
||||
fields={DOMAIN_FIELDS}
|
||||
messages={DOMAIN_MESSAGES}
|
||||
title="Test Collection"
|
||||
/>
|
||||
<CollectionEditForm form={form} title="Test Collection">
|
||||
<div>Form content</div>
|
||||
</CollectionEditForm>
|
||||
);
|
||||
|
||||
// Header should have dark text color inline style in dark mode
|
||||
const header = container.querySelector('.ui.header');
|
||||
expect(header).toBeInTheDocument();
|
||||
expect(header.style.color).toBe('rgb(238, 238, 238)'); // #eeeeee
|
||||
});
|
||||
|
||||
it('uses theme context from provider', () => {
|
||||
const form = createTestForm(mockCollection);
|
||||
|
||||
const {container} = render(
|
||||
<CollectionEditForm
|
||||
form={form}
|
||||
fields={DOMAIN_FIELDS}
|
||||
messages={DOMAIN_MESSAGES}
|
||||
/>
|
||||
);
|
||||
|
||||
const segment = container.querySelector('.ui.segment');
|
||||
expect(segment).toBeInTheDocument();
|
||||
// Should not be inverted by default
|
||||
expect(hasInvertedStyling(segment)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('CSS Classes', () => {
|
||||
it('uses required-indicator class for required fields', () => {
|
||||
const fieldsWithRequired = [
|
||||
{key: 'name', label: 'Name', type: 'text', required: true},
|
||||
{key: 'description', label: 'Description', type: 'textarea', required: true},
|
||||
];
|
||||
|
||||
const form = createTestForm(mockCollection);
|
||||
|
||||
const {container} = render(
|
||||
<CollectionEditForm
|
||||
form={form}
|
||||
fields={fieldsWithRequired}
|
||||
messages={DOMAIN_MESSAGES}
|
||||
/>
|
||||
);
|
||||
|
||||
// Should use CSS class instead of inline style for required indicator
|
||||
const requiredIndicators = container.querySelectorAll('.required-indicator');
|
||||
expect(requiredIndicators.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('uses action-button-spacing class for cancel button', () => {
|
||||
const form = createTestForm(mockCollection);
|
||||
const mockOnCancel = jest.fn();
|
||||
|
||||
const {container} = render(
|
||||
<CollectionEditForm
|
||||
form={form}
|
||||
fields={DOMAIN_FIELDS}
|
||||
messages={DOMAIN_MESSAGES}
|
||||
onCancel={mockOnCancel}
|
||||
/>
|
||||
render(
|
||||
<CollectionEditForm form={form} onCancel={mockOnCancel}>
|
||||
<div>Form content</div>
|
||||
</CollectionEditForm>
|
||||
);
|
||||
|
||||
const cancelButton = screen.getByRole('button', {name: /cancel/i});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue