Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add clear sort order test #7336

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/insomnia/src/common/__tests__/sorting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ import {
} from '../sorting';

describe('Sorting methods', () => {
it('defaults to ascending metaSortKey aka descending but flipped (* -1)', () => {
const unsorted = [
{ _id: '', metaSortKey: -990 },
{ _id: '', metaSortKey: -800 },
{ _id: '', metaSortKey: -799 },
{ _id: '', metaSortKey: -1000 },
{ _id: '', metaSortKey: -999 }];
const sorted = unsorted.sort(sortMethodMap['type-manual']);
expect(sorted).toEqual([
{ _id: '', metaSortKey: -1000 },
{ _id: '', metaSortKey: -999 },
{ _id: '', metaSortKey: -990 },
{ _id: '', metaSortKey: -800 },
{ _id: '', metaSortKey: -799 },
]);
});
it('sorts by name', () => {
const ascendingNameSort = sortMethodMap[SORT_NAME_ASC];
expect(
Expand Down
8 changes: 1 addition & 7 deletions packages/insomnia/src/ui/routes/workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,7 @@ export const workspaceLoader: LoaderFunction = async ({
const searchParams = new URL(request.url).searchParams;
const filter = searchParams.get('filter');
const sortOrder = searchParams.get('sortOrder') as SortOrder;
const defaultSort = (a: Request | GrpcRequest | WebSocketRequest | RequestGroup, b: Request | GrpcRequest | WebSocketRequest | RequestGroup) => {
if (a.metaSortKey === b.metaSortKey) {
return a._id > b._id ? -1 : 1;
}
return a.metaSortKey < b.metaSortKey ? -1 : 1;
};
const sortFunction = sortMethodMap[sortOrder] || defaultSort;
const sortFunction = sortMethodMap[sortOrder] || sortMethodMap['type-manual'];

// first recursion to get all the folders ids in order to use nedb search by an array
const flattenFoldersIntoList = async (id: string): Promise<string[]> => {
Expand Down
Loading