storj/web/satellite/tests/unit/onboardingTour/steps/CreateApiKeyStep.spec.ts
VitaliiShpital 2284008b8c web/satellite: onboarding tour: api keys and upload data steps
Change-Id: I8ffa6d688a22c1568495a7e0e176096cadcd6eaa
2020-05-04 13:26:12 +00:00

71 lines
2.3 KiB
TypeScript

// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.
import Vuex from 'vuex';
import CreateApiKeyStep from '@/components/onboardingTour/steps/CreateApiKeyStep.vue';
import { makeApiKeysModule } from '@/store/modules/apiKeys';
import { makeProjectsModule } from '@/store/modules/projects';
import { ApiKeysPage } from '@/types/apiKeys';
import { Project } from '@/types/projects';
import { NotificatorPlugin } from '@/utils/plugins/notificator';
import { SegmentioPlugin } from '@/utils/plugins/segment';
import { createLocalVue, mount } from '@vue/test-utils';
import { ApiKeysMock } from '../../mock/api/apiKeys';
import { ProjectsApiMock } from '../../mock/api/projects';
const localVue = createLocalVue();
const notificationPlugin = new NotificatorPlugin();
const segmentioPlugin = new SegmentioPlugin();
const projectsApi = new ProjectsApiMock();
const projectsModule = makeProjectsModule(projectsApi);
const apiKeysApi = new ApiKeysMock();
const apiKeysModule = makeApiKeysModule(apiKeysApi);
apiKeysApi.setMockApiKeysPage(new ApiKeysPage());
const project = new Project('id', 'projectName', 'projectDescription', 'test', 'testOwnerId', true);
projectsApi.setMockProjects([project]);
localVue.use(Vuex);
localVue.use(notificationPlugin);
localVue.use(segmentioPlugin);
const store = new Vuex.Store({ modules: { projectsModule, apiKeysModule }});
describe('CreateApiKeyStep.vue', () => {
it('renders correctly', (): void => {
const wrapper = mount(CreateApiKeyStep, {
store,
localVue,
});
expect(wrapper.findAll('.disabled').length).toBe(1);
expect(wrapper).toMatchSnapshot();
});
it('create api key works correctly correctly', async (): Promise<void> => {
const wrapper = mount(CreateApiKeyStep, {
store,
localVue,
});
await wrapper.vm.setApiKeyName('testName');
await wrapper.vm.createApiKey();
expect(wrapper.findAll('.disabled').length).toBe(0);
expect(wrapper).toMatchSnapshot();
});
it('done click works correctly correctly', async (): Promise<void> => {
const wrapper = mount(CreateApiKeyStep, {
store,
localVue,
});
await wrapper.find('.done-button').trigger('click');
expect(wrapper.emitted()).toHaveProperty('setUploadDataState');
});
});