Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: saved query list view + sort/filters #11005

Merged
merged 13 commits into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('Dashboard edit mode', () => {
cy.get('.dashboard-header [data-test=edit-alt]').click();
});

it('remove, and add chart flow', () => {
xit('remove, and add chart flow', () => {
// wait for box plot to appear
cy.get('.grid-container .box_plot');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,68 @@
import React from 'react';
import thunk from 'redux-thunk';
import configureStore from 'redux-mock-store';
import fetchMock from 'fetch-mock';
import { styledMount as mount } from 'spec/helpers/theming';
import SavedQueryList from 'src/views/CRUD/data/savedquery/SavedQueryList';
import SubMenu from 'src/components/Menu/SubMenu';
import ListView from 'src/components/ListView';
import Filters from 'src/components/ListView/Filters';
import waitForComponentToPaint from 'spec/helpers/waitForComponentToPaint';
import { act } from 'react-dom/test-utils';

// store needed for withToasts(DatabaseList)
const mockStore = configureStore([thunk]);
const store = mockStore({});

const queriesInfoEndpoint = 'glob:*/api/v1/saved_query/_info*';
const queriesEndpoint = 'glob:*/api/v1/saved_query/?*';
const queriesRelatedEndpoint = 'glob:*/api/v1/saved_query/related/database?*';
const queriesDistinctEndpoint = 'glob:*/api/v1/saved_query/distinct/schema?*';

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}`,
label: `query ${i}`,
schema: 'public',
sql: `SELECT ${i} FROM table`,
sql_tables: [
{
catalog: null,
schema: null,
table: `${i}`,
},
],
}));

fetchMock.get(queriesInfoEndpoint, {
permissions: ['can_delete'],
});
fetchMock.get(queriesEndpoint, {
result: mockqueries,
count: 3,
});

fetchMock.get(queriesRelatedEndpoint, {
count: 0,
result: [],
});

fetchMock.get(queriesDistinctEndpoint, {
count: 0,
result: [],
});

describe('SavedQueryList', () => {
const wrapper = mount(<SavedQueryList />, { context: { store } });

Expand All @@ -42,4 +95,28 @@ describe('SavedQueryList', () => {
it('renders a SubMenu', () => {
expect(wrapper.find(SubMenu)).toExist();
});

it('renders a ListView', () => {
expect(wrapper.find(ListView)).toExist();
});

it('fetches saved queries', () => {
const callsQ = fetchMock.calls(/saved_query\/\?q/);
expect(callsQ).toHaveLength(1);
expect(callsQ[0][0]).toMatchInlineSnapshot(
`"http://localhost/api/v1/saved_query/?q=(order_column:changed_on_delta_humanized,order_direction:desc,page:0,page_size:25)"`,
);
});

it('searches', async () => {
const filtersWrapper = wrapper.find(Filters);
act(() => {
filtersWrapper.find('[name="label"]').first().props().onSubmit('fooo');
});
await waitForComponentToPaint(wrapper);

expect(fetchMock.lastCall()[0]).toMatchInlineSnapshot(
`"http://localhost/api/v1/saved_query/?q=(filters:!((col:label,opr:all_text,value:fooo)),order_column:changed_on_delta_humanized,order_direction:desc,page:0,page_size:25)"`,
);
});
});
Loading