123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- import {act, render} from 'sentry-test/reactTestingLibrary';
- import {useSorts} from 'sentry/views/explore/hooks/useSorts';
- describe('useSorts', function () {
- it('allows changing sorts', function () {
- let sorts, setSorts;
- const fields = ['id', 'timestamp'];
- function TestPage() {
- [sorts, setSorts] = useSorts({fields});
- return null;
- }
- render(<TestPage />, {disableRouterMocks: true});
- expect(sorts).toEqual([
- {
- kind: 'desc',
- field: 'timestamp',
- },
- ]); // default
- act(() =>
- setSorts([
- {
- kind: 'asc',
- field: 'timestamp',
- },
- ])
- );
- expect(sorts).toEqual([
- {
- kind: 'asc',
- field: 'timestamp',
- },
- ]);
- act(() =>
- setSorts([
- {
- kind: 'desc',
- field: 'id',
- },
- ])
- );
- expect(sorts).toEqual([
- {
- kind: 'desc',
- field: 'id',
- },
- ]);
- });
- it('falls back to timestamp desc if possible', function () {
- let sorts, setSorts;
- const fields = ['id', 'timestamp'];
- function TestPage() {
- [sorts, setSorts] = useSorts({fields});
- return null;
- }
- render(<TestPage />, {disableRouterMocks: true});
- act(() =>
- setSorts([
- {
- kind: 'asc',
- field: 'foo',
- },
- ])
- );
- expect(sorts).toEqual([
- {
- kind: 'desc',
- field: 'timestamp',
- },
- ]);
- });
- it('falls back to first column desc if timestamp is not available', function () {
- let sorts, setSorts;
- const fields = ['id'];
- function TestPage() {
- [sorts, setSorts] = useSorts({fields});
- return null;
- }
- render(<TestPage />, {disableRouterMocks: true});
- act(() =>
- setSorts([
- {
- kind: 'asc',
- field: 'foo',
- },
- ])
- );
- expect(sorts).toEqual([
- {
- kind: 'desc',
- field: 'id',
- },
- ]);
- });
- });
|