mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* DashboardScene: Action toolbar progress * Add discard confirmation modal * minor fix * Update * tweaked * Updating * Progress * Update * Update * Added some unit tests * fix test * Change name to Exit edit * Tweaks * fix test * Minor margin fix * Move share to left of edit
84 lines
2.5 KiB
TypeScript
84 lines
2.5 KiB
TypeScript
import { screen, render } from '@testing-library/react';
|
|
import userEvent from '@testing-library/user-event';
|
|
import React from 'react';
|
|
import { TestProvider } from 'test/helpers/TestProvider';
|
|
import { getGrafanaContextMock } from 'test/mocks/getGrafanaContextMock';
|
|
|
|
import { transformSaveModelToScene } from '../serialization/transformSaveModelToScene';
|
|
import { transformSceneToSaveModel } from '../serialization/transformSceneToSaveModel';
|
|
|
|
import { ToolbarActions } from './NavToolbarActions';
|
|
|
|
describe('NavToolbarActions', () => {
|
|
describe('Give an already saved dashboard', () => {
|
|
it('Should show correct buttons when not in editing', async () => {
|
|
setup();
|
|
|
|
expect(screen.queryByText('Save dashboard')).not.toBeInTheDocument();
|
|
expect(await screen.findByText('Edit')).toBeInTheDocument();
|
|
expect(await screen.findByText('Share')).toBeInTheDocument();
|
|
});
|
|
|
|
it('Should show correct buttons when editing', async () => {
|
|
setup();
|
|
|
|
await userEvent.click(await screen.findByText('Edit'));
|
|
|
|
expect(await screen.findByText('Save dashboard')).toBeInTheDocument();
|
|
expect(await screen.findByText('Exit edit')).toBeInTheDocument();
|
|
expect(screen.queryByText('Edit')).not.toBeInTheDocument();
|
|
expect(screen.queryByText('Share')).not.toBeInTheDocument();
|
|
});
|
|
|
|
it('Should show correct buttons when in settings menu', async () => {
|
|
setup();
|
|
|
|
await userEvent.click(await screen.findByText('Edit'));
|
|
await userEvent.click(await screen.findByText('Settings'));
|
|
|
|
expect(await screen.findByText('Save dashboard')).toBeInTheDocument();
|
|
expect(await screen.findByText('Back to dashboard')).toBeInTheDocument();
|
|
});
|
|
});
|
|
});
|
|
|
|
let cleanUp = () => {};
|
|
|
|
function setup() {
|
|
const dashboard = transformSaveModelToScene({
|
|
dashboard: {
|
|
title: 'hello',
|
|
uid: 'my-uid',
|
|
schemaVersion: 30,
|
|
panels: [],
|
|
version: 10,
|
|
},
|
|
meta: {
|
|
canSave: true,
|
|
},
|
|
});
|
|
|
|
// Clear any data layers
|
|
dashboard.setState({ $data: undefined });
|
|
|
|
const initialSaveModel = transformSceneToSaveModel(dashboard);
|
|
dashboard.setInitialSaveModel(initialSaveModel);
|
|
|
|
dashboard.startUrlSync();
|
|
|
|
cleanUp();
|
|
cleanUp = dashboard.activate();
|
|
|
|
const context = getGrafanaContextMock();
|
|
|
|
render(
|
|
<TestProvider grafanaContext={context}>
|
|
<ToolbarActions dashboard={dashboard} />
|
|
</TestProvider>
|
|
);
|
|
|
|
const actions = context.chrome.state.getValue().actions;
|
|
|
|
return { dashboard, actions };
|
|
}
|