Plugin.test.ts 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. import { Plugin } from '@superset-ui/core';
  20. describe('Plugin', () => {
  21. it('exists', () => {
  22. expect(Plugin).toBeDefined();
  23. });
  24. describe('new Plugin()', () => {
  25. it('creates a new plugin', () => {
  26. const plugin = new Plugin();
  27. expect(plugin).toBeInstanceOf(Plugin);
  28. });
  29. });
  30. describe('.configure(config, replace)', () => {
  31. it('extends the default config with given config when replace is not set or false', () => {
  32. const plugin = new Plugin();
  33. plugin.configure({ key: 'abc', foo: 'bar' });
  34. plugin.configure({ key: 'def' });
  35. expect(plugin.config).toEqual({ key: 'def', foo: 'bar' });
  36. });
  37. it('replaces the default config with given config when replace is true', () => {
  38. const plugin = new Plugin();
  39. plugin.configure({ key: 'abc', foo: 'bar' });
  40. plugin.configure({ key: 'def' }, true);
  41. expect(plugin.config).toEqual({ key: 'def' });
  42. });
  43. it('returns the plugin itself', () => {
  44. const plugin = new Plugin();
  45. expect(plugin.configure({ key: 'abc' })).toBe(plugin);
  46. });
  47. });
  48. describe('.resetConfig()', () => {
  49. it('resets config back to default', () => {
  50. const plugin = new Plugin();
  51. plugin.configure({ key: 'abc', foo: 'bar' });
  52. plugin.resetConfig();
  53. expect(plugin.config).toEqual({});
  54. });
  55. it('returns the plugin itself', () => {
  56. const plugin = new Plugin();
  57. expect(plugin.resetConfig()).toBe(plugin);
  58. });
  59. });
  60. describe('.register()', () => {
  61. it('returns the plugin itself', () => {
  62. const plugin = new Plugin();
  63. expect(plugin.register()).toBe(plugin);
  64. });
  65. });
  66. describe('.unregister()', () => {
  67. it('returns the plugin itself', () => {
  68. const plugin = new Plugin();
  69. expect(plugin.unregister()).toBe(plugin);
  70. });
  71. });
  72. });