mirror of
https://github.com/apache/superset.git
synced 2026-05-09 18:05:52 +00:00
Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: hainenber <dotronghai96@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: hainenber <dotronghai96@gmail.com>
171 lines
5.0 KiB
TypeScript
171 lines
5.0 KiB
TypeScript
/**
|
|
* 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 { render, screen } from 'spec/helpers/testing-library';
|
|
import AllEntitiesTable from './AllEntitiesTable';
|
|
|
|
// eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks
|
|
describe('AllEntitiesTable', () => {
|
|
const mockSetShowTagModal = jest.fn();
|
|
|
|
const mockObjects = {
|
|
dashboard: [],
|
|
chart: [],
|
|
query: [],
|
|
};
|
|
|
|
const mockObjectsWithTags = {
|
|
dashboard: [
|
|
{
|
|
id: 1,
|
|
type: 'dashboard',
|
|
name: 'Sales Dashboard',
|
|
url: '/dashboard/1',
|
|
changed_on: '2023-11-20T12:34:56Z',
|
|
created_by: 1,
|
|
creator: 'John Doe',
|
|
owners: [{ id: 1, first_name: 'John', last_name: 'Doe' }],
|
|
tags: [
|
|
{ id: 101, name: 'Sales', type: 'TagType.custom' },
|
|
{ id: 42, name: 'Current Tag', type: 'TagType.custom' },
|
|
],
|
|
},
|
|
],
|
|
chart: [
|
|
{
|
|
id: 2,
|
|
type: 'chart',
|
|
name: 'Monthly Revenue',
|
|
url: '/chart/2',
|
|
changed_on: '2023-11-19T12:00:00Z',
|
|
created_by: 2,
|
|
creator: 'Jane Smith',
|
|
owners: [{ id: 2, first_name: 'Jane', last_name: 'Smith' }],
|
|
tags: [
|
|
{ id: 102, name: 'Revenue', type: 'TagType.custom' },
|
|
{ id: 42, name: 'Current Tag', type: 'TagType.custom' },
|
|
],
|
|
},
|
|
],
|
|
query: [
|
|
{
|
|
id: 3,
|
|
type: 'query',
|
|
name: 'User Engagement',
|
|
url: '/query/3',
|
|
changed_on: '2023-11-18T09:30:00Z',
|
|
created_by: 3,
|
|
creator: 'Alice Brown',
|
|
owners: [{ id: 3, first_name: 'Alice', last_name: 'Brown' }],
|
|
tags: [
|
|
{ id: 103, name: 'Engagement', type: 'TagType.custom' },
|
|
{ id: 42, name: 'Current Tag', type: 'TagType.custom' },
|
|
],
|
|
},
|
|
],
|
|
};
|
|
|
|
afterEach(() => {
|
|
jest.restoreAllMocks();
|
|
});
|
|
|
|
test('renders when empty with button to tag if user has perm', () => {
|
|
render(
|
|
<AllEntitiesTable
|
|
search=""
|
|
setShowTagModal={mockSetShowTagModal}
|
|
objects={mockObjects}
|
|
canEditTag
|
|
/>,
|
|
{ useRouter: true },
|
|
);
|
|
|
|
expect(
|
|
screen.getByText('No entities have this tag currently assigned'),
|
|
).toBeInTheDocument();
|
|
|
|
expect(screen.getByText('Add tag to entities')).toBeInTheDocument();
|
|
});
|
|
|
|
test('renders when empty without button to tag if user does not have perm', () => {
|
|
render(
|
|
<AllEntitiesTable
|
|
search=""
|
|
setShowTagModal={mockSetShowTagModal}
|
|
objects={mockObjects}
|
|
canEditTag={false}
|
|
/>,
|
|
{ useRouter: true },
|
|
);
|
|
|
|
expect(
|
|
screen.getByText('No entities have this tag currently assigned'),
|
|
).toBeInTheDocument();
|
|
|
|
expect(screen.queryByText('Add tag to entities')).not.toBeInTheDocument();
|
|
});
|
|
|
|
test('renders the correct tags for each object type', () => {
|
|
render(
|
|
<AllEntitiesTable
|
|
search=""
|
|
setShowTagModal={mockSetShowTagModal}
|
|
objects={mockObjectsWithTags}
|
|
canEditTag
|
|
/>,
|
|
{ useRouter: true },
|
|
);
|
|
|
|
expect(screen.getByText('Dashboards')).toBeInTheDocument();
|
|
expect(screen.getByText('Sales Dashboard')).toBeInTheDocument();
|
|
expect(screen.getByText('Sales')).toBeInTheDocument();
|
|
|
|
expect(screen.getByText('Charts')).toBeInTheDocument();
|
|
expect(screen.getByText('Monthly Revenue')).toBeInTheDocument();
|
|
expect(screen.getByText('Revenue')).toBeInTheDocument();
|
|
|
|
expect(screen.getByText('Queries')).toBeInTheDocument();
|
|
expect(screen.getByText('User Engagement')).toBeInTheDocument();
|
|
expect(screen.getByText('Engagement')).toBeInTheDocument();
|
|
});
|
|
|
|
test('Only list asset types that have entities', () => {
|
|
const mockObjects = {
|
|
dashboard: [],
|
|
chart: [mockObjectsWithTags.chart[0]],
|
|
query: [],
|
|
};
|
|
|
|
render(
|
|
<AllEntitiesTable
|
|
search=""
|
|
setShowTagModal={mockSetShowTagModal}
|
|
objects={mockObjects}
|
|
canEditTag
|
|
/>,
|
|
{ useRouter: true },
|
|
);
|
|
|
|
expect(screen.queryByText('Dashboards')).not.toBeInTheDocument();
|
|
expect(screen.getByText('Charts')).toBeInTheDocument();
|
|
expect(screen.getByText('Monthly Revenue')).toBeInTheDocument();
|
|
expect(screen.queryByText('Queries')).not.toBeInTheDocument();
|
|
});
|
|
});
|