Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-11-19 11:27:35 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-11-19 11:27:35 +0300
commit7e9c479f7de77702622631cff2628a9c8dcbc627 (patch)
treec8f718a08e110ad7e1894510980d2155a6549197 /spec/frontend/terraform
parente852b0ae16db4052c1c567d9efa4facc81146e88 (diff)
Add latest changes from gitlab-org/gitlab@13-6-stable-eev13.6.0-rc42
Diffstat (limited to 'spec/frontend/terraform')
-rw-r--r--spec/frontend/terraform/components/empty_state_spec.js26
-rw-r--r--spec/frontend/terraform/components/states_table_spec.js102
-rw-r--r--spec/frontend/terraform/components/terraform_list_spec.js172
3 files changed, 300 insertions, 0 deletions
diff --git a/spec/frontend/terraform/components/empty_state_spec.js b/spec/frontend/terraform/components/empty_state_spec.js
new file mode 100644
index 00000000000..c86160e18f3
--- /dev/null
+++ b/spec/frontend/terraform/components/empty_state_spec.js
@@ -0,0 +1,26 @@
+import { GlEmptyState, GlSprintf } from '@gitlab/ui';
+import { shallowMount } from '@vue/test-utils';
+import EmptyState from '~/terraform/components/empty_state.vue';
+
+describe('EmptyStateComponent', () => {
+ let wrapper;
+
+ const propsData = {
+ image: '/image/path',
+ };
+
+ beforeEach(() => {
+ wrapper = shallowMount(EmptyState, { propsData, stubs: { GlEmptyState, GlSprintf } });
+ return wrapper.vm.$nextTick();
+ });
+
+ afterEach(() => {
+ wrapper.destroy();
+ wrapper = null;
+ });
+
+ it('should render content', () => {
+ expect(wrapper.find(GlEmptyState).exists()).toBe(true);
+ expect(wrapper.text()).toContain('Get started with Terraform');
+ });
+});
diff --git a/spec/frontend/terraform/components/states_table_spec.js b/spec/frontend/terraform/components/states_table_spec.js
new file mode 100644
index 00000000000..7a8cb19971e
--- /dev/null
+++ b/spec/frontend/terraform/components/states_table_spec.js
@@ -0,0 +1,102 @@
+import { GlIcon, GlTooltip } from '@gitlab/ui';
+import { mount } from '@vue/test-utils';
+import { useFakeDate } from 'helpers/fake_date';
+import StatesTable from '~/terraform/components/states_table.vue';
+
+describe('StatesTable', () => {
+ let wrapper;
+ useFakeDate([2020, 10, 15]);
+
+ const propsData = {
+ states: [
+ {
+ name: 'state-1',
+ lockedAt: '2020-10-13T00:00:00Z',
+ lockedByUser: {
+ name: 'user-1',
+ },
+ updatedAt: '2020-10-13T00:00:00Z',
+ latestVersion: null,
+ },
+ {
+ name: 'state-2',
+ lockedAt: null,
+ lockedByUser: null,
+ updatedAt: '2020-10-10T00:00:00Z',
+ latestVersion: null,
+ },
+ {
+ name: 'state-3',
+ lockedAt: '2020-10-10T00:00:00Z',
+ lockedByUser: {
+ name: 'user-2',
+ },
+ updatedAt: '2020-10-10T00:00:00Z',
+ latestVersion: {
+ updatedAt: '2020-10-11T00:00:00Z',
+ createdByUser: {
+ name: 'user-3',
+ },
+ },
+ },
+ {
+ name: 'state-4',
+ lockedAt: '2020-10-10T00:00:00Z',
+ lockedByUser: null,
+ updatedAt: '2020-10-10T00:00:00Z',
+ latestVersion: {
+ updatedAt: '2020-10-09T00:00:00Z',
+ createdByUser: null,
+ },
+ },
+ ],
+ };
+
+ beforeEach(() => {
+ wrapper = mount(StatesTable, { propsData });
+ return wrapper.vm.$nextTick();
+ });
+
+ afterEach(() => {
+ wrapper.destroy();
+ wrapper = null;
+ });
+
+ it.each`
+ name | toolTipText | locked | lineNumber
+ ${'state-1'} | ${'Locked by user-1 2 days ago'} | ${true} | ${0}
+ ${'state-2'} | ${null} | ${false} | ${1}
+ ${'state-3'} | ${'Locked by user-2 5 days ago'} | ${true} | ${2}
+ ${'state-4'} | ${'Locked by Unknown User 5 days ago'} | ${true} | ${3}
+ `(
+ 'displays the name and locked information "$name" for line "$lineNumber"',
+ ({ name, toolTipText, locked, lineNumber }) => {
+ const states = wrapper.findAll('[data-testid="terraform-states-table-name"]');
+
+ const state = states.at(lineNumber);
+ const toolTip = state.find(GlTooltip);
+
+ expect(state.text()).toContain(name);
+ expect(state.find(GlIcon).exists()).toBe(locked);
+ expect(toolTip.exists()).toBe(locked);
+
+ if (locked) {
+ expect(toolTip.text()).toMatchInterpolatedText(toolTipText);
+ }
+ },
+ );
+
+ it.each`
+ updateTime | lineNumber
+ ${'updated 2 days ago'} | ${0}
+ ${'updated 5 days ago'} | ${1}
+ ${'user-3 updated 4 days ago'} | ${2}
+ ${'updated 6 days ago'} | ${3}
+ `('displays the time "$updateTime" for line "$lineNumber"', ({ updateTime, lineNumber }) => {
+ const states = wrapper.findAll('[data-testid="terraform-states-table-updated"]');
+
+ const state = states.at(lineNumber);
+
+ expect(state.text()).toMatchInterpolatedText(updateTime);
+ });
+});
diff --git a/spec/frontend/terraform/components/terraform_list_spec.js b/spec/frontend/terraform/components/terraform_list_spec.js
new file mode 100644
index 00000000000..b31afecc816
--- /dev/null
+++ b/spec/frontend/terraform/components/terraform_list_spec.js
@@ -0,0 +1,172 @@
+import { GlAlert, GlBadge, GlKeysetPagination, GlLoadingIcon, GlTab } from '@gitlab/ui';
+import { createLocalVue, shallowMount } from '@vue/test-utils';
+import createMockApollo from 'jest/helpers/mock_apollo_helper';
+import VueApollo from 'vue-apollo';
+import EmptyState from '~/terraform/components/empty_state.vue';
+import StatesTable from '~/terraform/components/states_table.vue';
+import TerraformList from '~/terraform/components/terraform_list.vue';
+import getStatesQuery from '~/terraform/graphql/queries/get_states.query.graphql';
+
+const localVue = createLocalVue();
+localVue.use(VueApollo);
+
+describe('TerraformList', () => {
+ let wrapper;
+
+ const propsData = {
+ emptyStateImage: '/path/to/image',
+ projectPath: 'path/to/project',
+ };
+
+ const createWrapper = ({ terraformStates, queryResponse = null }) => {
+ const apolloQueryResponse = {
+ data: {
+ project: {
+ terraformStates,
+ },
+ },
+ };
+
+ const statsQueryResponse = queryResponse || jest.fn().mockResolvedValue(apolloQueryResponse);
+ const apolloProvider = createMockApollo([[getStatesQuery, statsQueryResponse]]);
+
+ wrapper = shallowMount(TerraformList, {
+ localVue,
+ apolloProvider,
+ propsData,
+ });
+ };
+
+ const findBadge = () => wrapper.find(GlBadge);
+ const findEmptyState = () => wrapper.find(EmptyState);
+ const findPaginationButtons = () => wrapper.find(GlKeysetPagination);
+ const findStatesTable = () => wrapper.find(StatesTable);
+ const findTab = () => wrapper.find(GlTab);
+
+ afterEach(() => {
+ wrapper.destroy();
+ wrapper = null;
+ });
+
+ describe('when the terraform query has succeeded', () => {
+ describe('when there is a list of terraform states', () => {
+ const states = [
+ {
+ id: 'gid://gitlab/Terraform::State/1',
+ name: 'state-1',
+ lockedAt: null,
+ updatedAt: null,
+ lockedByUser: null,
+ latestVersion: null,
+ },
+ {
+ id: 'gid://gitlab/Terraform::State/2',
+ name: 'state-2',
+ lockedAt: null,
+ updatedAt: null,
+ lockedByUser: null,
+ latestVersion: null,
+ },
+ ];
+
+ beforeEach(() => {
+ createWrapper({
+ terraformStates: {
+ nodes: states,
+ count: states.length,
+ pageInfo: {
+ hasNextPage: true,
+ hasPreviousPage: false,
+ startCursor: 'prev',
+ endCursor: 'next',
+ },
+ },
+ });
+
+ return wrapper.vm.$nextTick();
+ });
+
+ it('displays a states tab and count', () => {
+ expect(findTab().text()).toContain('States');
+ expect(findBadge().text()).toBe('2');
+ });
+
+ it('renders the states table and pagination buttons', () => {
+ expect(findStatesTable().exists()).toBe(true);
+ expect(findPaginationButtons().exists()).toBe(true);
+ });
+
+ describe('when list has no additional pages', () => {
+ beforeEach(() => {
+ createWrapper({
+ terraformStates: {
+ nodes: states,
+ count: states.length,
+ pageInfo: {
+ hasNextPage: false,
+ hasPreviousPage: false,
+ startCursor: '',
+ endCursor: '',
+ },
+ },
+ });
+
+ return wrapper.vm.$nextTick();
+ });
+
+ it('renders the states table without pagination buttons', () => {
+ expect(findStatesTable().exists()).toBe(true);
+ expect(findPaginationButtons().exists()).toBe(false);
+ });
+ });
+ });
+
+ describe('when the list of terraform states is empty', () => {
+ beforeEach(() => {
+ createWrapper({
+ terraformStates: {
+ nodes: [],
+ count: 0,
+ pageInfo: null,
+ },
+ });
+
+ return wrapper.vm.$nextTick();
+ });
+
+ it('displays a states tab with no count', () => {
+ expect(findTab().text()).toContain('States');
+ expect(findBadge().exists()).toBe(false);
+ });
+
+ it('renders the empty state', () => {
+ expect(findEmptyState().exists()).toBe(true);
+ });
+ });
+ });
+
+ describe('when the terraform query has errored', () => {
+ beforeEach(() => {
+ createWrapper({ terraformStates: null, queryResponse: jest.fn().mockRejectedValue() });
+
+ return wrapper.vm.$nextTick();
+ });
+
+ it('displays an alert message', () => {
+ expect(wrapper.find(GlAlert).exists()).toBe(true);
+ });
+ });
+
+ describe('when the terraform query is loading', () => {
+ beforeEach(() => {
+ createWrapper({
+ terraformStates: null,
+ queryResponse: jest.fn().mockReturnValue(new Promise(() => {})),
+ });
+ });
+
+ it('displays a loading icon', () => {
+ expect(wrapper.find(GlLoadingIcon).exists()).toBe(true);
+ });
+ });
+});