mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Converts DashboardRow tests to RTL (#49722)
This commit is contained in:
parent
1595cc96e6
commit
a91ecc566b
@ -125,9 +125,6 @@ exports[`no enzyme tests`] = {
|
|||||||
"public/app/features/api-keys/ApiKeysAddedModal.test.tsx:3246264379": [
|
"public/app/features/api-keys/ApiKeysAddedModal.test.tsx:3246264379": [
|
||||||
[0, 20, 13, "RegExp match", "2409514259"]
|
[0, 20, 13, "RegExp match", "2409514259"]
|
||||||
],
|
],
|
||||||
"public/app/features/dashboard/components/DashboardRow/DashboardRow.test.tsx:1463123173": [
|
|
||||||
[0, 17, 13, "RegExp match", "2409514259"]
|
|
||||||
],
|
|
||||||
"public/app/features/dashboard/components/ShareModal/ShareLink.test.tsx:2357087833": [
|
"public/app/features/dashboard/components/ShareModal/ShareLink.test.tsx:2357087833": [
|
||||||
[0, 35, 13, "RegExp match", "2409514259"]
|
[0, 35, 13, "RegExp match", "2409514259"]
|
||||||
],
|
],
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { mount } from 'enzyme';
|
import { screen, render } from '@testing-library/react';
|
||||||
|
import userEvent from '@testing-library/user-event';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { PanelModel } from '../../state/PanelModel';
|
import { PanelModel } from '../../state/PanelModel';
|
||||||
@ -6,7 +7,7 @@ import { PanelModel } from '../../state/PanelModel';
|
|||||||
import { DashboardRow } from './DashboardRow';
|
import { DashboardRow } from './DashboardRow';
|
||||||
|
|
||||||
describe('DashboardRow', () => {
|
describe('DashboardRow', () => {
|
||||||
let wrapper: any, panel: PanelModel, dashboardMock: any;
|
let panel: PanelModel, dashboardMock: any;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
dashboardMock = {
|
dashboardMock = {
|
||||||
@ -19,39 +20,47 @@ describe('DashboardRow', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
panel = new PanelModel({ collapsed: false });
|
panel = new PanelModel({ collapsed: false });
|
||||||
wrapper = mount(<DashboardRow panel={panel} dashboard={dashboardMock} />);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should not have collapsed class when collaped is false', () => {
|
it('Should not have collapsed class when collaped is false', () => {
|
||||||
expect(wrapper.find('.dashboard-row')).toHaveLength(1);
|
render(<DashboardRow panel={panel} dashboard={dashboardMock} />);
|
||||||
expect(wrapper.find('.dashboard-row--collapsed')).toHaveLength(0);
|
const row = screen.getByTestId('dashboard-row-container');
|
||||||
|
expect(row).toBeInTheDocument();
|
||||||
|
expect(row).not.toHaveClass('dashboard-row--collapsed');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should collapse after clicking title', () => {
|
it('Should collapse after clicking title', async () => {
|
||||||
wrapper.find('.dashboard-row__title').simulate('click');
|
render(<DashboardRow panel={panel} dashboard={dashboardMock} />);
|
||||||
|
await userEvent.click(screen.getByTestId('data-testid dashboard-row-title-'));
|
||||||
|
|
||||||
expect(wrapper.find('.dashboard-row--collapsed')).toHaveLength(1);
|
const row = screen.getByTestId('dashboard-row-container');
|
||||||
|
expect(row).toHaveClass('dashboard-row--collapsed');
|
||||||
expect(dashboardMock.toggleRow.mock.calls).toHaveLength(1);
|
expect(dashboardMock.toggleRow.mock.calls).toHaveLength(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should subscribe to event during mount', () => {
|
it('Should subscribe to event during mount', () => {
|
||||||
|
render(<DashboardRow panel={panel} dashboard={dashboardMock} />);
|
||||||
expect(dashboardMock.events.subscribe.mock.calls).toHaveLength(1);
|
expect(dashboardMock.events.subscribe.mock.calls).toHaveLength(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have two actions as admin', () => {
|
it('should have a row options and delete row button', () => {
|
||||||
expect(wrapper.find('.dashboard-row__actions .pointer')).toHaveLength(2);
|
render(<DashboardRow panel={panel} dashboard={dashboardMock} />);
|
||||||
|
expect(screen.getByRole('button', { name: 'Delete row' })).toBeInTheDocument();
|
||||||
|
expect(screen.getByRole('button', { name: 'Row options' })).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not show row drag handle when cannot edit', () => {
|
it('should not show row drag handle when cannot edit', () => {
|
||||||
dashboardMock.meta.canEdit = false;
|
dashboardMock.meta.canEdit = false;
|
||||||
wrapper = mount(<DashboardRow panel={panel} dashboard={dashboardMock} />);
|
render(<DashboardRow panel={panel} dashboard={dashboardMock} />);
|
||||||
expect(wrapper.find('.dashboard-row__drag')).toHaveLength(0);
|
expect(screen.queryByTestId('dashboard-row-container')).toBeInTheDocument();
|
||||||
|
expect(screen.queryByTestId('dashboard-row-drag')).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have zero actions when cannot edit', () => {
|
it('should have zero actions when cannot edit', () => {
|
||||||
dashboardMock.meta.canEdit = false;
|
dashboardMock.meta.canEdit = false;
|
||||||
panel = new PanelModel({ collapsed: false });
|
panel = new PanelModel({ collapsed: false });
|
||||||
wrapper = mount(<DashboardRow panel={panel} dashboard={dashboardMock} />);
|
render(<DashboardRow panel={panel} dashboard={dashboardMock} />);
|
||||||
expect(wrapper.find('.dashboard-row__actions .pointer')).toHaveLength(0);
|
expect(screen.queryByRole('button', { name: 'Delete row' })).not.toBeInTheDocument();
|
||||||
|
expect(screen.queryByRole('button', { name: 'Row options' })).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -86,7 +86,7 @@ export class DashboardRow extends React.Component<DashboardRowProps, any> {
|
|||||||
const canEdit = this.props.dashboard.meta.canEdit === true;
|
const canEdit = this.props.dashboard.meta.canEdit === true;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classes}>
|
<div className={classes} data-testid="dashboard-row-container">
|
||||||
<a
|
<a
|
||||||
className="dashboard-row__title pointer"
|
className="dashboard-row__title pointer"
|
||||||
data-testid={selectors.components.DashboardRow.title(title)}
|
data-testid={selectors.components.DashboardRow.title(title)}
|
||||||
@ -105,7 +105,7 @@ export class DashboardRow extends React.Component<DashboardRowProps, any> {
|
|||||||
repeat={this.props.panel.repeat}
|
repeat={this.props.panel.repeat}
|
||||||
onUpdate={this.onUpdate}
|
onUpdate={this.onUpdate}
|
||||||
/>
|
/>
|
||||||
<a className="pointer" onClick={this.onDelete}>
|
<a className="pointer" onClick={this.onDelete} role="button" aria-label="Delete row">
|
||||||
<Icon name="trash-alt" />
|
<Icon name="trash-alt" />
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
@ -115,7 +115,7 @@ export class DashboardRow extends React.Component<DashboardRowProps, any> {
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{canEdit && <div className="dashboard-row__drag grid-drag-handle" />}
|
{canEdit && <div data-testid="dashboard-row-drag" className="dashboard-row__drag grid-drag-handle" />}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,8 @@ export const RowOptionsButton: FC<RowOptionsButtonProps> = ({ repeat, title, onU
|
|||||||
return (
|
return (
|
||||||
<a
|
<a
|
||||||
className="pointer"
|
className="pointer"
|
||||||
|
role="button"
|
||||||
|
aria-label="Row options"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
showModal(RowOptionsModal, { title, repeat, onDismiss: hideModal, onUpdate: onUpdateChange(hideModal) });
|
showModal(RowOptionsModal, { title, repeat, onDismiss: hideModal, onUpdate: onUpdateChange(hideModal) });
|
||||||
}}
|
}}
|
||||||
|
Loading…
Reference in New Issue
Block a user