Skip to content

Commit

Permalink
feat: annotation layers modal + filters (apache#11494)
Browse files Browse the repository at this point in the history
  • Loading branch information
riahk authored and auxten committed Nov 20, 2020
1 parent 93bceb8 commit efb97f5
Show file tree
Hide file tree
Showing 8 changed files with 457 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/**
* 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 configureStore from 'redux-mock-store';
import fetchMock from 'fetch-mock';
import AnnotationLayerModal from 'src/views/CRUD/annotationlayers/AnnotationLayerModal';
import Modal from 'src/common/components/Modal';
import waitForComponentToPaint from 'spec/helpers/waitForComponentToPaint';
import { styledMount as mount } from 'spec/helpers/theming';

const mockData = { id: 1, name: 'test', descr: 'test description' };
const FETCH_ANNOTATION_LAYER_ENDPOINT = 'glob:*/api/v1/annotation_layer/*';
const ANNOTATION_LAYER_PAYLOAD = { result: mockData };

fetchMock.get(FETCH_ANNOTATION_LAYER_ENDPOINT, ANNOTATION_LAYER_PAYLOAD);

const mockStore = configureStore([thunk]);
const store = mockStore({});

const mockedProps = {
addDangerToast: () => {},
onLayerAdd: jest.fn(() => []),
onHide: () => {},
show: true,
layer: mockData,
};

async function mountAndWait(props = mockedProps) {
const mounted = mount(<AnnotationLayerModal show {...props} />, {
context: { store },
});
await waitForComponentToPaint(mounted);

return mounted;
}

describe('AnnotationLayerModal', () => {
let wrapper;

beforeAll(async () => {
wrapper = await mountAndWait();
});

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

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

it('renders add header when no layer is included', async () => {
const addWrapper = await mountAndWait({});
expect(
addWrapper.find('[data-test="annotation-layer-modal-title"]').text(),
).toEqual('Add Annotation Layer');
});

it('renders edit header when layer prop is included', () => {
expect(
wrapper.find('[data-test="annotation-layer-modal-title"]').text(),
).toEqual('Edit Annotation Layer Properties');
});

it('renders input element for name', () => {
expect(wrapper.find('input[name="name"]')).toExist();
});

it('renders textarea element for description', () => {
expect(wrapper.find('textarea[name="descr"]')).toExist();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ import fetchMock from 'fetch-mock';
import { styledMount as mount } from 'spec/helpers/theming';

import AnnotationLayersList from 'src/views/CRUD/annotationlayers/AnnotationLayersList';
import AnnotationLayerModal from 'src/views/CRUD/annotationlayers/AnnotationLayerModal';
import SubMenu from 'src/components/Menu/SubMenu';
import ListView from 'src/components/ListView';
// import Filters from 'src/components/ListView/Filters';
import Filters from 'src/components/ListView/Filters';
// import DeleteModal from 'src/components/DeleteModal';
// import Button from 'src/components/Button';
// import IndeterminateCheckbox from 'src/components/IndeterminateCheckbox';
import waitForComponentToPaint from 'spec/helpers/waitForComponentToPaint';
// import { act } from 'react-dom/test-utils';
import { act } from 'react-dom/test-utils';

// store needed for withToasts(AnnotationLayersList)
const mockStore = configureStore([thunk]);
Expand All @@ -39,7 +40,7 @@ const store = mockStore({});
const layersInfoEndpoint = 'glob:*/api/v1/annotation_layer/_info*';
const layersEndpoint = 'glob:*/api/v1/annotation_layer/?*';
// const layerEndpoint = 'glob:*/api/v1/annotation_layer/*';
// const templatesRelatedEndpoint = 'glob:*/api/v1/annotation_layer/related/*';
const layersRelatedEndpoint = 'glob:*/api/v1/annotation_layer/related/*';

const mocklayers = [...new Array(3)].map((_, i) => ({
changed_on_delta_humanized: `${i} day(s) ago`,
Expand All @@ -63,14 +64,14 @@ fetchMock.get(layersEndpoint, {
});

/* fetchMock.delete(layerEndpoint, {});
fetchMock.delete(layersEndpoint, {});
fetchMock.delete(layersEndpoint, {}); */

fetchMock.get(layersRelatedEndpoint, {
created_by: {
count: 0,
result: [],
},
}); */
});

describe('AnnotationLayersList', () => {
const wrapper = mount(<AnnotationLayersList />, { context: { store } });
Expand All @@ -91,11 +92,31 @@ describe('AnnotationLayersList', () => {
expect(wrapper.find(ListView)).toExist();
});

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

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

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

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

expect(fetchMock.lastCall()[0]).toMatchInlineSnapshot(
`"http://localhost/api/v1/annotation_layer/?q=(filters:!((col:name,opr:ct,value:foo)),order_column:name,order_direction:desc,page:0,page_size:25)"`,
);
});
});
2 changes: 1 addition & 1 deletion superset-frontend/src/components/ListView/ListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import {
import { ListViewError, useListViewState } from './utils';

const ListViewStyles = styled.div`
background: ${({ theme }) => theme.colors.grayscale.light5};
text-align: center;
.superset-list-view {
Expand All @@ -58,6 +57,7 @@ const ListViewStyles = styled.div`
}
}
.body {
background: ${({ theme }) => theme.colors.grayscale.light5};
}
.ant-empty {
Expand Down
Loading

0 comments on commit efb97f5

Please sign in to comment.