feat: annotation layers modal + filters (#11494)

This commit is contained in:
Moriah Kreeger
2020-10-30 15:51:46 -07:00
committed by GitHub
parent 5d9560c408
commit 01ddbd0697
8 changed files with 457 additions and 34 deletions

View File

@@ -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();
});
});

View File

@@ -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]);
@@ -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`,
@@ -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 } });
@@ -91,6 +92,10 @@ 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);
@@ -98,4 +103,20 @@ describe('AnnotationLayersList', () => {
`"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)"`,
);
});
});