Skip to content

Commit

Permalink
chore: Adds the tests that need to be coded for the Select component (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-s-molina committed Jul 25, 2021
1 parent 7330aef commit 9c81599
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 1 deletion.
82 changes: 82 additions & 0 deletions superset-frontend/src/components/Select/Select.test.tsx
@@ -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
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

0 comments on commit 9c81599

Please sign in to comment.