Merge pull request #610 from outline/jori/natural-sort

Added natural sorting for documents and collections
This commit is contained in:
Tom Moor
2018-02-28 23:28:47 -08:00
committed by GitHub
6 changed files with 19 additions and 46 deletions

View File

@@ -8,6 +8,7 @@ import stores from 'stores';
import Collection from 'models/Collection';
import ErrorsStore from 'stores/ErrorsStore';
import UiStore from 'stores/UiStore';
import naturalSort from 'shared/utils/naturalSort';
import type { PaginationParams } from 'types';
type Options = {
@@ -42,7 +43,7 @@ class CollectionsStore {
@computed
get orderedData(): Collection[] {
return _.sortBy(this.data.values(), 'name');
return naturalSort(Array.from(this.data.values()), 'name');
}
/**

View File

@@ -1,43 +0,0 @@
/* eslint-disable */
import CollectionsStore from './CollectionsStore';
const { client } = require('utils/ApiClient');
describe('CollectionsStore', () => {
let store;
beforeEach(() => {
store = new CollectionsStore({});
});
describe('#fetchPage', () => {
test('should load stores', async () => {
client.post = jest.fn(() => ({
data: [
{
id: 123,
name: 'New collection',
},
],
}))
await store.fetchPage();
expect(client.post).toHaveBeenCalledWith('/collections.list', undefined);
expect(store.data.size).toBe(1);
expect(store.data.values()[0].name).toBe('New collection');
});
test('should report errors', async () => {
client.post = jest.fn(() => Promise.reject())
store.errors = {
add: jest.fn(),
};
await store.fetchPage();
expect(store.errors.add).toHaveBeenCalledWith(
'Failed to load collections'
);
});
});
});