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

chore: Adds the tests that need to be coded for the Select component #15885

Merged
merged 1 commit into from
Jul 25, 2021
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
82 changes: 82 additions & 0 deletions superset-frontend/src/components/Select/Select.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* 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 { Select } from 'src/components';

test('renders with default props', () => {
const ariaLabel = 'test';
render(
<Select
ariaLabel={ariaLabel}
options={[
{ label: 'A', value: 0 },
{ label: 'B', value: 1 },
]}
/>,
);

expect(screen.getByRole('combobox', { name: ariaLabel })).toBeInTheDocument();
});

/*
Tests for the sync version of the select:
- Opens the select without any data
- Makes a selection in single mode
- Makes multiple selections in multiple mode
- Changes the selected item in single mode
- Deselects an item in multiple mode
- Adds a header to the select
- Adds a new option if none is available and allowNewValue is true
- Does not add a new option if the option already exists
- Does not add a new option if allowNewValue is false
- Inverts the selection
- Sets a initial value in single mode
- Sets a initial value in multiple mode
- Searches for an item
- Displays the selected items first
- Searches for label or value
- Clear all the values

Tests for the async version of the select:
- Opens the select without any data
- Makes a selection in single mode
- Makes multiple selections in multiple mode
- Changes the selected item in single mode
- Deselects an item in multiple mode
- Adds a new option if none is available and allowNewValue is true
- Does not add a new option if the option already exists
- Does not add a new option if allowNewValue is false
- Sets a initial value in single mode
- Sets a initial value in multiple mode
- Searches for an item already loaded
- Searches for an item in a page not loaded
- Displays the loading indicator
- Fetches more data when scrolling and more data is available
- Doesn't fetch more data when no more data is available
- Requests the correct page and page size
- Fetches only after a search input is entered if fetchOnlyOnSearch is true
- Does not fetch data when rendering
- Fetches data when opening the select
- Displays an error message when an exception is thrown while fetching
- Does not fire a new request for the same search input
- Displays the selected items first
- Sets the page to zero when a new search is made
- Clear all the values
*/
2 changes: 1 addition & 1 deletion superset-frontend/src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ const Select = ({
onDeselect={handleOnDeselect}
onDropdownVisibleChange={handleOnDropdownVisibleChange}
onPopupScroll={isAsync ? handlePagination : undefined}
onSearch={handleOnSearch}
onSearch={shouldShowSearch ? handleOnSearch : undefined}
onSelect={handleOnSelect}
onClear={() => setSelectValue(undefined)}
options={selectOptions}
Expand Down