From df5fb5a97c46201978d9dc4ef24b08681e1aed4d Mon Sep 17 00:00:00 2001 From: Geido <60598000+geido@users.noreply.github.com> Date: Tue, 16 Mar 2021 01:09:02 +0200 Subject: [PATCH] test: Tests and dedicated directory for the SupersetResourceSelect Component (#13508) * Refactor * Clean up * Add license * Use findBy --- .../SupersetResourceSelect_spec.tsx | 59 ----------------- .../SupersetResourceSelect.test.tsx | 64 +++++++++++++++++++ .../index.tsx} | 0 3 files changed, 64 insertions(+), 59 deletions(-) delete mode 100644 superset-frontend/spec/javascripts/components/SupersetResourceSelect_spec.tsx create mode 100644 superset-frontend/src/components/SupersetResourceSelect/SupersetResourceSelect.test.tsx rename superset-frontend/src/components/{SupersetResourceSelect.tsx => SupersetResourceSelect/index.tsx} (100%) diff --git a/superset-frontend/spec/javascripts/components/SupersetResourceSelect_spec.tsx b/superset-frontend/spec/javascripts/components/SupersetResourceSelect_spec.tsx deleted file mode 100644 index 60cd4a3dd..000000000 --- a/superset-frontend/spec/javascripts/components/SupersetResourceSelect_spec.tsx +++ /dev/null @@ -1,59 +0,0 @@ -/** - * 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 { mount } from 'enzyme'; -import thunk from 'redux-thunk'; -import { Provider } from 'react-redux'; -import configureStore from 'redux-mock-store'; -import SupersetResourceSelect from 'src/components/SupersetResourceSelect'; -import { supersetTheme, ThemeProvider } from '@superset-ui/core'; -import fetchMock from 'fetch-mock'; - -describe('SupersetResourceSelect', () => { - const NOOP = () => {}; - - fetchMock.get('glob:*/api/v1/dataset/?q=*', {}); - - it('is a valid element', () => { - // @ts-ignore - expect( - React.isValidElement(), - ).toBe(true); - }); - - it('take in props', () => { - const mockStore = configureStore([thunk]); - const store = mockStore({}); - const selectProps = { - resource: 'dataset', - searchColumn: 'table_name', - transformItem: jest.fn(), - isMulti: false, - onError: NOOP, - }; - const wrapper = mount(, { - wrappingComponent: ({ children }) => ( - - {children} - - ), - }); - expect(wrapper.props().resource).toEqual('dataset'); - }); -}); diff --git a/superset-frontend/src/components/SupersetResourceSelect/SupersetResourceSelect.test.tsx b/superset-frontend/src/components/SupersetResourceSelect/SupersetResourceSelect.test.tsx new file mode 100644 index 000000000..ad5d68803 --- /dev/null +++ b/superset-frontend/src/components/SupersetResourceSelect/SupersetResourceSelect.test.tsx @@ -0,0 +1,64 @@ +/** + * 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 { render, screen } from 'spec/helpers/testing-library'; +import userEvent from '@testing-library/user-event'; +import fetchMock from 'fetch-mock'; +import SupersetResourceSelect from '.'; + +const mockedProps = { + resource: 'dataset', + searchColumn: 'table_name', + onError: () => {}, +}; + +fetchMock.get('glob:*/api/v1/dataset/?q=*', {}); + +test('should render', () => { + const { container } = render(); + expect(container).toBeInTheDocument(); +}); + +test('should render the Select... placeholder', () => { + render(); + expect(screen.getByText('Select...')).toBeInTheDocument(); +}); + +test('should render the Loading... message', () => { + render(); + const select = screen.getByText('Select...'); + userEvent.click(select); + expect(screen.getByText('Loading...')).toBeInTheDocument(); +}); + +test('should render the No options message', async () => { + render(); + const select = screen.getByText('Select...'); + userEvent.click(select); + expect(await screen.findByText('No options')).toBeInTheDocument(); +}); + +test('should render the typed text', async () => { + render(); + const select = screen.getByText('Select...'); + userEvent.click(select); + userEvent.type(select, 'typed text'); + expect(await screen.findByText('typed text')).toBeInTheDocument(); +}); diff --git a/superset-frontend/src/components/SupersetResourceSelect.tsx b/superset-frontend/src/components/SupersetResourceSelect/index.tsx similarity index 100% rename from superset-frontend/src/components/SupersetResourceSelect.tsx rename to superset-frontend/src/components/SupersetResourceSelect/index.tsx