2019-08-15 19:21:46 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
import { createLocalVue, mount } from '@vue/test-utils';
|
|
|
|
import Vuex from 'vuex';
|
2019-08-19 11:00:38 +01:00
|
|
|
import ApiKeysArea from '@/components/apiKeys/ApiKeysArea.vue';
|
2019-08-15 19:21:46 +01:00
|
|
|
import { ApiKey } from '@/types/apiKeys';
|
|
|
|
import { makeApiKeysModule } from '@/store/modules/apiKeys';
|
|
|
|
import { API_KEYS_MUTATIONS } from '@/store/mutationConstants';
|
2019-08-19 11:00:38 +01:00
|
|
|
import { ApiKeysApiGql } from '@/api/apiKeys';
|
2019-08-15 19:21:46 +01:00
|
|
|
|
|
|
|
const localVue = createLocalVue();
|
|
|
|
localVue.use(Vuex);
|
2019-08-19 11:00:38 +01:00
|
|
|
const apiKeysApi = new ApiKeysApiGql();
|
|
|
|
const apiKeysModule = makeApiKeysModule(apiKeysApi);
|
|
|
|
const ADD = API_KEYS_MUTATIONS.ADD;
|
2019-08-15 19:21:46 +01:00
|
|
|
const store = new Vuex.Store(apiKeysModule);
|
|
|
|
|
|
|
|
describe('ApiKeysArea', () => {
|
|
|
|
let apiKey = new ApiKey('testId', 'test', 'test', 'test');
|
|
|
|
let apiKey1 = new ApiKey('testId1', 'test1', 'test1', 'test1');
|
|
|
|
|
|
|
|
it('renders correctly', () => {
|
|
|
|
const wrapper = mount(ApiKeysArea, {
|
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('function apiKeyList works correctly', () => {
|
2019-08-19 11:00:38 +01:00
|
|
|
store.commit(ADD, apiKey);
|
2019-08-15 19:21:46 +01:00
|
|
|
|
|
|
|
const wrapper = mount(ApiKeysArea, {
|
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.vm.apiKeyList).toEqual([apiKey]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('action on toggleSelection works correctly', () => {
|
2019-08-19 11:00:38 +01:00
|
|
|
store.commit(ADD, apiKey1);
|
2019-08-15 19:21:46 +01:00
|
|
|
|
|
|
|
const wrapper = mount(ApiKeysArea, {
|
|
|
|
store,
|
|
|
|
localVue
|
|
|
|
});
|
|
|
|
|
2019-08-21 14:47:07 +01:00
|
|
|
wrapper.vm.toggleSelection(apiKey1);
|
2019-08-15 19:21:46 +01:00
|
|
|
|
|
|
|
expect(store.getters.selectedAPIKeys.length).toBe(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('action on onClearSelection works correctly', () => {
|
|
|
|
const wrapper = mount(ApiKeysArea, {
|
|
|
|
store,
|
|
|
|
localVue
|
|
|
|
});
|
|
|
|
|
|
|
|
wrapper.vm.onClearSelection();
|
|
|
|
|
|
|
|
expect(wrapper.vm.$data.isDeleteClicked).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('function onCreateApiKeyClick works correctly', () => {
|
|
|
|
const wrapper = mount(ApiKeysArea, {
|
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
wrapper.vm.onCreateApiKeyClick();
|
|
|
|
|
|
|
|
expect(wrapper.vm.$data.isNewApiKeyPopupShown).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('function onFirstDeleteClick works correctly', () => {
|
|
|
|
const wrapper = mount(ApiKeysArea, {
|
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
wrapper.vm.onFirstDeleteClick();
|
|
|
|
|
|
|
|
expect(wrapper.vm.$data.isDeleteClicked).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('function apiKeyCountTitle works correctly', () => {
|
|
|
|
const wrapper = mount(ApiKeysArea, {
|
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.vm.apiKeyCountTitle).toMatch('api key');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('function isEmpty works correctly', () => {
|
2019-08-19 11:00:38 +01:00
|
|
|
store.commit(ADD, apiKey);
|
2019-08-15 19:21:46 +01:00
|
|
|
|
|
|
|
const wrapper = mount(ApiKeysArea, {
|
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.vm.isEmpty).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('function isSelected works correctly', () => {
|
|
|
|
const wrapper = mount(ApiKeysArea, {
|
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.vm.isSelected).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('function selectedAPIKeysCount works correctly', () => {
|
|
|
|
const wrapper = mount(ApiKeysArea, {
|
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.vm.selectedAPIKeysCount).toBe(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('function headerState works correctly', () => {
|
|
|
|
const wrapper = mount(ApiKeysArea, {
|
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.vm.headerState).toBe(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('function apiKeyCountTitle with 2 keys works correctly', () => {
|
2019-08-19 11:00:38 +01:00
|
|
|
store.commit(ADD, apiKey);
|
|
|
|
store.commit(ADD, apiKey1);
|
2019-08-15 19:21:46 +01:00
|
|
|
|
|
|
|
const wrapper = mount(ApiKeysArea, {
|
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.vm.apiKeyCountTitle).toMatch('api keys');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('function closeNewApiKeyPopup works correctly', () => {
|
|
|
|
const wrapper = mount(ApiKeysArea, {
|
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
wrapper.vm.closeNewApiKeyPopup();
|
|
|
|
|
|
|
|
expect(wrapper.vm.$data.isNewApiKeyPopupShown).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('function showCopyApiKeyPopup works correctly', () => {
|
|
|
|
const wrapper = mount(ApiKeysArea, {
|
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
let testSecret = 'testSecret';
|
|
|
|
|
|
|
|
wrapper.vm.showCopyApiKeyPopup(testSecret);
|
|
|
|
|
|
|
|
expect(wrapper.vm.$data.isCopyApiKeyPopupShown).toBe(true);
|
|
|
|
expect(wrapper.vm.$data.apiKeySecret).toMatch('testSecret');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('function closeCopyNewApiKeyPopup works correctly', () => {
|
|
|
|
const wrapper = mount(ApiKeysArea, {
|
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
wrapper.vm.closeCopyNewApiKeyPopup();
|
|
|
|
|
|
|
|
expect(wrapper.vm.$data.isCopyApiKeyPopupShown).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('action on onDelete with name works correctly', async () => {
|
|
|
|
const wrapper = mount(ApiKeysArea, {
|
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
wrapper.vm.onDelete();
|
|
|
|
|
|
|
|
expect(wrapper.vm.$data.isDeleteClicked).toBe(false);
|
|
|
|
});
|
|
|
|
});
|