superset/superset-frontend/packages/superset-ui-core/test/number-format/NumberFormatterRegistrySingleton.test.ts

59 lines
2.1 KiB
TypeScript
Raw Normal View History

/*
* 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.
*/
import {
NumberFormatterRegistry,
getNumberFormatterRegistry,
getNumberFormatter,
formatNumber,
} from '@superset-ui/core';
describe('NumberFormatterRegistrySingleton', () => {
describe('getNumberFormatterRegistry()', () => {
chore(frontend-tests): Spelling (#19853) * spelling: against Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: been Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: charts Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: clicking Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: columns Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: duplicate Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: especially Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: extensions Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: fields Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: filter Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: for Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: label Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: labeled Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: nativefilter Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: registry Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: render Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: resizable Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: response Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: successful Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: transform Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: unfortunately Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: until Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: virtual Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> * spelling: wrapper Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-26 13:35:01 -04:00
it('returns a NumberFormatterRegistry', () => {
expect(getNumberFormatterRegistry()).toBeInstanceOf(
NumberFormatterRegistry,
);
});
});
describe('getNumberFormatter(format)', () => {
it('returns a format function', () => {
const format = getNumberFormatter('.3s');
expect(format(12345)).toEqual('12.3k');
});
it('returns a format function even given invalid format', () => {
const format = getNumberFormatter('xkcd');
expect(format(12345)).toEqual('12345 (Invalid format: xkcd)');
});
it('falls back to default format if format is not specified', () => {
const formatter = getNumberFormatter();
expect(formatter.format(100)).toEqual('100');
});
});
describe('formatNumber(format, value)', () => {
it('format the given number using the specified format', () => {
const output = formatNumber('.3s', 12345);
expect(output).toEqual('12.3k');
});
it('falls back to the default formatter if the format is undefined', () => {
expect(formatNumber(undefined, 1000)).toEqual('1k');
});
});
});