2021-08-26 10:33:15 +00:00
|
|
|
import {shallow} from 'enzyme';
|
|
|
|
import React from 'react';
|
2022-08-13 08:20:06 +00:00
|
|
|
import {Responsive} from 'react-grid-layout';
|
2021-08-26 10:33:15 +00:00
|
|
|
|
|
|
|
import * as Dashboard from 'src/main/components/Dashboard';
|
|
|
|
|
|
|
|
describe('src/main/components/Dashboard', () => {
|
2022-08-13 08:20:06 +00:00
|
|
|
describe('ControlledDashboard', () => {
|
2021-08-26 10:33:15 +00:00
|
|
|
let layout = null;
|
|
|
|
let mockOnGridLayoutChange = null;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2022-08-13 08:20:06 +00:00
|
|
|
layout = [
|
|
|
|
{i: 'test2', x: 1, y: 0, w: 1, h: 1},
|
|
|
|
{i: 'test', x: 0, y: 0, w: 1, h: 3},
|
|
|
|
];
|
2021-08-26 10:33:15 +00:00
|
|
|
mockOnGridLayoutChange = jasmine.createSpy();
|
|
|
|
});
|
|
|
|
|
2022-08-13 08:20:06 +00:00
|
|
|
it('configures and renders the Responsive grid', () => {
|
2021-08-26 10:33:15 +00:00
|
|
|
// Given
|
|
|
|
const component = shallow(
|
2022-08-13 08:20:06 +00:00
|
|
|
<Dashboard.ControlledDashboard
|
2021-08-26 10:33:15 +00:00
|
|
|
layout={layout}
|
2022-08-13 08:20:06 +00:00
|
|
|
width={1024}
|
2021-08-26 10:33:15 +00:00
|
|
|
onGridLayoutChange={mockOnGridLayoutChange}
|
|
|
|
>
|
|
|
|
<span key="test">It works!</span>
|
2022-08-13 08:20:06 +00:00
|
|
|
</Dashboard.ControlledDashboard>
|
2021-08-26 10:33:15 +00:00
|
|
|
);
|
|
|
|
|
2022-08-13 08:20:06 +00:00
|
|
|
const expectedLayouts = {
|
|
|
|
lg: layout,
|
|
|
|
md: [
|
|
|
|
{i: 'test', x: 0, y: 0, w: 12, h: 3},
|
|
|
|
{i: 'test2', x: 0, y: 3, w: 12, h: 1},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
2021-08-26 10:33:15 +00:00
|
|
|
// Then
|
2022-08-13 08:20:06 +00:00
|
|
|
const responsiveGrid = component.find(Responsive).at(0);
|
|
|
|
expect(responsiveGrid.exists()).toBe(true);
|
|
|
|
expect(responsiveGrid.prop('breakpoints')).toEqual({lg: 1023, md: 0});
|
|
|
|
expect(responsiveGrid.prop('cols')).toEqual({lg: 12, md: 12});
|
|
|
|
expect(responsiveGrid.prop('containerPadding')).toEqual({
|
|
|
|
lg: [10, 10],
|
|
|
|
md: [10, 10],
|
|
|
|
});
|
|
|
|
expect(responsiveGrid.prop('draggableHandle')).toEqual(
|
|
|
|
'.draggable-handle',
|
|
|
|
);
|
|
|
|
expect(responsiveGrid.prop('isDraggable')).toBe(true);
|
|
|
|
expect(responsiveGrid.prop('isResizable')).toBe(true);
|
|
|
|
expect(responsiveGrid.prop('layouts')).toEqual(expectedLayouts);
|
|
|
|
expect(responsiveGrid.prop('rowHeight')).toEqual(30);
|
|
|
|
expect(responsiveGrid.prop('width')).toEqual(1024);
|
|
|
|
expect(responsiveGrid.prop('onLayoutChange')).toEqual(
|
2021-08-26 10:33:15 +00:00
|
|
|
mockOnGridLayoutChange
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2022-08-13 08:20:06 +00:00
|
|
|
it('renders as read-only on non-desktop screens', () => {
|
|
|
|
// Given
|
|
|
|
const component = shallow(
|
|
|
|
<Dashboard.ControlledDashboard
|
|
|
|
layout={layout}
|
|
|
|
width={1023}
|
|
|
|
onGridLayoutChange={mockOnGridLayoutChange}
|
|
|
|
>
|
|
|
|
<span key="test">It works!</span>
|
|
|
|
</Dashboard.ControlledDashboard>
|
|
|
|
);
|
|
|
|
|
|
|
|
// Then
|
|
|
|
expect(component.hasClass('read-only')).toBe(true);
|
|
|
|
|
|
|
|
const responsiveGrid = component.find(Responsive).at(0);
|
|
|
|
expect(responsiveGrid.prop('isDraggable')).toBe(false);
|
|
|
|
expect(responsiveGrid.prop('isResizable')).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders as read-only', () => {
|
|
|
|
// Given
|
|
|
|
const component = shallow(
|
|
|
|
<Dashboard.ControlledDashboard
|
|
|
|
layout={layout}
|
|
|
|
readOnly={true}
|
|
|
|
width={1024}
|
|
|
|
onGridLayoutChange={mockOnGridLayoutChange}
|
|
|
|
>
|
|
|
|
<span key="test">It works!</span>
|
|
|
|
</Dashboard.ControlledDashboard>
|
|
|
|
);
|
|
|
|
|
|
|
|
// Then
|
|
|
|
expect(component.hasClass('read-only')).toBe(true);
|
|
|
|
|
|
|
|
const responsiveGrid = component.find(Responsive).at(0);
|
|
|
|
expect(responsiveGrid.prop('isDraggable')).toBe(false);
|
|
|
|
expect(responsiveGrid.prop('isResizable')).toBe(false);
|
|
|
|
});
|
|
|
|
|
2021-08-26 10:33:15 +00:00
|
|
|
it('renders the children', () => {
|
|
|
|
// Given
|
|
|
|
const children = <span key="test">It works!</span>;
|
|
|
|
const component = shallow(
|
2022-08-13 08:20:06 +00:00
|
|
|
<Dashboard.ControlledDashboard
|
2021-08-26 10:33:15 +00:00
|
|
|
layout={layout}
|
2022-08-13 08:20:06 +00:00
|
|
|
width={1024}
|
2021-08-26 10:33:15 +00:00
|
|
|
onGridLayoutChange={mockOnGridLayoutChange}
|
|
|
|
>
|
|
|
|
{children}
|
2022-08-13 08:20:06 +00:00
|
|
|
</Dashboard.ControlledDashboard>
|
2021-08-26 10:33:15 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// Then
|
|
|
|
expect(component.contains(children)).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|