mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-10 18:27:25 +03:00
Improved sorting dropdown to display order field and order dir
This commit is contained in:
parent
16f4f7eac8
commit
93b4de60f6
2 changed files with 22 additions and 2 deletions
|
@ -33,7 +33,7 @@ export default function SortingDropdown<T extends string = string>(
|
|||
>
|
||||
{!isButton && <>Order by</>}
|
||||
{isButton && !orderField && <>Order by...</>}
|
||||
{isButton && orderField && <>Order by: {items[orderField]} - {orderDir}</>}
|
||||
{isButton && orderField && `Order by: "${items[orderField]}" - "${orderDir ?? 'DESC'}"`}
|
||||
</DropdownToggle>
|
||||
<DropdownMenu
|
||||
right={right}
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import { shallow, ShallowWrapper } from 'enzyme';
|
||||
import { DropdownItem } from 'reactstrap';
|
||||
import { DropdownItem, DropdownToggle } from 'reactstrap';
|
||||
import { identity, values } from 'ramda';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import { faSortAmountDown as caretDownIcon } from '@fortawesome/free-solid-svg-icons';
|
||||
import SortingDropdown, { SortingDropdownProps } from '../../src/utils/SortingDropdown';
|
||||
import { OrderDir } from '../../src/utils/utils';
|
||||
|
||||
describe('<SortingDropdown />', () => {
|
||||
let wrapper: ShallowWrapper;
|
||||
|
@ -73,4 +74,23 @@ describe('<SortingDropdown />', () => {
|
|||
expect(onChange).toHaveBeenCalledTimes(1);
|
||||
expect(onChange).toHaveBeenCalledWith('foo', 'DESC');
|
||||
});
|
||||
|
||||
it.each([
|
||||
[{ isButton: false }, '>Order by<' ],
|
||||
[{ isButton: true }, '>Order by...<' ],
|
||||
[
|
||||
{ isButton: true, orderField: 'foo', orderDir: 'ASC' as OrderDir },
|
||||
'Order by: "Foo" - "ASC"',
|
||||
],
|
||||
[
|
||||
{ isButton: true, orderField: 'baz', orderDir: 'DESC' as OrderDir },
|
||||
'Order by: "Hello World" - "DESC"',
|
||||
],
|
||||
[{ isButton: true, orderField: 'baz' }, 'Order by: "Hello World" - "DESC"' ],
|
||||
])('displays expected text in toggle', (props, expectedText) => {
|
||||
const wrapper = createWrapper(props);
|
||||
const toggle = wrapper.find(DropdownToggle);
|
||||
|
||||
expect(toggle.html()).toContain(expectedText);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue