Skip to content
Merged
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
28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@
"@babel/preset-typescript": "^7.24.7",
"@babel/template": "^7.24.7",
"@babel/types": "^7.24.7",
"@box/activity-feed": "^2.1.5",
"@box/blueprint-web": "^16.1.1",
"@box/blueprint-web-assets": "^5.1.1",
"@box/activity-feed": "^2.1.9",
"@box/blueprint-web": "^16.1.4",
"@box/blueprint-web-assets": "^5.2.2",
"@box/box-ai-agent-selector": "^1.39.21",
"@box/box-ai-content-answers": "^1.43.22",
"@box/box-item-type-selector": "^1.39.21",
"@box/cldr-data": "^34.2.0",
"@box/collaboration-popover": "^2.1.1",
"@box/collaboration-popover": "^2.1.4",
"@box/combobox-with-api": "^1.42.22",
"@box/content-field": "^1.40.23",
"@box/copy-input": "^1.42.16",
Expand All @@ -143,11 +143,11 @@
"@box/metadata-template-browser": "^1.24.11",
"@box/metadata-view": "^1.53.26",
"@box/react-virtualized": "^9.22.3-rc-box.10",
"@box/readable-time": "^2.1.1",
"@box/threaded-annotations": "^2.1.3",
"@box/readable-time": "^2.1.4",
"@box/threaded-annotations": "^2.1.7",
"@box/types": "^2.1.8",
"@box/unified-share-modal": "^2.15.16",
"@box/user-selector": "^2.1.2",
"@box/user-selector": "^2.1.5",
"@box/uploads-manager": "^1.17.2",
"@cfaester/enzyme-adapter-react-18": "^0.8.0",
"@chromatic-com/storybook": "^4.0.1",
Expand Down Expand Up @@ -294,14 +294,14 @@
"webpack-dev-server": "^5.2.4"
},
"peerDependencies": {
"@box/activity-feed": "^2.1.5",
"@box/blueprint-web": "^16.1.1",
"@box/blueprint-web-assets": "^5.1.1",
"@box/activity-feed": "^2.1.9",
"@box/blueprint-web": "^16.1.4",
"@box/blueprint-web-assets": "^5.2.2",
"@box/box-ai-agent-selector": "^1.39.21",
"@box/box-ai-content-answers": "^1.43.22",
"@box/box-item-type-selector": "^1.39.21",
"@box/cldr-data": ">=34.2.0",
Comment thread
jackiejou marked this conversation as resolved.
"@box/collaboration-popover": "^2.1.1",
"@box/collaboration-popover": "^2.1.4",
"@box/combobox-with-api": "^1.42.22",
"@box/content-field": "^1.40.23",
"@box/copy-input": "^1.42.16",
Expand All @@ -311,11 +311,11 @@
"@box/metadata-template-browser": "^1.24.11",
"@box/metadata-view": "^1.53.26",
"@box/react-virtualized": "^9.22.3-rc-box.10",
"@box/readable-time": "^2.1.1",
"@box/threaded-annotations": "^2.1.3",
"@box/readable-time": "^2.1.4",
"@box/threaded-annotations": "^2.1.7",
"@box/types": "^2.1.8",
"@box/unified-share-modal": "^2.15.16",
"@box/user-selector": "^2.1.2",
"@box/user-selector": "^2.1.5",
"@box/uploads-manager": "^1.17.2",
"@hapi/address": "^2.1.4",
"@tanstack/react-virtual": "^3.13.12",
Expand Down
164 changes: 85 additions & 79 deletions src/elements/content-sidebar/__tests__/SidebarFileProperties.test.js
Original file line number Diff line number Diff line change
@@ -1,99 +1,105 @@
import set from 'lodash/set';
import * as React from 'react';
import { shallow, mount } from 'enzyme';
import ItemProperties from '../../../features/item-details/ItemProperties';
import InlineError from '../../../components/inline-error/InlineError';
import { render, screen } from '../../../test-utils/testing-library';

import SidebarFileProperties, { SidebarFilePropertiesComponent } from '../SidebarFileProperties';
import { PLACEHOLDER_USER } from '../../../constants';

describe('elements/content-sidebar/SidebarFileProperties', () => {
const getWrapper = props => shallow(<SidebarFilePropertiesComponent {...props} />);
const getMountWrapper = props => mount(<SidebarFilePropertiesComponent {...props} />);
const props = {
file: {
content_created_at: '2018-04-18T16:56:05.352Z',
content_modified_at: '2018-04-18T16:56:05.352Z',
description: 'foo',
owned_by: {
name: 'foo',
},
created_by: {
name: 'foo',
},
metadata: {
global: {
archivedItemTemplate: {
archiveDate: '1726832355000',
},
},
const baseFile = {
content_created_at: '2018-04-18T16:56:05.352Z',
content_modified_at: '2018-04-18T16:56:05.352Z',
created_by: { name: 'foo' },
description: 'foo',
metadata: {
global: {
archivedItemTemplate: { archiveDate: '1726832355000' },
},
size: '1',
permissions: {
can_rename: true,
},
uploader_display_name: 'File Request',
},
onDescriptionChange: jest.fn(),
intl: {
locale: 'en',
},
owned_by: { name: 'foo' },
permissions: { can_rename: true },
size: '1',
uploader_display_name: 'File Request',
};

const retentionPolicyProps = {
file: {
size: '1',
},
hasRetentionPolicy: true,
onRetentionPolicyExtendClick: jest.fn(),
retentionPolicy: {
dispositionTime: 1556317461,
policyName: 'test policy',
policyType: 'finite',
retentionPolicyDescription: 'test policy (1 year retention & auto-deletion',
},
intl: {
locale: 'en',
},
const baseProps = {
file: baseFile,
intl: { locale: 'en' },
onDescriptionChange: jest.fn(),
};

describe('render()', () => {
test('should render ItemProperties', () => {
const wrapper = getWrapper(props);
test('should render ItemProperties with file details', () => {
render(<SidebarFilePropertiesComponent {...baseProps} />);

expect(wrapper.find(ItemProperties)).toHaveLength(1);
expect(wrapper).toMatchSnapshot();
});
expect(screen.getByTestId('item-properties')).toBeVisible();
expect(screen.getByText('Owner')).toBeVisible();
expect(screen.getByText('Uploader')).toBeVisible();
expect(screen.getByText('Created')).toBeVisible();
expect(screen.getByText('Modified')).toBeVisible();
expect(screen.getByText('Archived')).toBeVisible();
expect(screen.getByText('Size')).toBeVisible();
expect(screen.getAllByText('foo').length).toBeGreaterThan(0);
expect(screen.getByText('1 B')).toBeVisible();

test('should render ItemProperties for anonymous uploaders', () => {
const propsHere = set({ ...props }, 'file.created_by.id', PLACEHOLDER_USER.id);
const wrapper = getWrapper(propsHere);
const description = screen.getByDisplayValue('foo');
expect(description).toHaveAttribute('data-resin-target', 'description');
});

expect(wrapper.find(ItemProperties)).toHaveLength(1);
expect(wrapper).toMatchSnapshot();
});
test('should use uploader_display_name when uploader is anonymous', () => {
const props = {
...baseProps,
file: {
...baseFile,
created_by: { ...baseFile.created_by, id: PLACEHOLDER_USER.id },
},
};

test('should render an error', () => {
const fakeError = {
id: 'foo',
description: 'bar',
defaultMessage: 'baz',
};
render(<SidebarFilePropertiesComponent {...props} />);

expect(screen.getByText('Uploader')).toBeVisible();
expect(screen.getByText('File Request')).toBeVisible();
});

test('should render an inline error along with the wrapped component', () => {
const fakeError = {
defaultMessage: 'baz',
description: 'bar',
id: 'foo',
};

render(
<SidebarFileProperties
file={baseFile}
inlineError={{ content: fakeError, title: fakeError }}
onDescriptionChange={jest.fn()}
/>,
);

const errorTitles = screen.getAllByText('baz');
expect(errorTitles.length).toBeGreaterThan(0);
expect(screen.getByTestId('item-properties')).toBeVisible();
});

const errorProps = {
inlineError: {
title: fakeError,
content: fakeError,
},
};
const wrapper = shallow(<SidebarFileProperties {...errorProps} />).dive();
test('should render retention policy information when hasRetentionPolicy is set', () => {
const onRetentionPolicyExtendClick = jest.fn();

expect(wrapper.find(InlineError)).toHaveLength(1);
expect(wrapper).toMatchSnapshot();
});
render(
<SidebarFilePropertiesComponent
file={{ size: '1' }}
hasRetentionPolicy
intl={{ locale: 'en' }}
onRetentionPolicyExtendClick={onRetentionPolicyExtendClick}
retentionPolicy={{
dispositionTime: 1556317461,
policyName: 'test policy',
policyType: 'finite',
retentionPolicyDescription: 'test policy (1 year retention & auto-deletion',
}}
/>,
);

test('should render retention policy information when given proper props and callback', () => {
const wrapper = getMountWrapper(retentionPolicyProps);
expect(wrapper).toMatchSnapshot();
});
expect(screen.getByText('Policy')).toBeVisible();
expect(screen.getByText('test policy (1 year retention & auto-deletion')).toBeVisible();
expect(screen.getByText('Policy Expiration')).toBeVisible();
expect(screen.getByRole('button', { name: 'Extend' })).toBeVisible();
});
});
Loading
Loading