>,
+ ) => {
const { operatorValue, value, rows, columns, field = 'brand', ...other } = props;
return (
@@ -86,6 +90,12 @@ describe(' - Filter', () => {
],
}}
disableColumnFilter={false}
+ initialState={{
+ preferencePanel: {
+ open: true,
+ openedPanelValue: GridPreferencePanelsValue.filters,
+ },
+ }}
{...other}
/>
@@ -303,6 +313,42 @@ describe(' - Filter', () => {
});
});
+ ['contains', 'startsWith', 'equals', 'endsWith'].forEach((operatorValue) => {
+ it(`should show all rows when the value is '' and operator='${operatorValue}'`, () => {
+ render(
+ ,
+ );
+ expect(getColumnValues()).to.deep.equal(['Asics', 'RedBull', 'Hugo']);
+ fireEvent.change(screen.getByRole('combobox', { name: 'Operators' }), {
+ target: { value: operatorValue },
+ });
+ const input = screen.getByRole('textbox', { name: 'Value' });
+ fireEvent.change(input, { target: { value: 'abc' } });
+ clock.tick(500);
+ expect(getColumnValues()).to.deep.equal([]);
+ fireEvent.change(input, { target: { value: '' } });
+ clock.tick(500);
+ expect(getColumnValues()).to.deep.equal(['Asics', 'RedBull', 'Hugo']);
+ });
+ });
+
describe('RegExp', () => {
['contains', 'startsWith', 'endsWith'].forEach((operatorValue) => {
it('should escape RegExp characters if applied as filter values', () => {
@@ -441,6 +487,31 @@ describe(' - Filter', () => {
);
expect(getColumnValues(0)).to.deep.equal(['0', '2']);
});
+
+ it('should show all rows when the value is empty', () => {
+ render(
+ String(value) },
+ ]}
+ rows={[
+ { id: 2, brand: 0 },
+ { id: 3, brand: 1984 },
+ { id: 4, brand: 1954 },
+ { id: 5, brand: 1974 },
+ ]}
+ />,
+ );
+ expect(getColumnValues()).to.deep.equal(['0', '1984', '1954', '1974']);
+ const input = screen.getByRole('spinbutton', { name: 'Value' });
+ fireEvent.change(input, { target: { value: 999999 } });
+ clock.tick(500);
+ expect(getColumnValues()).to.deep.equal([]);
+ fireEvent.change(input, { target: { value: '' } });
+ clock.tick(500);
+ expect(getColumnValues()).to.deep.equal(['0', '1984', '1954', '1974']);
+ });
});
describe('date operators', () => {
@@ -851,12 +922,6 @@ describe(' - Filter', () => {
]}
field="voltage"
operatorValue="is"
- initialState={{
- preferencePanel: {
- open: true,
- openedPanelValue: GridPreferencePanelsValue.filters,
- },
- }}
/>,
);
expect(getColumnValues()).to.deep.equal(['Hair Dryer', 'Dishwasher', 'Microwave']);
@@ -882,12 +947,6 @@ describe(' - Filter', () => {
]}
field="voltage"
operatorValue="is"
- initialState={{
- preferencePanel: {
- open: true,
- openedPanelValue: GridPreferencePanelsValue.filters,
- },
- }}
/>,
);
expect(getColumnValues()).to.deep.equal(['Hair Dryer', 'Dishwasher', 'Microwave']);
@@ -906,12 +965,6 @@ describe(' - Filter', () => {
columns={[{ field: 'name' }, { field: 'voltage', type: 'singleSelect' }]}
field="voltage"
operatorValue="is"
- initialState={{
- preferencePanel: {
- open: true,
- openedPanelValue: GridPreferencePanelsValue.filters,
- },
- }}
/>,
);
expect(getColumnValues()).to.deep.equal(['Hair Dryer', 'Dishwasher', 'Microwave']);
@@ -966,18 +1019,7 @@ describe(' - Filter', () => {
});
it('should work with numeric values', () => {
- const { setProps } = render(
- ,
- );
+ const { setProps } = render();
expect(getColumnValues()).to.deep.equal(['Nike', 'Adidas', 'Puma']);
setProps({ value: 2 });
expect(getColumnValues()).to.deep.equal(['Puma']);
@@ -1100,18 +1142,7 @@ describe(' - Filter', () => {
describe('Filter preference panel', () => {
it('should show an empty string as the default filter input value', () => {
- render(
- ,
- );
+ render();
expect(screen.getByRole('textbox', { name: 'Value' }).value).to.equal('');
});
});