-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Variable Editor: Fix filters not working (#865)
- Loading branch information
1 parent
84d6655
commit 6a6fa3a
Showing
2 changed files
with
52 additions
and
7 deletions.
There are no files selected for viewing
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,45 @@ | ||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { TableFilter } from './query.filters'; | ||
|
||
// We need to freeze the object to test for mutations | ||
describe('TableFilter', () => { | ||
it('should render correct number of filters', () => { | ||
const query: any = Object.freeze({ columns: [{ text: 'name' }], filters: [{ field: 'name', operator: '', value: [''] }], type: 'csv' }); | ||
const onChange = jest.fn(); | ||
const onRunQuery = jest.fn(); | ||
render(<TableFilter query={query} onChange={onChange} onRunQuery={onRunQuery} />); | ||
fireEvent.click(screen.getByTestId('infinity-query-row-collapse-show-results-filter')); | ||
expect(screen.getByText(/Filter 1/)).toBeInTheDocument(); | ||
}); | ||
|
||
it('should add filter correctly', () => { | ||
const query: any = Object.freeze({ columns: [], filters: [], type: 'csv' }); | ||
const onChange = jest.fn(); | ||
const onRunQuery = jest.fn(); | ||
render(<TableFilter query={query} onChange={onChange} onRunQuery={onRunQuery} />); | ||
fireEvent.click(screen.getByTestId('infinity-query-row-collapse-show-results-filter')); | ||
fireEvent.click(screen.getByText(/Add filter/)); | ||
expect(onChange).toHaveBeenCalledWith({ ...query, filters: [{ field: '', operator: 'equals', value: [''] }] }); | ||
}); | ||
|
||
it('should remove filter correctly', () => { | ||
const query: any = Object.freeze({ columns: [], filters: [{ field: '', operator: '', value: [''] }], type: 'csv' }); | ||
const onChange = jest.fn(); | ||
const onRunQuery = jest.fn(); | ||
render(<TableFilter query={query} onChange={onChange} onRunQuery={onRunQuery} />); | ||
fireEvent.click(screen.getByTestId('infinity-query-row-collapse-show-results-filter')); | ||
fireEvent.click(screen.getByTestId(/trash-alt/)); | ||
expect(onChange).toHaveBeenCalledWith({ ...query, filters: [] }); | ||
}); | ||
|
||
it('should handle value change', () => { | ||
const query: any = Object.freeze({ columns: [], filters: [{ field: '', operator: '', value: [''] }], type: 'csv' }); | ||
const onChange = jest.fn(); | ||
const onRunQuery = jest.fn(); | ||
render(<TableFilter query={query} onChange={onChange} onRunQuery={onRunQuery} />); | ||
fireEvent.click(screen.getByTestId('infinity-query-row-collapse-show-results-filter')); | ||
fireEvent.change(screen.getByPlaceholderText(/Value/), { target: { value: 'test' } }); | ||
expect(onChange).toHaveBeenCalledWith({ ...query, filters: [{ field: '', operator: '', value: ['test'] }] }); | ||
}); | ||
}); |
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