diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-22 03:09:11 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-22 03:09:11 +0300 |
commit | ab85af0f318ccbcfdd508e7a2f85788f26831785 (patch) | |
tree | 497309067bd3ab4378f9d4bbf95859c64f95744f /spec/frontend/ci_variable_list/components/ci_variable_table_spec.js | |
parent | a6c2be7cd20a9515b347e72d63c5b47bb9b79457 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/ci_variable_list/components/ci_variable_table_spec.js')
-rw-r--r-- | spec/frontend/ci_variable_list/components/ci_variable_table_spec.js | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/spec/frontend/ci_variable_list/components/ci_variable_table_spec.js b/spec/frontend/ci_variable_list/components/ci_variable_table_spec.js new file mode 100644 index 00000000000..973a9c51f16 --- /dev/null +++ b/spec/frontend/ci_variable_list/components/ci_variable_table_spec.js @@ -0,0 +1,89 @@ +import Vuex from 'vuex'; +import { createLocalVue, mount } from '@vue/test-utils'; +import { GlTable } from '@gitlab/ui'; +import CiVariableTable from '~/ci_variable_list/components/ci_variable_table.vue'; +import createStore from '~/ci_variable_list/store'; +import mockData from '../services/mock_data'; + +const localVue = createLocalVue(); +localVue.use(Vuex); + +describe('Ci variable table', () => { + let wrapper; + let store; + + const createComponent = () => { + store = createStore(); + store.state.isGroup = true; + jest.spyOn(store, 'dispatch').mockImplementation(); + wrapper = mount(CiVariableTable, { + localVue, + store, + }); + }; + + const findDeleteButton = () => wrapper.find({ ref: 'delete-ci-variable' }); + const findRevealButton = () => wrapper.find({ ref: 'secret-value-reveal-button' }); + const findEditButton = () => wrapper.find({ ref: 'edit-ci-variable' }); + const findEmptyVariablesPlaceholder = () => wrapper.find({ ref: 'empty-variables' }); + const findTable = () => wrapper.find(GlTable); + + beforeEach(() => { + createComponent(); + }); + + afterEach(() => { + wrapper.destroy(); + }); + + it('dispatches fetchVariables when mounted', () => { + expect(store.dispatch).toHaveBeenCalledWith('fetchVariables'); + }); + + it('fields prop does not contain environment_scope if group', () => { + expect(findTable().props('fields')).not.toEqual( + expect.arrayContaining([ + expect.objectContaining({ + key: 'environment_scope', + label: 'Environment Scope', + }), + ]), + ); + }); + + describe('Renders correct data', () => { + it('displays empty message when variables are not present', () => { + expect(findEmptyVariablesPlaceholder().exists()).toBe(true); + }); + + it('displays correct amount of variables present and no empty message', () => { + store.state.variables = mockData.mockVariables; + + return wrapper.vm.$nextTick(() => { + expect(wrapper.findAll('.js-ci-variable-row').length).toBe(1); + expect(findEmptyVariablesPlaceholder().exists()).toBe(false); + }); + }); + }); + + describe('Table click actions', () => { + beforeEach(() => { + store.state.variables = mockData.mockVariables; + }); + + it('dispatches deleteVariable with correct variable to delete', () => { + findDeleteButton().trigger('click'); + expect(store.dispatch).toHaveBeenCalledWith('deleteVariable', mockData.mockVariables[0]); + }); + + it('reveals secret values when button is clicked', () => { + findRevealButton().trigger('click'); + expect(store.dispatch).toHaveBeenCalledWith('toggleValues', false); + }); + + it('dispatches editVariable with correct variable to edit', () => { + findEditButton().trigger('click'); + expect(store.dispatch).toHaveBeenCalledWith('editVariable', mockData.mockVariables[0]); + }); + }); +}); |