Skip to content

Commit

Permalink
Extracts types and fixes tests
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-s-molina committed Sep 7, 2022
1 parent ceeef67 commit f4dd980
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ test('renders the items sorted', () => {
const { container } = render(<MetadataBar items={ITEMS.slice(0, 6)} />);
const nodes = container.firstChild?.childNodes as NodeListOf<HTMLElement>;
expect(within(nodes[0]).getByText(DASHBOARD_TITLE)).toBeInTheDocument();
expect(within(nodes[1]).getByText(ROWS_TITLE)).toBeInTheDocument();
expect(within(nodes[2]).getByText(SQL_TITLE)).toBeInTheDocument();
expect(within(nodes[1]).getByText(SQL_TITLE)).toBeInTheDocument();
expect(within(nodes[2]).getByText(ROWS_TITLE)).toBeInTheDocument();
expect(within(nodes[3]).getByText(DESCRIPTION_VALUE)).toBeInTheDocument();
expect(within(nodes[4]).getByText(CREATED_BY)).toBeInTheDocument();
});
Expand Down Expand Up @@ -221,7 +221,7 @@ test('correctly renders the owner tooltip', async () => {
test('correctly renders the rows tooltip', async () => {
await runWithBarCollapsed(async () => {
render(<MetadataBar items={ITEMS.slice(4, 8)} />);
userEvent.hover(screen.getAllByRole('img')[0]);
userEvent.hover(screen.getAllByRole('img')[2]);
const tooltip = await screen.findByRole('tooltip');
expect(tooltip).toBeInTheDocument();
expect(within(tooltip).getByText(ROWS_TITLE)).toBeInTheDocument();
Expand All @@ -241,7 +241,7 @@ test('correctly renders the sql tooltip', async () => {
test('correctly renders the table tooltip', async () => {
await runWithBarCollapsed(async () => {
render(<MetadataBar items={ITEMS.slice(4, 8)} />);
userEvent.hover(screen.getAllByRole('img')[2]);
userEvent.hover(screen.getAllByRole('img')[0]);
const tooltip = await screen.findByRole('tooltip');
expect(tooltip).toBeInTheDocument();
expect(within(tooltip).getByText(TABLE_TITLE)).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
BinaryQueryObjectFilterClause,
css,
ensureIsArray,
GenericDataType,
t,
useTheme,
QueryFormData,
Expand All @@ -47,32 +46,7 @@ import Alert from 'src/components/Alert';
import { useApiV1Resource } from 'src/hooks/apiResources';
import TableControls from './TableControls';
import { getDrillPayload } from './utils';

type ResultsPage = {
total: number;
data: Record<string, any>[];
colNames: string[];
colTypes: GenericDataType[];
};

type Dataset = {
changed_by?: {
first_name: string;
last_name: string;
};
created_by?: {
first_name: string;
last_name: string;
};
changed_on: Date;
created_on: Date;
description: string;
table_name: string;
owners: {
first_name: string;
last_name: string;
}[];
};
import { Dataset, ResultsPage } from './types';

const PAGE_SIZE = 50;

Expand Down Expand Up @@ -284,9 +258,10 @@ export default function DrillDetailPane({
owners,
} = result;
const notAvailable = t('Not available');
const createdBy = created_by
? `${created_by.first_name} ${created_by.last_name}`
: notAvailable;
const createdBy =
`${created_by?.first_name ?? ''} ${
created_by?.last_name ?? ''
}`.trim() || notAvailable;
const modifiedBy = changed_by
? `${changed_by.first_name} ${changed_by.last_name}`
: notAvailable;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* 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 { GenericDataType } from '@superset-ui/core';

export type ResultsPage = {
total: number;
data: Record<string, any>[];
colNames: string[];
colTypes: GenericDataType[];
};

export type Dataset = {
changed_by?: {
first_name: string;
last_name: string;
};
created_by?: {
first_name: string;
last_name: string;
};
changed_on: Date;
created_on: Date;
description: string;
table_name: string;
owners: {
first_name: string;
last_name: string;
}[];
};

0 comments on commit f4dd980

Please sign in to comment.