mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
* Trying to get rid of type guard but failing * Improve typing of scene object state * Fixed wrongly renamed event * Tweaks
69 lines
1.7 KiB
TypeScript
69 lines
1.7 KiB
TypeScript
import { SceneObjectBase } from './SceneObjectBase';
|
|
import { SceneLayoutChild, SceneObject, SceneObjectStatePlain } from './types';
|
|
|
|
interface TestSceneState extends SceneObjectStatePlain {
|
|
name?: string;
|
|
nested?: SceneObject<TestSceneState>;
|
|
children?: SceneLayoutChild[];
|
|
actions?: SceneObject[];
|
|
}
|
|
|
|
class TestScene extends SceneObjectBase<TestSceneState> {}
|
|
|
|
describe('SceneObject', () => {
|
|
it('Can clone', () => {
|
|
const scene = new TestScene({
|
|
nested: new TestScene({
|
|
name: 'nested',
|
|
}),
|
|
children: [
|
|
new TestScene({
|
|
name: 'layout child',
|
|
}),
|
|
],
|
|
});
|
|
|
|
scene.state.nested?.activate();
|
|
|
|
const clone = scene.clone();
|
|
expect(clone).not.toBe(scene);
|
|
expect(clone.state.nested).not.toBe(scene.state.nested);
|
|
expect(clone.state.nested?.isActive).toBe(undefined);
|
|
expect(clone.state.children![0]).not.toBe(scene.state.children![0]);
|
|
});
|
|
|
|
it('SceneObject should have parent when added to container', () => {
|
|
const scene = new TestScene({
|
|
nested: new TestScene({
|
|
name: 'nested',
|
|
}),
|
|
children: [
|
|
new TestScene({
|
|
name: 'layout child',
|
|
}),
|
|
],
|
|
actions: [
|
|
new TestScene({
|
|
name: 'layout child',
|
|
}),
|
|
],
|
|
});
|
|
|
|
expect(scene.parent).toBe(undefined);
|
|
expect(scene.state.nested?.parent).toBe(scene);
|
|
expect(scene.state.children![0].parent).toBe(scene);
|
|
expect(scene.state.actions![0].parent).toBe(scene);
|
|
});
|
|
|
|
it('Can clone with state change', () => {
|
|
const scene = new TestScene({
|
|
nested: new TestScene({
|
|
name: 'nested',
|
|
}),
|
|
});
|
|
|
|
const clone = scene.clone({ name: 'new name' });
|
|
expect(clone.state.name).toBe('new name');
|
|
});
|
|
});
|