mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
* First stab at new page layouts behind feature toggle * Simplifying PageHeader * Progress on a new model that can more easily support new and old page layouts * Progress * rename folder * Progress * Minor change * fixes * Fixing tests * Make breadcrumbs work * Add tests for old Page component * Adding tests for new Page component and behavior * fixing page header test * Fixed test * Moving user profile routes to navId * PageLayouts: Updates dashboards routes with navId * added missing navId * AppChrome outside route * Renaming folder * Minor fix * Updated * Fixing StoragePage * Updated * Updating translation ids * Updated snapshot * update nav translation ids (yes this is confusing) Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com> Co-authored-by: joshhunt <josh@trtr.co>
66 lines
2.2 KiB
TypeScript
66 lines
2.2 KiB
TypeScript
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
import userEvent from '@testing-library/user-event';
|
|
import React from 'react';
|
|
|
|
import { locationService } from '@grafana/runtime';
|
|
|
|
import { backendSrv } from '../../core/services/backend_srv';
|
|
|
|
import { PlaylistNewPage } from './PlaylistNewPage';
|
|
import { Playlist } from './types';
|
|
|
|
jest.mock('./usePlaylist', () => ({
|
|
// so we don't need to add dashboard items in test
|
|
usePlaylist: jest.fn().mockReturnValue({
|
|
playlist: { items: [{ title: 'First item', type: 'dashboard_by_id', order: 1, value: '1' }], loading: false },
|
|
}),
|
|
}));
|
|
|
|
jest.mock('@grafana/runtime', () => ({
|
|
...jest.requireActual('@grafana/runtime'),
|
|
getBackendSrv: () => backendSrv,
|
|
}));
|
|
|
|
jest.mock('../../core/components/TagFilter/TagFilter', () => ({
|
|
TagFilter: () => {
|
|
return <>mocked-tag-filter</>;
|
|
},
|
|
}));
|
|
|
|
function getTestContext({ name, interval, items }: Partial<Playlist> = {}) {
|
|
jest.clearAllMocks();
|
|
const playlist = { name, items, interval } as unknown as Playlist;
|
|
const backendSrvMock = jest.spyOn(backendSrv, 'post');
|
|
|
|
const { rerender } = render(<PlaylistNewPage />);
|
|
|
|
return { playlist, rerender, backendSrvMock };
|
|
}
|
|
|
|
describe('PlaylistNewPage', () => {
|
|
describe('when mounted', () => {
|
|
it('then header should be correct', () => {
|
|
getTestContext();
|
|
|
|
expect(screen.getByRole('heading', { name: /new playlist/i })).toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
describe('when submitted', () => {
|
|
it('then correct api should be called', async () => {
|
|
const { backendSrvMock } = getTestContext();
|
|
|
|
expect(locationService.getLocation().pathname).toEqual('/');
|
|
await userEvent.type(screen.getByRole('textbox', { name: /playlist name/i }), 'A Name');
|
|
fireEvent.submit(screen.getByRole('button', { name: /save/i }));
|
|
await waitFor(() => expect(backendSrvMock).toHaveBeenCalledTimes(1));
|
|
expect(backendSrvMock).toHaveBeenCalledWith('/api/playlists', {
|
|
name: 'A Name',
|
|
interval: '5m',
|
|
items: [{ title: 'First item', type: 'dashboard_by_id', order: 1, value: '1' }],
|
|
});
|
|
expect(locationService.getLocation().pathname).toEqual('/playlists');
|
|
});
|
|
});
|
|
});
|