ChartMetadata.test.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 { ChartMetadata } from '@superset-ui/core';
  20. describe('ChartMetadata', () => {
  21. it('exists', () => {
  22. expect(ChartMetadata).toBeDefined();
  23. });
  24. describe('new ChartMetadata({})', () => {
  25. it('creates new metadata instance', () => {
  26. const metadata = new ChartMetadata({
  27. name: 'test chart',
  28. credits: [],
  29. description: 'some kind of chart',
  30. thumbnail: 'test.png',
  31. });
  32. expect(metadata).toBeInstanceOf(ChartMetadata);
  33. });
  34. });
  35. describe('.canBeAnnotationType(type)', () => {
  36. const metadata = new ChartMetadata({
  37. name: 'test chart',
  38. canBeAnnotationTypes: ['event'],
  39. credits: [],
  40. description: 'some kind of chart',
  41. thumbnail: 'test.png',
  42. });
  43. it('returns true if can', () => {
  44. expect(metadata.canBeAnnotationType('event')).toBeTruthy();
  45. });
  46. it('returns false otherwise', () => {
  47. expect(metadata.canBeAnnotationType('invalid-type')).toBeFalsy();
  48. });
  49. });
  50. describe('.clone()', () => {
  51. const metadata = new ChartMetadata({
  52. name: 'test chart',
  53. canBeAnnotationTypes: ['event'],
  54. credits: [],
  55. description: 'some kind of chart',
  56. thumbnail: 'test.png',
  57. });
  58. const clone = metadata.clone();
  59. it('returns a new instance', () => {
  60. expect(metadata).not.toBe(clone);
  61. });
  62. it('returns a new instance with same field values', () => {
  63. expect(metadata.name).toEqual(clone.name);
  64. expect(metadata.credits).toEqual(clone.credits);
  65. expect(metadata.description).toEqual(clone.description);
  66. expect(metadata.canBeAnnotationTypes).toEqual(clone.canBeAnnotationTypes);
  67. expect(metadata.thumbnail).toEqual(clone.thumbnail);
  68. });
  69. });
  70. });