@@ -95,7 +96,7 @@ const FilterSecurityCard: React.FC<{ filter?: DeviceSecurityVariation | string }
}
};
-const getNoResultsMessage = (filter: DeviceSecurityVariation): string => {
+const getNoResultsMessage = (filter?: DeviceSecurityVariation): string => {
switch (filter) {
case DeviceSecurityVariation.Verified:
return _t('No verified sessions found.');
@@ -107,7 +108,7 @@ const getNoResultsMessage = (filter: DeviceSecurityVariation): string => {
return _t('No sessions found.');
}
};
-interface NoResultsProps { filter: DeviceSecurityVariation, clearFilter: () => void}
+interface NoResultsProps { filter?: DeviceSecurityVariation, clearFilter: () => void}
const NoResults: React.FC
= ({ filter, clearFilter }) =>
{ getNoResultsMessage(filter) }
@@ -158,7 +159,7 @@ const FilteredDeviceList: React.FC
= ({
}) => {
const sortedDevices = getFilteredSortedDevices(devices, filter);
- const options = [
+ const options: FilterDropdownOption[] = [
{ id: ALL_FILTER_ID, label: _t('All') },
{
id: DeviceSecurityVariation.Verified,
@@ -180,7 +181,7 @@ const FilteredDeviceList: React.FC = ({
},
];
- const onFilterOptionChange = (filterId: DeviceSecurityVariation | typeof ALL_FILTER_ID) => {
+ const onFilterOptionChange = (filterId: DeviceFilterKey) => {
onFilterChange(filterId === ALL_FILTER_ID ? undefined : filterId as DeviceSecurityVariation);
};
@@ -189,16 +190,14 @@ const FilteredDeviceList: React.FC = ({
{ _t('Sessions') }
-
id='device-list-filter'
label={_t('Filter devices')}
value={filter || ALL_FILTER_ID}
onOptionChange={onFilterOptionChange}
- >
- { options.map(({ id, label }) =>
- { label }
,
- ) }
-
+ options={options}
+ selectedLabel={_t('Show')}
+ />
{ !!sortedDevices.length
?
diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json
index ae602ac216..1e0450ae60 100644
--- a/src/i18n/strings/en_EN.json
+++ b/src/i18n/strings/en_EN.json
@@ -1734,6 +1734,7 @@
"Inactive": "Inactive",
"Inactive for %(inactiveAgeDays)s days or longer": "Inactive for %(inactiveAgeDays)s days or longer",
"Filter devices": "Filter devices",
+ "Show": "Show",
"Security recommendations": "Security recommendations",
"Improve your account security by following these recommendations": "Improve your account security by following these recommendations",
"View all": "View all",
diff --git a/test/components/views/elements/FilterDropdown-test.tsx b/test/components/views/elements/FilterDropdown-test.tsx
new file mode 100644
index 0000000000..3c30e70ac1
--- /dev/null
+++ b/test/components/views/elements/FilterDropdown-test.tsx
@@ -0,0 +1,68 @@
+/*
+Copyright 2022 The Matrix.org Foundation C.I.C.
+
+Licensed 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 { act, fireEvent, render } from '@testing-library/react';
+import React from 'react';
+
+import { FilterDropdown } from '../../../../src/components/views/elements/FilterDropdown';
+import { flushPromises, mockPlatformPeg } from '../../../test-utils';
+
+mockPlatformPeg();
+
+describe('', () => {
+ const options = [
+ { id: 'one', label: 'Option one' },
+ { id: 'two', label: 'Option two', description: 'with description' },
+ ];
+ const defaultProps = {
+ className: 'test',
+ value: 'one',
+ options,
+ id: 'test',
+ label: 'test label',
+ onOptionChange: jest.fn(),
+ };
+ const getComponent = (props = {}): JSX.Element =>
+ ();
+
+ const openDropdown = async (container: HTMLElement): Promise => await act(async () => {
+ const button = container.querySelector('[role="button"]');
+ expect(button).toBeTruthy();
+ fireEvent.click(button as Element);
+ await flushPromises();
+ });
+
+ it('renders selected option', () => {
+ const { container } = render(getComponent());
+ expect(container).toMatchSnapshot();
+ });
+
+ it('renders when selected option is not in options', () => {
+ const { container } = render(getComponent({ value: 'oops' }));
+ expect(container).toMatchSnapshot();
+ });
+
+ it('renders selected option with selectedLabel', () => {
+ const { container } = render(getComponent({ selectedLabel: 'Show' }));
+ expect(container).toMatchSnapshot();
+ });
+
+ it('renders dropdown options in menu', async () => {
+ const { container } = render(getComponent());
+ await openDropdown(container);
+ expect(container.querySelector('.mx_Dropdown_menu')).toMatchSnapshot();
+ });
+});
diff --git a/test/components/views/elements/__snapshots__/FilterDropdown-test.tsx.snap b/test/components/views/elements/__snapshots__/FilterDropdown-test.tsx.snap
new file mode 100644
index 0000000000..627c92f3eb
--- /dev/null
+++ b/test/components/views/elements/__snapshots__/FilterDropdown-test.tsx.snap
@@ -0,0 +1,137 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[` renders dropdown options in menu 1`] = `
+
+`;
+
+exports[` renders selected option 1`] = `
+
+`;
+
+exports[` renders selected option with selectedLabel 1`] = `
+
+
+
+
+ Show: Option one
+
+
+
+
+
+`;
+
+exports[` renders when selected option is not in options 1`] = `
+
+`;
diff --git a/test/components/views/settings/devices/FilteredDeviceList-test.tsx b/test/components/views/settings/devices/FilteredDeviceList-test.tsx
index ecfbc0489d..68ef60e76b 100644
--- a/test/components/views/settings/devices/FilteredDeviceList-test.tsx
+++ b/test/components/views/settings/devices/FilteredDeviceList-test.tsx
@@ -94,11 +94,11 @@ describe('', () => {
) => await act(async () => {
const dropdown = container.querySelector('[aria-label="Filter devices"]');
- fireEvent.click(dropdown);
+ fireEvent.click(dropdown as Element);
// tick to let dropdown render
await flushPromises();
- fireEvent.click(container.querySelector(`#device-list-filter__${option}`));
+ fireEvent.click(container.querySelector(`#device-list-filter__${option}`) as Element);
});
it('does not display filter description when filter is falsy', () => {
@@ -198,7 +198,7 @@ describe('', () => {
act(() => {
const tile = getByTestId(`device-tile-${hundredDaysOld.device_id}`);
const toggle = tile.querySelector('[aria-label="Toggle device details"]');
- fireEvent.click(toggle);
+ fireEvent.click(toggle as Element);
});
expect(onDeviceExpandToggle).toHaveBeenCalledWith(hundredDaysOld.device_id);