superset/superset-frontend/spec/javascripts/views/CRUD/welcome/SavedQueries_spec.tsx
Phillip Kelley-Dotson f7051eaade
feat: home screen mvp (#11206)
* step 1: broken stuff!

* first steps

* more adding and slicing

* step 1: broken stuff!

* can now filter dashboards/charts for "Edited" tabs (filter by changed_by o_m)

* more updates

* update recent card

* add icon

* Adding Expand Icon to Collapse component

* more updates

* clean up code

* remove lock file

* remove consoles

* fixing subnav button height shift

* lil' ascii arrows

* update branch

* update test part 1

* remove consoles

* fix typescript

* add images and update emptystate

* add changes

* update chart card

* fix css issues from rebase

* add suggestions

* more changes

* update tests and clear typescript errors

* Update superset-frontend/src/views/CRUD/welcome/ActivityTable.tsx

Co-authored-by: Evan Rusackas <evan@preset.io>

* update from comments

* more updates..

* fix rebase

* fix pesky type errors

* test fixes

* lint fix

* Update superset-frontend/spec/javascripts/views/CRUD/welcome/Welcome_spec.tsx

Co-authored-by: Evan Rusackas <evan@preset.io>

* Update superset-frontend/src/views/CRUD/welcome/EmptyState.tsx

Co-authored-by: Evan Rusackas <evan@preset.io>

* Update superset-frontend/src/components/Menu/SubMenu.tsx

Co-authored-by: Evan Rusackas <evan@preset.io>

* Update superset-frontend/src/components/ListViewCard/index.tsx

Co-authored-by: ʈᵃᵢ <tdupreetan@gmail.com>

* Update superset-frontend/src/components/ListViewCard/index.tsx

Co-authored-by: ʈᵃᵢ <tdupreetan@gmail.com>

* add suggestions

* fix lint

* remove unused code

* toast getrecentActivityobjs

* add some suggestions

* remove types for now

* cypress fix

* remove unused type

Co-authored-by: Evan Rusackas <evan@preset.io>
Co-authored-by: ʈᵃᵢ <tdupreetan@gmail.com>
2020-10-29 21:59:31 -07:00

107 lines
3.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 React from 'react';
import thunk from 'redux-thunk';
import { styledMount as mount } from 'spec/helpers/theming';
import fetchMock from 'fetch-mock';
import configureStore from 'redux-mock-store';
import { act } from 'react-dom/test-utils';
import waitForComponentToPaint from 'spec/helpers/waitForComponentToPaint';
import SubMenu from 'src/components/Menu/SubMenu';
import SavedQueries from 'src/views/CRUD/welcome/SavedQueries';
// store needed for withToasts(DashboardTable)
const mockStore = configureStore([thunk]);
const store = mockStore({});
const queriesEndpoint = 'glob:*/api/v1/saved_query/?*';
const savedQueriesInfo = 'glob:*/api/v1/saved_query/_info';
const mockqueries = [...new Array(3)].map((_, i) => ({
created_by: {
id: i,
first_name: `user`,
last_name: `${i}`,
},
created_on: `${i}-2020`,
database: {
database_name: `db ${i}`,
id: i,
},
changed_on_delta_humanized: '1 day ago',
db_id: i,
description: `SQL for ${i}`,
id: i,
label: `query ${i}`,
schema: 'public',
sql: `SELECT ${i} FROM table`,
sql_tables: [
{
catalog: null,
schema: null,
table: `${i}`,
},
],
}));
fetchMock.get(queriesEndpoint, {
result: mockqueries,
});
fetchMock.get(savedQueriesInfo, {
permissions: ['can_list', 'can_edit', 'can_delete'],
});
describe('SavedQueries', () => {
const savedQueryProps = {
user: {
userId: '1',
},
};
const wrapper = mount(<SavedQueries {...savedQueryProps} />, {
context: { store },
});
beforeAll(async () => {
await waitForComponentToPaint(wrapper);
});
it('is valid', () => {
expect(wrapper.find(SavedQueries)).toExist();
});
it('it renders a submenu with clickable tables and buttons', async () => {
expect(wrapper.find(SubMenu)).toExist();
expect(wrapper.find('MenuItem')).toHaveLength(2);
expect(wrapper.find('button')).toHaveLength(2);
act(() => {
wrapper.find('MenuItem').at(1).simulate('click');
});
await waitForComponentToPaint(wrapper);
expect(fetchMock.calls(/saved_query\/\?q/)).toHaveLength(1);
});
it('fetches queries favorites and renders listviewcard cards', () => {
expect(fetchMock.calls(/saved_query\/\?q/)).toHaveLength(1);
expect(wrapper.find('ListViewCard')).toExist();
});
});