6b153192a3
After migrating to eslint some errors were disabled to make it easier to migrate. This enables all the lint rules and treats all warnings as a build failure. Similarly, CI won't automatically try to fix mistakes. Change-Id: I80f808af026fc51bed90421b3b24737994a52094
98 lines
2.9 KiB
TypeScript
98 lines
2.9 KiB
TypeScript
// Copyright (C) 2019 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
import Vuex from 'vuex';
|
|
|
|
import { BucketsApiGql } from '@/api/buckets';
|
|
import { ProjectsApiGql } from '@/api/projects';
|
|
import { BUCKET_ACTIONS, makeBucketsModule } from '@/store/modules/buckets';
|
|
import { makeProjectsModule } from '@/store/modules/projects';
|
|
import { Bucket, BucketCursor, BucketPage } from '@/types/buckets';
|
|
import { Project } from '@/types/projects';
|
|
import { createLocalVue } from '@vue/test-utils';
|
|
|
|
const Vue = createLocalVue();
|
|
const bucketsApi = new BucketsApiGql();
|
|
const bucketsModule = makeBucketsModule(bucketsApi);
|
|
const { FETCH, SET_SEARCH, CLEAR } = BUCKET_ACTIONS;
|
|
|
|
const projectsApi = new ProjectsApiGql();
|
|
const projectsModule = makeProjectsModule(projectsApi);
|
|
const selectedProject = new Project();
|
|
selectedProject.id = '1';
|
|
projectsModule.state.selectedProject = selectedProject;
|
|
|
|
Vue.use(Vuex);
|
|
|
|
const store = new Vuex.Store<{
|
|
projectsModule: typeof projectsModule.state,
|
|
bucketsModule: typeof bucketsModule.state,
|
|
}>({modules: { projectsModule, bucketsModule } });
|
|
const state = store.state.bucketsModule;
|
|
const bucket = new Bucket('test', 10, 10, 1, new Date(), new Date());
|
|
const page: BucketPage = { buckets: [bucket], currentPage: 1, pageCount: 1, offset: 0, limit: 7, search: 'test', totalCount: 1 };
|
|
|
|
describe('actions', () => {
|
|
beforeEach(() => {
|
|
jest.resetAllMocks();
|
|
});
|
|
|
|
it('success fetch buckets', async () => {
|
|
jest.spyOn(bucketsApi, 'get').mockReturnValue(
|
|
Promise.resolve(page),
|
|
);
|
|
|
|
await store.dispatch(FETCH, 1);
|
|
|
|
expect(state.page).toEqual(page);
|
|
expect(state.cursor.page).toEqual(1);
|
|
});
|
|
|
|
it('fetch throws an error when api call fails', async () => {
|
|
jest.spyOn(bucketsApi, 'get').mockImplementation(() => { throw new Error(); });
|
|
|
|
try {
|
|
await store.dispatch(FETCH , 1);
|
|
} catch (error) {
|
|
expect(state.page).toEqual(page);
|
|
}
|
|
});
|
|
|
|
it('success set search buckets', () => {
|
|
store.dispatch(SET_SEARCH, 'test');
|
|
|
|
expect(state.cursor.search).toMatch('test');
|
|
});
|
|
|
|
it('success clear', () => {
|
|
store.dispatch(CLEAR);
|
|
|
|
expect(state.cursor).toEqual(new BucketCursor('', 7, 1));
|
|
expect(state.page).toEqual(new BucketPage([], '', 7, 0, 1, 1, 0));
|
|
});
|
|
});
|
|
|
|
describe('getters', () => {
|
|
const page: BucketPage = { buckets: [bucket], currentPage: 1, pageCount: 1, offset: 0, limit: 7, search: 'test', totalCount: 1 };
|
|
|
|
it('page of buckets', async () => {
|
|
jest.spyOn(bucketsApi, 'get').mockReturnValue(
|
|
Promise.resolve(page),
|
|
);
|
|
|
|
await store.dispatch(FETCH, 1);
|
|
|
|
const storePage = store.getters.page;
|
|
|
|
expect(storePage).toEqual(page);
|
|
});
|
|
|
|
it('cursor of buckets', () => {
|
|
store.dispatch(CLEAR);
|
|
|
|
const cursor = store.getters.cursor;
|
|
|
|
expect(cursor).toEqual(new BucketCursor('', 7, 1));
|
|
});
|
|
});
|