2020-05-12 20:47:41 -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.
|
|
|
|
*/
|
|
|
|
import React from 'react';
|
2022-03-29 15:11:08 -04:00
|
|
|
import { render, screen } from '@testing-library/react';
|
|
|
|
import '@testing-library/jest-dom';
|
2021-05-12 06:20:33 -04:00
|
|
|
import { GenericDataType } from '@superset-ui/core';
|
2020-05-12 20:47:41 -04:00
|
|
|
|
2020-06-18 14:04:51 -04:00
|
|
|
import { ColumnTypeLabel, ColumnTypeLabelProps } from '../../src';
|
2020-05-12 20:47:41 -04:00
|
|
|
|
|
|
|
describe('ColumnOption', () => {
|
|
|
|
const defaultProps = {
|
2021-05-12 06:20:33 -04:00
|
|
|
type: GenericDataType.STRING,
|
2020-05-12 20:47:41 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
const props = { ...defaultProps };
|
|
|
|
|
2022-03-29 15:11:08 -04:00
|
|
|
function renderColumnTypeLabel(overrides: Partial<ColumnTypeLabelProps>) {
|
|
|
|
render(<ColumnTypeLabel {...props} {...overrides} />);
|
2020-05-12 20:47:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
it('is a valid element', () => {
|
2021-11-09 07:42:28 -05:00
|
|
|
expect(React.isValidElement(<ColumnTypeLabel {...defaultProps} />)).toBe(
|
|
|
|
true,
|
|
|
|
);
|
2020-05-12 20:47:41 -04:00
|
|
|
});
|
|
|
|
it('string type shows ABC icon', () => {
|
2022-03-29 15:11:08 -04:00
|
|
|
renderColumnTypeLabel({ type: GenericDataType.STRING });
|
|
|
|
expect(screen.getByLabelText('string type icon')).toBeVisible();
|
2020-05-12 20:47:41 -04:00
|
|
|
});
|
|
|
|
it('int type shows # icon', () => {
|
2022-03-29 15:11:08 -04:00
|
|
|
renderColumnTypeLabel({ type: GenericDataType.NUMERIC });
|
|
|
|
expect(screen.getByLabelText('numeric type icon')).toBeVisible();
|
2020-05-12 20:47:41 -04:00
|
|
|
});
|
2022-03-29 15:11:08 -04:00
|
|
|
it('bool type shows 1|0 icon', () => {
|
|
|
|
renderColumnTypeLabel({ type: GenericDataType.BOOLEAN });
|
|
|
|
expect(screen.getByLabelText('boolean type icon')).toBeVisible();
|
2020-05-12 20:47:41 -04:00
|
|
|
});
|
|
|
|
it('expression type shows function icon', () => {
|
2022-03-29 15:11:08 -04:00
|
|
|
renderColumnTypeLabel({ type: 'expression' });
|
|
|
|
expect(screen.getByLabelText('function type icon')).toBeVisible();
|
2020-05-12 20:47:41 -04:00
|
|
|
});
|
|
|
|
it('unknown type shows question mark', () => {
|
2022-03-29 15:11:08 -04:00
|
|
|
renderColumnTypeLabel({ type: undefined });
|
|
|
|
expect(screen.getByLabelText('unknown type icon')).toBeVisible();
|
2020-05-12 20:47:41 -04:00
|
|
|
});
|
|
|
|
it('datetime type displays', () => {
|
2022-03-29 15:11:08 -04:00
|
|
|
renderColumnTypeLabel({ type: GenericDataType.TEMPORAL });
|
|
|
|
expect(screen.getByLabelText('temporal type icon')).toBeVisible();
|
2020-05-12 20:47:41 -04:00
|
|
|
});
|
|
|
|
});
|