This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
outline/frontend/stores/CollectionsStore.test.js

55 lines
1.1 KiB
JavaScript

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