2021-10-28 06:27:35 -04:00
|
|
|
/*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
* or more contributor license agreements. See the NOTICE file
|
|
|
|
* distributed with this work for additional information
|
|
|
|
* regarding copyright ownership. The ASF licenses this file
|
|
|
|
* to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing,
|
|
|
|
* software distributed under the License is distributed on an
|
|
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
* KIND, either express or implied. See the License for the
|
|
|
|
* specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*/
|
|
|
|
|
2022-01-07 20:16:24 -05:00
|
|
|
import { Plugin, Preset } from '@superset-ui/core';
|
2018-11-01 17:20:12 -04:00
|
|
|
|
|
|
|
describe('Preset', () => {
|
|
|
|
it('exists', () => {
|
|
|
|
expect(Preset).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('new Preset()', () => {
|
|
|
|
it('creates new preset', () => {
|
|
|
|
const preset = new Preset();
|
|
|
|
expect(preset).toBeInstanceOf(Preset);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('.register()', () => {
|
|
|
|
it('register all listed presets then plugins', () => {
|
2018-12-14 17:09:48 -05:00
|
|
|
const values: number[] = [];
|
2018-11-01 17:20:12 -04:00
|
|
|
class Plugin1 extends Plugin {
|
|
|
|
register() {
|
|
|
|
values.push(1);
|
2018-12-14 17:09:48 -05:00
|
|
|
|
|
|
|
return this;
|
2018-11-01 17:20:12 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
class Plugin2 extends Plugin {
|
|
|
|
register() {
|
|
|
|
values.push(2);
|
2018-12-14 17:09:48 -05:00
|
|
|
|
|
|
|
return this;
|
2018-11-01 17:20:12 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
class Plugin3 extends Plugin {
|
|
|
|
register() {
|
|
|
|
values.push(3);
|
2018-12-14 17:09:48 -05:00
|
|
|
|
|
|
|
return this;
|
2018-11-01 17:20:12 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
class Plugin4 extends Plugin {
|
|
|
|
register() {
|
|
|
|
const { key } = this.config;
|
2020-04-30 16:50:06 -04:00
|
|
|
values.push(key as number);
|
2018-12-14 17:09:48 -05:00
|
|
|
|
|
|
|
return this;
|
2018-11-01 17:20:12 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const preset1 = new Preset({
|
|
|
|
plugins: [new Plugin1()],
|
|
|
|
});
|
|
|
|
const preset2 = new Preset({
|
|
|
|
plugins: [new Plugin2()],
|
|
|
|
});
|
|
|
|
const preset3 = new Preset({
|
|
|
|
presets: [preset1, preset2],
|
2018-12-14 17:09:48 -05:00
|
|
|
plugins: [new Plugin3(), new Plugin4().configure({ key: 9 })],
|
2018-11-01 17:20:12 -04:00
|
|
|
});
|
|
|
|
preset3.register();
|
2018-12-14 17:09:48 -05:00
|
|
|
expect(values).toEqual([1, 2, 3, 9]);
|
2018-11-01 17:20:12 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('returns itself', () => {
|
|
|
|
const preset = new Preset();
|
|
|
|
expect(preset.register()).toBe(preset);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|