Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions specifyweb/frontend/js_src/lib/components/AppResources/Create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,17 +259,7 @@ function EditAppResource({
readonly templateFile: string | undefined;
}): JSX.Element {
const resource = React.useMemo(
() =>
deserializeResource(
addMissingFields(type.tableName as 'SpAppResource', {
// I don't think this field is used anywhere
level: 0,
mimeType,
name: name.trim(),
specifyUser: userInformation.resource_uri,
spAppResourceDir: directory.resource_uri,
})
),
() => buildNewAppResource(type, name, mimeType, directory),
[directory, name, type, mimeType]
);

Expand Down Expand Up @@ -321,6 +311,29 @@ function EditAppResource({
);
}

/**
* S6 hard-fails when opening a label whose spappresource.Description is NULL,
* so default description to the resource name on creation. See ticket #824.
*/
const buildNewAppResource = (
type: AppResourceType,
name: string,
mimeType: string | undefined,
directory: SerializedResource<SpAppResourceDir>
) =>
deserializeResource(
addMissingFields(type.tableName as 'SpAppResource', {
// I don't think this field is used anywhere
level: 0,
mimeType,
name: name.trim(),
description: name.trim(),
specifyUser: userInformation.resource_uri,
spAppResourceDir: directory.resource_uri,
})
);

export const exportsForTests = {
getUrl,
buildNewAppResource,
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ import { requireContext } from '../../../tests/helpers';
import { mount } from '../../../tests/reactUtils';
import { TestComponentWrapperRouter } from '../../../tests/utils';
import { LoadingContext } from '../../Core/Contexts';
import type { SerializedResource } from '../../DataModel/helperTypes';
import type { SpAppResourceDir } from '../../DataModel/types';
import { UnloadProtectsContext } from '../../Router/UnloadProtect';
import { CreateAppResource } from '../Create';
import { CreateAppResource, exportsForTests } from '../Create';
import { appResourceTypes } from '../types';
import { testAppResources } from './testAppResources';

const { buildNewAppResource } = exportsForTests;

requireContext();

beforeEach(() => {
Expand Down Expand Up @@ -98,3 +103,22 @@ describe('CreateAppResource', () => {
);
});
});

describe('buildNewAppResource', () => {
const directory = {
resource_uri: '/api/specify/spappresourcedir/1/',
} as SerializedResource<SpAppResourceDir>;

// Specify 6 hard-fails on labels whose spappresource.Description is NULL,
// so a freshly created resource must carry a non-null description (#824).
test('defaults description to the trimmed name', () => {
const resource = buildNewAppResource(
appResourceTypes.appResources,
' My Label ',
'text/xml',
directory
);
expect(resource.get('name')).toBe('My Label');
expect(resource.get('description')).toBe('My Label');
});
});
Loading