mirror of
https://github.com/CzBiX/qb-web.git
synced 2026-04-13 14:50:25 +08:00
63 lines
1.2 KiB
TypeScript
63 lines
1.2 KiB
TypeScript
import Vuex from 'vuex';
|
|
import { createLocalVue } from '@vue/test-utils';
|
|
import store from '@/store';
|
|
import { RootState } from '@/store/types';
|
|
import { mock, mockBaseTorrent } from '../utils';
|
|
|
|
|
|
const localVue = createLocalVue();
|
|
localVue.use(Vuex);
|
|
|
|
const emtpyState: RootState = {
|
|
rid: 0,
|
|
mainData: undefined,
|
|
preferences: null,
|
|
pasteUrl: null,
|
|
};
|
|
|
|
const mockState = mock(emtpyState);
|
|
|
|
beforeEach(() => {
|
|
store.replaceState(emtpyState);
|
|
});
|
|
|
|
test('update preferences', () => {
|
|
const obj = {
|
|
url: 'something',
|
|
};
|
|
store.commit('updatePreferences', obj);
|
|
|
|
expect(store.state.preferences).toEqual(obj);
|
|
});
|
|
|
|
test('set paste url', () => {
|
|
store.commit('setPasteUrl', {
|
|
url: 'something',
|
|
});
|
|
|
|
expect(store.state.pasteUrl).toEqual('something');
|
|
});
|
|
|
|
describe('all torrents getter', () => {
|
|
test('empty', () => {
|
|
expect(store.getters.allTorrents).toEqual([]);
|
|
});
|
|
|
|
test('with data', () => {
|
|
store.replaceState(mockState({
|
|
mainData: {
|
|
categories: {},
|
|
server_state: undefined as any,
|
|
torrents: {
|
|
a: mockBaseTorrent({}),
|
|
b: mockBaseTorrent({}),
|
|
},
|
|
},
|
|
}));
|
|
|
|
expect(store.getters.allTorrents).toMatchObject([
|
|
{ hash: 'a' }, { hash: 'b' },
|
|
]);
|
|
});
|
|
});
|