forked from Powerarena-Limited/superset
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Tests audit for the Dashboard FilterBar (apache#13916)
* Add FilterBar tests * Finalize FilterBar tests * Add tests for FilterBar Header * Add tests for FilterBar FilterConfigurationLink * Add tests for FilterBar FilterSets EditSection * Add tests for FilterBar FilterSets * Clean up * Add tests for FilterBar FilterSetUnit * Add tests for FilterBar FilterSets FiltersHeader * Add tests for FilterBar FilterSets Footer * Fix linting * Fix import * Fix minor changes * Fix import * Add factory and clean up
- Loading branch information
Showing
19 changed files
with
692 additions
and
102 deletions.
There are no files selected for viewing
50 changes: 0 additions & 50 deletions
50
superset-frontend/spec/javascripts/dashboard/components/nativeFilters/FilterBar_spec.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterBar.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/** | ||
* 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 { mockStore } from 'spec/fixtures/mockStore'; | ||
import { Provider } from 'react-redux'; | ||
import FilterBar, { FiltersBarProps } from '.'; | ||
|
||
const createProps = () => ({ | ||
filtersOpen: false, | ||
toggleFiltersBar: jest.fn(), | ||
}); | ||
|
||
const setup = (props: FiltersBarProps) => ( | ||
<Provider store={mockStore}> | ||
<FilterBar {...props} /> | ||
</Provider> | ||
); | ||
|
||
test('should render', () => { | ||
const mockedProps = createProps(); | ||
const { container } = render(setup(mockedProps)); | ||
expect(container).toBeInTheDocument(); | ||
}); | ||
|
||
test('should render the "Filters" heading', () => { | ||
const mockedProps = createProps(); | ||
render(setup(mockedProps)); | ||
expect(screen.getByText('Filters')).toBeInTheDocument(); | ||
}); | ||
|
||
test('should render the "Clear all" option', () => { | ||
const mockedProps = createProps(); | ||
render(setup(mockedProps)); | ||
expect(screen.getByText('Clear all')).toBeInTheDocument(); | ||
}); | ||
|
||
test('should render the "Apply" option', () => { | ||
const mockedProps = createProps(); | ||
render(setup(mockedProps)); | ||
expect(screen.getByText('Apply')).toBeInTheDocument(); | ||
}); | ||
|
||
test('should render the collapse icon', () => { | ||
const mockedProps = createProps(); | ||
render(setup(mockedProps)); | ||
expect(screen.getByRole('img', { name: 'collapse' })).toBeInTheDocument(); | ||
}); | ||
|
||
test('should render the filter icon', () => { | ||
const mockedProps = createProps(); | ||
render(setup(mockedProps)); | ||
expect(screen.getByRole('img', { name: 'filter' })).toBeInTheDocument(); | ||
}); | ||
|
||
test('should render the filter control name', () => { | ||
const mockedProps = createProps(); | ||
render(setup(mockedProps)); | ||
expect(screen.getByText('test')).toBeInTheDocument(); | ||
}); | ||
|
||
test('should toggle', () => { | ||
const mockedProps = createProps(); | ||
render(setup(mockedProps)); | ||
const collapse = screen.getByRole('img', { name: 'collapse' }); | ||
expect(mockedProps.toggleFiltersBar).not.toHaveBeenCalled(); | ||
userEvent.click(collapse); | ||
expect(mockedProps.toggleFiltersBar).toHaveBeenCalled(); | ||
}); |
49 changes: 49 additions & 0 deletions
49
...mponents/nativeFilters/FilterBar/FilterConfigurationLink/FilterConfigurationLink.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* 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 FilterConfigurationLink from '.'; | ||
|
||
test('should render', () => { | ||
const { container } = render( | ||
<FilterConfigurationLink>Config link</FilterConfigurationLink>, | ||
{ | ||
useRedux: true, | ||
}, | ||
); | ||
expect(container).toBeInTheDocument(); | ||
}); | ||
|
||
test('should render the config link text', () => { | ||
render(<FilterConfigurationLink>Config link</FilterConfigurationLink>, { | ||
useRedux: true, | ||
}); | ||
expect(screen.getByText('Config link')).toBeInTheDocument(); | ||
}); | ||
|
||
test('should render the modal on click', () => { | ||
render(<FilterConfigurationLink>Config link</FilterConfigurationLink>, { | ||
useRedux: true, | ||
}); | ||
const configLink = screen.getByText('Config link'); | ||
expect(screen.queryByRole('dialog')).not.toBeInTheDocument(); | ||
userEvent.click(configLink); | ||
expect(screen.getByRole('dialog')).toBeInTheDocument(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
...frontend/src/dashboard/components/nativeFilters/FilterBar/FilterSets/EditSection.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/** | ||
* 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 { mockStore } from 'spec/fixtures/mockStore'; | ||
import { Provider } from 'react-redux'; | ||
import EditSection, { EditSectionProps } from './EditSection'; | ||
|
||
const createProps = () => ({ | ||
filterSetId: 'set-id', | ||
dataMaskSelected: { | ||
DefaultsID: { | ||
currentState: { | ||
value: 'value', | ||
}, | ||
}, | ||
}, | ||
onCancel: jest.fn(), | ||
disabled: false, | ||
}); | ||
|
||
const setup = (props: EditSectionProps) => ( | ||
<Provider store={mockStore}> | ||
<EditSection {...props} /> | ||
</Provider> | ||
); | ||
|
||
test('should render', () => { | ||
const mockedProps = createProps(); | ||
const { container } = render(setup(mockedProps)); | ||
expect(container).toBeInTheDocument(); | ||
}); | ||
|
||
test('should render the title', () => { | ||
const mockedProps = createProps(); | ||
render(setup(mockedProps)); | ||
expect(screen.getByText('Editing filter set:')).toBeInTheDocument(); | ||
}); | ||
|
||
test('should render the set name', () => { | ||
const mockedProps = createProps(); | ||
render(setup(mockedProps)); | ||
expect(screen.getByText('Set name')).toBeInTheDocument(); | ||
}); | ||
|
||
test('should render a textbox', () => { | ||
const mockedProps = createProps(); | ||
render(setup(mockedProps)); | ||
expect(screen.getByRole('textbox')).toBeInTheDocument(); | ||
}); | ||
|
||
test('should change the set name', () => { | ||
const mockedProps = createProps(); | ||
render(setup(mockedProps)); | ||
const textbox = screen.getByRole('textbox'); | ||
userEvent.clear(textbox); | ||
userEvent.type(textbox, 'New name'); | ||
expect(textbox).toHaveValue('New name'); | ||
}); | ||
|
||
test('should render the enter icon', () => { | ||
const mockedProps = createProps(); | ||
render(setup(mockedProps)); | ||
expect(screen.getByRole('img', { name: 'enter' })).toBeInTheDocument(); | ||
}); | ||
|
||
test('should render the Cancel button', () => { | ||
const mockedProps = createProps(); | ||
render(setup(mockedProps)); | ||
expect(screen.getByText('Cancel')).toBeInTheDocument(); | ||
}); | ||
|
||
test('should cancel', () => { | ||
const mockedProps = createProps(); | ||
render(setup(mockedProps)); | ||
const cancelBtn = screen.getByText('Cancel'); | ||
expect(mockedProps.onCancel).not.toHaveBeenCalled(); | ||
userEvent.click(cancelBtn); | ||
expect(mockedProps.onCancel).toHaveBeenCalled(); | ||
}); | ||
|
||
test('should render the Save button', () => { | ||
const mockedProps = createProps(); | ||
render(setup(mockedProps)); | ||
expect(screen.getByText('Save')).toBeInTheDocument(); | ||
}); | ||
|
||
test('should render the Save button as disabled', () => { | ||
const mockedProps = createProps(); | ||
const saveDisabledProps = { | ||
...mockedProps, | ||
disabled: true, | ||
}; | ||
render(setup(saveDisabledProps)); | ||
expect(screen.getByText('Save').parentElement).toBeDisabled(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.