legend.test.ts 1000 B

123456789101112131415161718192021222324252627282930
  1. import { renderLegendFormat } from './legend';
  2. describe('renderLegendFormat()', () => {
  3. const labels = {
  4. a: 'AAA',
  5. b: 'BBB',
  6. 'with space': 'CCC',
  7. };
  8. it('works without any labels', () => {
  9. expect(renderLegendFormat('hello', {})).toEqual('hello');
  10. expect(renderLegendFormat('hello', labels)).toEqual('hello');
  11. });
  12. it('Simple replace', () => {
  13. expect(renderLegendFormat('value: {{a}}', labels)).toEqual('value: AAA');
  14. expect(renderLegendFormat('{{a}} {{with space}}', labels)).toEqual('AAA CCC');
  15. // not sure if this is expected... but current behavior
  16. expect(renderLegendFormat('{{ a }}', labels)).toEqual('AAA');
  17. });
  18. it('Bad syntax', () => {
  19. expect(renderLegendFormat('value: {{a}', labels)).toEqual('value: {{a}');
  20. expect(renderLegendFormat('value: {a}}}', labels)).toEqual('value: {a}}}');
  21. // Current behavior -- not sure if expected or not
  22. expect(renderLegendFormat('value: {{{a}}}', labels)).toEqual('value: {a}');
  23. });
  24. });