mirror of
https://github.com/strapi/strapi.git
synced 2025-09-26 00:39:49 +00:00
Add missing tests
Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
parent
fa268d8d5d
commit
0a49805d61
@ -1,20 +1,9 @@
|
||||
/* eslint-disable indent */
|
||||
import styled from 'styled-components';
|
||||
import { Flex, Text } from '@buffetjs/core';
|
||||
|
||||
import { Flex } from '@buffetjs/core';
|
||||
import { activeStyle } from '../../utils';
|
||||
import Chevron from '../../../Chevron';
|
||||
|
||||
const activeStyle = theme => `
|
||||
color: ${theme.main.colors.mediumBlue};
|
||||
${Text} {
|
||||
color: ${theme.main.colors.mediumBlue};
|
||||
}
|
||||
${Chevron} {
|
||||
display: block;
|
||||
color: ${theme.main.colors.mediumBlue};
|
||||
}
|
||||
`;
|
||||
|
||||
const RowWrapper = styled(Flex)`
|
||||
height: 36px;
|
||||
padding: 1rem 0;
|
||||
|
@ -49,7 +49,7 @@ const ActionRow = ({ name, value, required, propertyActions }) => {
|
||||
// TODO
|
||||
textColor="grey"
|
||||
>
|
||||
{required && <RequiredSign>*</RequiredSign>}
|
||||
{required && <RequiredSign />}
|
||||
<Chevron icon={isActive ? 'caret-up' : 'caret-down'} />
|
||||
</RowLabel>
|
||||
<Flex style={{ flex: 1 }}>
|
||||
|
@ -5,9 +5,9 @@ import styled from 'styled-components';
|
||||
import CheckboxWithCondition from '../../../CheckboxWithCondition';
|
||||
import Chevron from '../../../Chevron';
|
||||
import CollapseLabel from '../../../CollapseLabel';
|
||||
import Curve from '../../../Curve';
|
||||
import HiddenAction from '../../../HiddenAction';
|
||||
import RequiredSign from '../../../RequiredSign';
|
||||
import Curve from './Curve';
|
||||
import { RowStyle, RowWrapper } from './row';
|
||||
import { LeftBorderTimeline, TopTimeline } from './timeline';
|
||||
import Wrapper from './Wrapper';
|
||||
@ -17,7 +17,6 @@ const SubLevelWrapper = styled.div`
|
||||
`;
|
||||
|
||||
const SubActionRow = ({ recursiveLevel, values, propertyActions }) => {
|
||||
console.log({ propertyActions });
|
||||
const [rowToOpen, setRowToOpen] = useState(null);
|
||||
const handleClickToggleSubLevel = useCallback(name => {
|
||||
setRowToOpen(prev => {
|
||||
@ -72,7 +71,7 @@ const SubActionRow = ({ recursiveLevel, values, propertyActions }) => {
|
||||
>
|
||||
{value.key}
|
||||
</Text>
|
||||
{value.required && <RequiredSign>*</RequiredSign>}
|
||||
{value.required && <RequiredSign />}
|
||||
<Chevron icon={isActive ? 'caret-up' : 'caret-down'} />
|
||||
</CollapseLabel>
|
||||
</RowStyle>
|
||||
|
@ -5,9 +5,9 @@ import styled from 'styled-components';
|
||||
import CheckboxWithCondition from '../../../CheckboxWithCondition';
|
||||
import Chevron from '../../../Chevron';
|
||||
import CollapseLabel from '../../../CollapseLabel';
|
||||
import Curve from '../../../Curve';
|
||||
import HiddenAction from '../../../HiddenAction';
|
||||
import RequiredSign from '../../../RequiredSign';
|
||||
import Curve from './Curve';
|
||||
import { RowStyle, RowWrapper } from './row';
|
||||
import { LeftBorderTimeline, TopTimeline } from './timeline';
|
||||
import Wrapper from './Wrapper';
|
||||
@ -71,7 +71,7 @@ const SubActionRow = ({ recursiveLevel, values, propertyActions }) => {
|
||||
>
|
||||
{value.key}
|
||||
</Text>
|
||||
{value.required && <RequiredSign>*</RequiredSign>}
|
||||
{value.required && <RequiredSign />}
|
||||
<Chevron icon={isActive ? 'caret-up' : 'caret-down'} />
|
||||
</CollapseLabel>
|
||||
</RowStyle>
|
||||
|
@ -1,18 +1,8 @@
|
||||
import styled from 'styled-components';
|
||||
import { Flex, Text } from '@buffetjs/core';
|
||||
import { Flex } from '@buffetjs/core';
|
||||
import PropTypes from 'prop-types';
|
||||
import Chevron from '../../../Chevron';
|
||||
|
||||
const activeStyle = theme => `
|
||||
color: ${theme.main.colors.mediumBlue};
|
||||
${Text} {
|
||||
color: ${theme.main.colors.mediumBlue};
|
||||
}
|
||||
${Chevron} {
|
||||
display: block;
|
||||
color: ${theme.main.colors.mediumBlue};
|
||||
}
|
||||
`;
|
||||
import { activeStyle } from '../../utils';
|
||||
|
||||
const RowStyle = styled.div`
|
||||
padding-left: ${({ theme }) => theme.main.sizes.paddings.xs};
|
||||
|
@ -2,7 +2,7 @@ import React, { useCallback, useMemo } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import Collapse from './Collapse';
|
||||
import CollapsePropertyMatrix from './CollapsePropertyMatrix';
|
||||
import getAvailableActions from './utils/getAvailableActions';
|
||||
import { getAvailableActions } from './utils';
|
||||
import Wrapper from './Wrapper';
|
||||
|
||||
const ContentTypeCollapse = ({
|
||||
|
@ -0,0 +1,16 @@
|
||||
// import styled from 'styled-components';
|
||||
import { Text } from '@buffetjs/core';
|
||||
import Chevron from '../../Chevron';
|
||||
|
||||
const activeStyle = theme => `
|
||||
color: ${theme.main.colors.mediumBlue};
|
||||
${Text} {
|
||||
color: ${theme.main.colors.mediumBlue};
|
||||
}
|
||||
${Chevron} {
|
||||
display: block;
|
||||
color: ${theme.main.colors.mediumBlue};
|
||||
}
|
||||
`;
|
||||
|
||||
export default activeStyle;
|
@ -0,0 +1,2 @@
|
||||
export { default as activeStyle } from './activeStyle';
|
||||
export { default as getAvailableActions } from './getAvailableActions';
|
@ -0,0 +1,110 @@
|
||||
import getAvailableActions from '../getAvailableActions';
|
||||
|
||||
describe('ADMIN | COMPONENTS | Permissions | ContentTypeCollapse | utils | getAvailableActions', () => {
|
||||
it('should return an empty array', () => {
|
||||
expect(getAvailableActions([])).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('should set the isDisplayed key to false to all actions if the subject value does not match the target', () => {
|
||||
const actions = [
|
||||
{
|
||||
label: 'Create',
|
||||
actionId: 'content-manager.explorer.create',
|
||||
subjects: ['restaurant', 'address'],
|
||||
applyToProperties: ['fields', 'locales'],
|
||||
},
|
||||
{
|
||||
label: 'Read',
|
||||
actionId: 'content-manager.explorer.read',
|
||||
subjects: ['restaurant', 'address'],
|
||||
applyToProperties: ['fields', 'locales'],
|
||||
},
|
||||
];
|
||||
const expected = [
|
||||
{
|
||||
label: 'Create',
|
||||
actionId: 'content-manager.explorer.create',
|
||||
subjects: ['restaurant', 'address'],
|
||||
applyToProperties: ['fields', 'locales'],
|
||||
isDisplayed: false,
|
||||
},
|
||||
{
|
||||
label: 'Read',
|
||||
actionId: 'content-manager.explorer.read',
|
||||
subjects: ['restaurant', 'address'],
|
||||
applyToProperties: ['fields', 'locales'],
|
||||
isDisplayed: false,
|
||||
},
|
||||
];
|
||||
|
||||
expect(getAvailableActions(actions, 'test')).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should set the isDisplayed key to false for the actions which the type of the subjects value is not an array', () => {
|
||||
const actions = [
|
||||
{
|
||||
label: 'Create',
|
||||
actionId: 'content-manager.explorer.create',
|
||||
subjects: 'test',
|
||||
applyToProperties: ['fields', 'locales'],
|
||||
},
|
||||
{
|
||||
label: 'Read',
|
||||
actionId: 'content-manager.explorer.read',
|
||||
applyToProperties: ['fields', 'locales'],
|
||||
},
|
||||
];
|
||||
const expected = [
|
||||
{
|
||||
label: 'Create',
|
||||
actionId: 'content-manager.explorer.create',
|
||||
subjects: 'test',
|
||||
applyToProperties: ['fields', 'locales'],
|
||||
isDisplayed: false,
|
||||
},
|
||||
{
|
||||
label: 'Read',
|
||||
actionId: 'content-manager.explorer.read',
|
||||
applyToProperties: ['fields', 'locales'],
|
||||
isDisplayed: false,
|
||||
},
|
||||
];
|
||||
|
||||
expect(getAvailableActions(actions, 'test')).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should set the isDisplayed key to false for the action which include the targetSubject in the subjects value array', () => {
|
||||
const actions = [
|
||||
{
|
||||
label: 'Create',
|
||||
actionId: 'content-manager.explorer.create',
|
||||
subjects: ['restaurant', 'address'],
|
||||
applyToProperties: ['fields', 'locales'],
|
||||
},
|
||||
{
|
||||
label: 'Read',
|
||||
actionId: 'content-manager.explorer.read',
|
||||
subjects: [],
|
||||
applyToProperties: ['fields', 'locales'],
|
||||
},
|
||||
];
|
||||
const expected = [
|
||||
{
|
||||
label: 'Create',
|
||||
actionId: 'content-manager.explorer.create',
|
||||
subjects: ['restaurant', 'address'],
|
||||
applyToProperties: ['fields', 'locales'],
|
||||
isDisplayed: true,
|
||||
},
|
||||
{
|
||||
label: 'Read',
|
||||
actionId: 'content-manager.explorer.read',
|
||||
subjects: [],
|
||||
applyToProperties: ['fields', 'locales'],
|
||||
isDisplayed: false,
|
||||
},
|
||||
];
|
||||
|
||||
expect(getAvailableActions(actions, 'address')).toEqual(expected);
|
||||
});
|
||||
});
|
@ -1,4 +1,4 @@
|
||||
import React from 'react';
|
||||
import React, { memo } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
const Curve = props => (
|
||||
@ -32,4 +32,4 @@ Curve.propTypes = {
|
||||
fill: PropTypes.string,
|
||||
};
|
||||
|
||||
export default Curve;
|
||||
export default memo(Curve);
|
@ -1,8 +1,11 @@
|
||||
import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
|
||||
const RequiredSign = styled.span`
|
||||
const Required = styled.span`
|
||||
color: ${({ theme }) => theme.main.colors.red};
|
||||
padding-left: 2px;
|
||||
`;
|
||||
|
||||
const RequiredSign = () => <Required>*</Required>;
|
||||
|
||||
export default RequiredSign;
|
||||
|
Loading…
x
Reference in New Issue
Block a user