2019-08-15 19:21:46 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
import Vuex from 'vuex';
|
2019-09-09 11:33:39 +01:00
|
|
|
|
2019-08-19 11:00:38 +01:00
|
|
|
import ApiKeysArea from '@/components/apiKeys/ApiKeysArea.vue';
|
2019-09-09 11:33:39 +01:00
|
|
|
|
|
|
|
import { ApiKeysApiGql } from '@/api/apiKeys';
|
2019-09-12 15:10:50 +01:00
|
|
|
import { API_KEYS_MUTATIONS, makeApiKeysModule } from '@/store/modules/apiKeys';
|
2019-08-29 11:05:22 +01:00
|
|
|
import { makeNotificationsModule } from '@/store/modules/notifications';
|
2019-09-12 15:10:50 +01:00
|
|
|
import { ApiKey, ApiKeysPage } from '@/types/apiKeys';
|
2019-09-26 14:36:12 +01:00
|
|
|
import { createLocalVue, shallowMount } from '@vue/test-utils';
|
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);
|
2019-08-29 11:05:22 +01:00
|
|
|
const notificationsModule = makeNotificationsModule();
|
2019-09-26 14:36:12 +01:00
|
|
|
const { SET_PAGE, CLEAR } = API_KEYS_MUTATIONS;
|
2019-08-29 11:05:22 +01:00
|
|
|
const store = new Vuex.Store({ modules: { apiKeysModule, notificationsModule }});
|
2019-08-15 19:21:46 +01:00
|
|
|
|
|
|
|
describe('ApiKeysArea', () => {
|
2019-09-09 11:33:39 +01:00
|
|
|
const apiKey = new ApiKey('testId', 'test', 'test', 'test');
|
|
|
|
const apiKey1 = new ApiKey('testId1', 'test1', 'test1', 'test1');
|
2019-08-15 19:21:46 +01:00
|
|
|
|
2019-09-12 15:10:50 +01:00
|
|
|
const testApiKeysPage = new ApiKeysPage();
|
|
|
|
testApiKeysPage.apiKeys = [apiKey];
|
|
|
|
testApiKeysPage.totalCount = 1;
|
|
|
|
testApiKeysPage.pageCount = 1;
|
|
|
|
|
2019-08-15 19:21:46 +01:00
|
|
|
it('renders correctly', () => {
|
2019-09-12 15:10:50 +01:00
|
|
|
const wrapper = shallowMount(ApiKeysArea, {
|
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders empty screen with add key prompt', () => {
|
|
|
|
const wrapper = shallowMount(ApiKeysArea, {
|
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
store.commit(CLEAR);
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders empty search state correctly', () => {
|
|
|
|
const wrapper = shallowMount(ApiKeysArea, {
|
2019-08-15 19:21:46 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('function apiKeyList works correctly', () => {
|
2019-09-12 15:10:50 +01:00
|
|
|
store.commit(SET_PAGE, testApiKeysPage);
|
2019-08-15 19:21:46 +01:00
|
|
|
|
2019-09-12 15:10:50 +01:00
|
|
|
const wrapper = shallowMount(ApiKeysArea, {
|
2019-08-15 19:21:46 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.vm.apiKeyList).toEqual([apiKey]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('action on toggleSelection works correctly', () => {
|
2019-09-12 15:10:50 +01:00
|
|
|
store.commit(SET_PAGE, testApiKeysPage);
|
2019-08-15 19:21:46 +01:00
|
|
|
|
2019-09-12 15:10:50 +01:00
|
|
|
const wrapper = shallowMount(ApiKeysArea, {
|
2019-08-15 19:21:46 +01:00
|
|
|
store,
|
2019-09-13 15:58:18 +01:00
|
|
|
localVue,
|
2019-08-15 19:21:46 +01:00
|
|
|
});
|
|
|
|
|
2019-09-12 15:10:50 +01:00
|
|
|
wrapper.vm.toggleSelection(apiKey);
|
2019-08-15 19:21:46 +01:00
|
|
|
|
2019-09-12 15:10:50 +01:00
|
|
|
expect(store.getters.selectedApiKeys.length).toBe(1);
|
2019-08-15 19:21:46 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('action on onClearSelection works correctly', () => {
|
2019-09-12 15:10:50 +01:00
|
|
|
const wrapper = shallowMount(ApiKeysArea, {
|
2019-08-15 19:21:46 +01:00
|
|
|
store,
|
2019-09-13 15:58:18 +01:00
|
|
|
localVue,
|
2019-08-15 19:21:46 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
wrapper.vm.onClearSelection();
|
|
|
|
|
|
|
|
expect(wrapper.vm.$data.isDeleteClicked).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('function onCreateApiKeyClick works correctly', () => {
|
2019-09-12 15:10:50 +01:00
|
|
|
const wrapper = shallowMount(ApiKeysArea, {
|
2019-08-15 19:21:46 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
wrapper.vm.onCreateApiKeyClick();
|
|
|
|
|
|
|
|
expect(wrapper.vm.$data.isNewApiKeyPopupShown).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('function onFirstDeleteClick works correctly', () => {
|
2019-09-12 15:10:50 +01:00
|
|
|
const wrapper = shallowMount(ApiKeysArea, {
|
2019-08-15 19:21:46 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
wrapper.vm.onFirstDeleteClick();
|
|
|
|
|
|
|
|
expect(wrapper.vm.$data.isDeleteClicked).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('function apiKeyCountTitle works correctly', () => {
|
2019-09-12 15:10:50 +01:00
|
|
|
const wrapper = shallowMount(ApiKeysArea, {
|
2019-08-15 19:21:46 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.vm.apiKeyCountTitle).toMatch('api key');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('function isEmpty works correctly', () => {
|
2019-09-12 15:10:50 +01:00
|
|
|
store.commit(SET_PAGE, testApiKeysPage);
|
2019-08-15 19:21:46 +01:00
|
|
|
|
2019-09-12 15:10:50 +01:00
|
|
|
const wrapper = shallowMount(ApiKeysArea, {
|
2019-08-15 19:21:46 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.vm.isEmpty).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('function selectedAPIKeysCount works correctly', () => {
|
2019-09-12 15:10:50 +01:00
|
|
|
const wrapper = shallowMount(ApiKeysArea, {
|
2019-08-15 19:21:46 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.vm.selectedAPIKeysCount).toBe(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('function headerState works correctly', () => {
|
2019-09-12 15:10:50 +01:00
|
|
|
const wrapper = shallowMount(ApiKeysArea, {
|
2019-08-15 19:21:46 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.vm.headerState).toBe(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('function apiKeyCountTitle with 2 keys works correctly', () => {
|
2019-09-12 15:10:50 +01:00
|
|
|
const testPage = new ApiKeysPage();
|
|
|
|
testPage.apiKeys = [apiKey, apiKey1];
|
|
|
|
testPage.totalCount = 1;
|
|
|
|
testPage.pageCount = 1;
|
|
|
|
|
|
|
|
store.commit(SET_PAGE, testPage);
|
2019-08-15 19:21:46 +01:00
|
|
|
|
2019-09-12 15:10:50 +01:00
|
|
|
const wrapper = shallowMount(ApiKeysArea, {
|
2019-08-15 19:21:46 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.vm.apiKeyCountTitle).toMatch('api keys');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('function closeNewApiKeyPopup works correctly', () => {
|
2019-09-12 15:10:50 +01:00
|
|
|
const wrapper = shallowMount(ApiKeysArea, {
|
2019-08-15 19:21:46 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
wrapper.vm.closeNewApiKeyPopup();
|
|
|
|
|
|
|
|
expect(wrapper.vm.$data.isNewApiKeyPopupShown).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('function showCopyApiKeyPopup works correctly', () => {
|
2019-09-12 15:10:50 +01:00
|
|
|
const wrapper = shallowMount(ApiKeysArea, {
|
2019-08-15 19:21:46 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
2019-09-09 11:33:39 +01:00
|
|
|
const testSecret = 'testSecret';
|
2019-08-15 19:21:46 +01:00
|
|
|
|
|
|
|
wrapper.vm.showCopyApiKeyPopup(testSecret);
|
|
|
|
|
|
|
|
expect(wrapper.vm.$data.isCopyApiKeyPopupShown).toBe(true);
|
|
|
|
expect(wrapper.vm.$data.apiKeySecret).toMatch('testSecret');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('function closeCopyNewApiKeyPopup works correctly', () => {
|
2019-09-12 15:10:50 +01:00
|
|
|
const wrapper = shallowMount(ApiKeysArea, {
|
2019-08-15 19:21:46 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
wrapper.vm.closeCopyNewApiKeyPopup();
|
|
|
|
|
|
|
|
expect(wrapper.vm.$data.isCopyApiKeyPopupShown).toBe(false);
|
|
|
|
});
|
|
|
|
|
2019-09-09 11:33:39 +01:00
|
|
|
it('action on onDelete with name works correctly', () => {
|
2019-09-12 15:10:50 +01:00
|
|
|
const wrapper = shallowMount(ApiKeysArea, {
|
2019-08-15 19:21:46 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
wrapper.vm.onDelete();
|
|
|
|
|
|
|
|
expect(wrapper.vm.$data.isDeleteClicked).toBe(false);
|
|
|
|
});
|
|
|
|
});
|