Skip to content

Commit

Permalink
module test added
Browse files Browse the repository at this point in the history
  • Loading branch information
vitPinchuk committed Sep 30, 2024
1 parent 3f5932b commit 9210ffe
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/module.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { PanelPlugin } from '@grafana/data';

import { PanelOptions } from '@/types';

import { plugin } from './module';
import { createTableConfig } from './utils';

/*
Plugin
Expand Down Expand Up @@ -48,4 +51,39 @@ describe('plugin', () => {
*/
expect(builder.addCustomEditor).toHaveBeenCalled();
});

describe('Visibility', () => {
/**
* Add Input Implementation
* @param config
* @param result
*/
const addInputImplementation = (config: Partial<PanelOptions>, result: string[]) => (input: any) => {
if (input.showIf) {
if (input.showIf(config)) {
result.push(input.path);
}
} else {
result.push(input.path);
}
return builder;
};

it('Should show pagination editor', () => {
const shownOptionsPaths: string[] = [];

builder.addCustomEditor.mockImplementation(
addInputImplementation(
{
tables: [createTableConfig({ name: 'group1', items: [] })],
},
shownOptionsPaths
)
);

plugin['optionsSupplier'](builder);

expect(shownOptionsPaths).toEqual(expect.arrayContaining(['tables', 'tables', 'tables', 'nestedObjects']));
});
});
});

0 comments on commit 9210ffe

Please sign in to comment.