Skip to content

Commit

Permalink
chore: add tests and stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
timogasda committed Sep 27, 2023
1 parent d47e9fa commit 94c4d24
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
15 changes: 15 additions & 0 deletions pages/property-filter/permutations.page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import React from 'react';
import { ButtonDropdown } from '~components';
import PropertyFilter, { PropertyFilterProps } from '~components/property-filter';
import Select from '~components/select';
import FormField from '~components/form-field';
Expand Down Expand Up @@ -93,6 +94,20 @@ const permutations = createPermutations<Partial<PropertyFilterProps>>([
</FormField>,
],
},
{
query: [
{ tokens: [], operation: 'and' },
{
tokens: [
{ value: '123', operator: ':' },
{ value: '234', operator: '!:' },
{ propertyKey: 'instanceid', value: '345', operator: '=' },
],
operation: 'and',
},
],
customFilterActions: [<ButtonDropdown key={0} mainAction={{ text: 'Clear filters' }} items={[]} />],
},
]);

export default function () {
Expand Down
16 changes: 16 additions & 0 deletions src/property-filter/__tests__/property-filter.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,22 @@ describe('property filter parts', () => {
});
});

describe('custom element slots', () => {
test('can define a customControl element', () => {
const { propertyFilterWrapper } = renderComponent({ customControl: <div>Custom</div> });
expect(propertyFilterWrapper.findCustomControl()?.getElement()).toHaveTextContent('Custom');
});

test('can define a customFilterAction that replaces the clear filters button', () => {
const { propertyFilterWrapper } = renderComponent({
customFilterActions: <div>Custom actions</div>,
query: { tokens: [{ value: 'free text', operator: '=' }], operation: 'and' },
});
expect(propertyFilterWrapper.findRemoveAllButton()).toBeNull();
expect(propertyFilterWrapper.findCustomFilterActions()?.getElement()).toHaveTextContent('Custom actions');
});
});

test('property filter input can be found with autosuggest selector', () => {
const { container } = renderComponent();
expect(createWrapper(container).findAutosuggest()!.getElement()).not.toBe(null);
Expand Down
3 changes: 2 additions & 1 deletion src/property-filter/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@

.remove-all,
.token-label,
.join-operation {
.join-operation,
.custom-filter-actions {
/* used in test-utils */
}
14 changes: 14 additions & 0 deletions src/test-utils/dom/property-filter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,18 @@ export default class PropertyFilterWrapper extends AutosuggestWrapper {
findRemoveAllButton(): ElementWrapper | null {
return this.findByClassName(styles['remove-all']);
}

/**
* Returns the element containing the `customControl` slot.
*/
findCustomControl(): ElementWrapper | null {
return this.findByClassName(styles['custom-control']);
}

/**
* Returns the element containing the `customFilterActions` slot.
*/
findCustomFilterActions(): ElementWrapper | null {
return this.findByClassName(styles['custom-filter-actions']);
}
}

0 comments on commit 94c4d24

Please sign in to comment.