grafana/public/app/features/scenes/components/NestedScene.test.tsx
Torkel Ödegaard 4aae9d1567
Scene: Support for collapsable rows via a nested scene object (#52367)
* initial row test

* Updated

* Row is more of a nested collapsable scene

* Updated

* Added test for nested scene

* Added test for nested scene
2022-07-18 20:26:10 +02:00

52 lines
1.5 KiB
TypeScript

import { screen, render } from '@testing-library/react';
import React from 'react';
import { NestedScene } from './NestedScene';
import { Scene } from './Scene';
import { SceneCanvasText } from './SceneCanvasText';
import { SceneFlexLayout } from './SceneFlexLayout';
function setup() {
const scene = new Scene({
title: 'Hello',
layout: new SceneFlexLayout({
children: [
new NestedScene({
title: 'Nested title',
canRemove: true,
canCollapse: true,
layout: new SceneFlexLayout({
children: [new SceneCanvasText({ text: 'SceneCanvasText' })],
}),
}),
],
}),
});
render(<scene.Component model={scene} />);
}
describe('NestedScene', () => {
it('Renders heading and layout', () => {
setup();
expect(screen.getByRole('heading', { name: 'Nested title' })).toBeInTheDocument();
expect(screen.getByText('SceneCanvasText')).toBeInTheDocument();
});
it('Can remove', async () => {
setup();
screen.getByRole('button', { name: 'Remove scene' }).click();
expect(screen.queryByRole('heading', { name: 'Nested title' })).not.toBeInTheDocument();
});
it('Can collapse and expand', async () => {
setup();
screen.getByRole('button', { name: 'Collapse scene' }).click();
expect(screen.queryByText('SceneCanvasText')).not.toBeInTheDocument();
screen.getByRole('button', { name: 'Expand scene' }).click();
expect(screen.getByText('SceneCanvasText')).toBeInTheDocument();
});
});