This commit is contained in:
NikolayRechkin 2020-01-10 13:48:20 +03:00
commit 820ed0606f
6 changed files with 94 additions and 66 deletions

View File

@ -1,13 +1,11 @@
{
"InviteLinkTitle": "Invitation link",
"HelpAnswerLinkInviteSettings": "Share the link to invite your colleagues to your portal.",
"InviteLinkValidInterval": "This link is valid for {{ count }} day only.",
"InviteLinkValidInterval": "This link is valid for {{ count }} days only.",
"CopyToClipboard": "Copy the link",
"CloseButton": "Close",
"LinkCopySuccess": "Link has been copied to the clipboard",
"GetShortenLink": "Get shortened link",
"InviteUsersAsCollaborators": "Add users as {{typeGuests, lowercase}}",
"LoadingProcessing": "Loading...",
"InviteLinkValidInterval_plural": "This link is valid for {{ count }} days only."
"LoadingProcessing": "Loading..."
}

View File

@ -1,13 +1,11 @@
{
"InviteLinkTitle": "Пригласительная ссылка",
"HelpAnswerLinkInviteSettings": "Поделитесь ссылкой, чтобы пригласить коллег на портал.",
"InviteLinkValidInterval": "Эта ссылка действительна только в течение {{ count }} дня.",
"InviteLinkValidInterval": "Эта ссылка действительна только в течение {{ count }} дней.",
"CopyToClipboard": "Копировать ссылку",
"CloseButton": "Закрыть",
"LinkCopySuccess": "Ссылка скопирована в буфер обмена",
"GetShortenLink": "Получить сокращенную ссылку",
"InviteUsersAsCollaborators": "Добавить со статусом {{typeGuests, lowercase}}",
"LoadingProcessing": "Загрузка...",
"InviteLinkValidInterval_plural": "Эта ссылка действительна только в течение {{ count }} дней."
"LoadingProcessing": "Загрузка..."
}

View File

@ -1,6 +1,6 @@
{
"name": "asc-web-components",
"version": "1.0.300",
"version": "1.0.301",
"description": "Ascensio System SIA component library",
"license": "AGPL-3.0",
"main": "dist/asc-web-components.js",

View File

@ -32,7 +32,8 @@ const baseProps = {
selectedOption: {
key: 0,
icon: 'CatalogFolderIcon',
label: "Select"
label: "Select",
default: true
},
options: baseOptions,
opened: false,
@ -41,6 +42,17 @@ const baseProps = {
scaled: true
};
const toggleDisplayProps = {
options: [],
selectedOption: {
key: 0,
label: "Selected option"
},
scaled: false,
size: "content",
displayType: "toggle"
};
describe('<ComboBox />', () => {
it('rendered without error', () => {
const wrapper = mount(
@ -76,6 +88,13 @@ describe('<ComboBox />', () => {
expect(wrapper.prop('opened')).toEqual(true);
});
it('opened without borders', () => {
const wrapper = mount(<ComboBox {...baseProps} opened={true} noBorder={true} />);
expect(wrapper.prop('opened')).toEqual(true);
expect(wrapper.prop('noBorder')).toEqual(true);
});
it('with DropDown max height', () => {
const wrapper = mount(<ComboBox {...baseProps} dropDownMaxHeight={200} />);
@ -188,26 +207,6 @@ describe('<ComboBox />', () => {
expect(wrapper.state('isOpen')).toBe(false);
});
//TODO: Remove or re-write duplicate test
/* it('causes function comboBoxClick() with opened prop', () => {
const wrapper = mount(<ComboBox {...baseProps} opened={true} />);
const instance = wrapper.instance();
instance.comboBoxClick(new Event('click'));
expect(wrapper.state('isOpen')).toBe(false);
});
//TODO: Remove or re-write duplicate test
it('causes function comboBoxClick()', () => {
const wrapper = mount(<ComboBox {...baseProps} />);
const instance = wrapper.instance();
instance.comboBoxClick(new Event('click'));
expect(wrapper.state('isOpen')).toBe(false);
}); */
it('causes function handleClick() with simulate', () => {
const wrapper = mount(<ComboBox {...baseProps} opened={true} />);
@ -224,38 +223,35 @@ describe('<ComboBox />', () => {
expect(wrapper.state('isOpen')).toBe(true);
});
it('componentDidUpdate() state lifecycle test', () => {
it('componentDidUpdate() lifecycle test', () => {
const wrapper = shallow(<ComboBox {...baseProps} />);
const instance = wrapper.instance();
const newSelected = { key: 1, label: "Select" };
wrapper.setState({ isOpen: false });
jest.spyOn(instance, 'setIsOpen');
instance.componentDidUpdate(wrapper.props(), wrapper.state());
expect(wrapper.state()).toBe(wrapper.state());
wrapper.setProps({
opened: true
});
it('componentDidUpdate() props lifecycle test', () => {
const wrapper = shallow(<ComboBox {...baseProps} />);
const instance = wrapper.instance();
expect(wrapper.props().opened).toBe(true);
wrapper.setProps({
opened: false
});
expect(wrapper.props().opened).toBe(false);
instance.componentDidUpdate({
opened: true,
selectedOption: {
key: 1,
label: "Select"
}
}, wrapper.state());
expect(wrapper.props()).toBe(wrapper.props());
selectedOption: newSelected
}, {
isOpen: true
});
it('componentWillUnmount() lifecycle test', () => {
const wrapper = mount(<ComboBox {...baseProps} opened={true} />);
const componentWillUnmount = jest.spyOn(wrapper.instance(), 'componentWillUnmount');
instance.forceUpdate(); //Need for manual re-render, enzyme issue
wrapper.unmount();
expect(componentWillUnmount).toHaveBeenCalled();
expect(instance.setIsOpen).toHaveBeenCalled();
});
it('accepts id', () => {
@ -281,4 +277,50 @@ describe('<ComboBox />', () => {
expect(wrapper.getDOMNode().style).toHaveProperty('color', 'red');
});
it('render like toggle displayType', () => {
const onToggleClick = jest.fn();
const wrapper = mount(
<ComboBox
{...toggleDisplayProps}
toggleAction={onToggleClick}
/>
);
expect(wrapper.prop('displayType')).toEqual('toggle');
});
it('click on toggle', () => {
const onToggleClick = jest.fn();
const wrapper = mount(
<ComboBox
{...toggleDisplayProps}
toggleAction={onToggleClick}
/>
);
jest.spyOn(wrapper.instance(), 'setIsOpen');
wrapper.simulate('click');
expect(onToggleClick).toHaveBeenCalled();
expect(wrapper.instance().setIsOpen).toHaveBeenCalled();
});
it('click outside', () => {
const onToggleClick = jest.fn();
const wrapper = mount(<ComboBox {...baseProps} opened toggleAction={onToggleClick} />);
const instance = wrapper.instance();
jest.spyOn(instance, 'setIsOpen');
jest.spyOn(instance, 'handleClickOutside');
instance.handleClickOutside(); //TODO: rework with simulation
expect(wrapper.state('isOpen')).toBe(false);
expect(wrapper.prop('opened')).toBe(true);
expect(instance.handleClickOutside).toHaveBeenCalled();
expect(onToggleClick).toHaveBeenCalled();
expect(instance.setIsOpen).toHaveBeenCalled();
});
});

View File

@ -35,7 +35,7 @@ class ComboBox extends React.Component {
shouldComponentUpdate(nextProps, nextState) {
const needUpdate = !isEqual(this.props, nextProps) || !isEqual(this.state, nextState);
console.log("shouldComponentUpdate", needUpdate);
//console.log("shouldComponentUpdate", needUpdate);
return needUpdate;
}
@ -45,8 +45,7 @@ class ComboBox extends React.Component {
setIsOpen = (isOpen) => this.setState({ isOpen: isOpen });
handleClickOutside = e => {
// ..handling code goes here...
console.log(`ComboBox handleClickOutside`, e);
//console.log(`ComboBox handleClickOutside`, e);
this.setState({ isOpen: !this.state.isOpen }, () => {
this.props.toggleAction && this.props.toggleAction(e, this.state.isOpen);
})
@ -68,9 +67,9 @@ class ComboBox extends React.Component {
this.props.onSelect && this.props.onSelect(option);
};
componentDidUpdate(prevProps) {
if (this.props.opened !== prevProps.opened) {
this.setIsOpen(this.props.opened);
componentDidUpdate(prevProps, prevState) {
if (this.props.opened !== prevProps.opened && this.state.isOpen !== prevState.isOpen) {
this.setIsOpen(this.state.isOpen);
}
if (this.props.selectedOption !== prevProps.selectedOption) {

View File

@ -140,15 +140,6 @@ describe('<ContextMenuButton />', () => {
expect(wrapper.props()).toBe(wrapper.props());
});
it('componentWillUnmount() props lifecycle test', () => {
const wrapper = shallow(<ContextMenuButton {...baseProps} />);
const instance = wrapper.instance();
instance.componentWillUnmount();
expect(wrapper).toExist(false);
});
it('accepts id', () => {
const wrapper = mount(
<ContextMenuButton {...baseProps} id="testId" />