debian-mirror-gitlab/spec/frontend/environments/environment_details/index_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

110 lines
3.7 KiB
JavaScript
Raw Normal View History

2023-03-17 16:20:25 +05:30
import Vue from 'vue';
import VueApollo from 'vue-apollo';
import { GlLoadingIcon, GlTableLite } from '@gitlab/ui';
import resolvedEnvironmentDetails from 'test_fixtures/graphql/environments/graphql/queries/environment_details.query.graphql.json';
import emptyEnvironmentDetails from 'test_fixtures/graphql/environments/graphql/queries/environment_details.query.graphql.empty.json';
import { mountExtended } from 'helpers/vue_test_utils_helper';
import EnvironmentsDetailPage from '~/environments/environment_details/index.vue';
2023-07-09 08:55:56 +05:30
import ConfirmRollbackModal from '~/environments/components/confirm_rollback_modal.vue';
2023-03-17 16:20:25 +05:30
import EmptyState from '~/environments/environment_details/empty_state.vue';
import getEnvironmentDetails from '~/environments/graphql/queries/environment_details.query.graphql';
2023-07-09 08:55:56 +05:30
import createMockApollo from 'helpers/mock_apollo_helper';
import waitForPromises from 'helpers/wait_for_promises';
2023-03-17 16:20:25 +05:30
2023-07-09 08:55:56 +05:30
const GRAPHQL_ETAG_KEY = '/graphql/environments';
describe('~/environments/environment_details/index.vue', () => {
2023-03-17 16:20:25 +05:30
Vue.use(VueApollo);
let wrapper;
2023-07-09 08:55:56 +05:30
let routerMock;
2023-03-17 16:20:25 +05:30
2023-06-20 00:43:36 +05:30
const emptyEnvironmentToRollbackData = { id: '', name: '', lastDeployment: null, retryUrl: '' };
const environmentToRollbackMock = jest.fn();
const mockResolvers = {
Query: {
environmentToRollback: environmentToRollbackMock,
},
};
2023-03-17 16:20:25 +05:30
const defaultWrapperParameters = {
resolvedData: resolvedEnvironmentDetails,
2023-06-20 00:43:36 +05:30
environmentToRollbackData: emptyEnvironmentToRollbackData,
2023-03-17 16:20:25 +05:30
};
2023-06-20 00:43:36 +05:30
const createWrapper = ({
resolvedData,
environmentToRollbackData,
} = defaultWrapperParameters) => {
const mockApollo = createMockApollo(
[[getEnvironmentDetails, jest.fn().mockResolvedValue(resolvedData)]],
mockResolvers,
);
environmentToRollbackMock.mockReturnValue(
environmentToRollbackData || emptyEnvironmentToRollbackData,
);
const projectFullPath = 'gitlab-group/test-project';
2023-07-09 08:55:56 +05:30
routerMock = {
push: jest.fn(),
};
2023-03-17 16:20:25 +05:30
return mountExtended(EnvironmentsDetailPage, {
apolloProvider: mockApollo,
2023-06-20 00:43:36 +05:30
provide: {
projectPath: projectFullPath,
2023-07-09 08:55:56 +05:30
graphqlEtagKey: GRAPHQL_ETAG_KEY,
2023-06-20 00:43:36 +05:30
},
2023-03-17 16:20:25 +05:30
propsData: {
2023-06-20 00:43:36 +05:30
projectFullPath,
2023-03-17 16:20:25 +05:30
environmentName: 'test-environment-name',
},
2023-07-09 08:55:56 +05:30
mocks: {
$router: routerMock,
},
2023-03-17 16:20:25 +05:30
});
};
describe('when fetching data', () => {
it('should show a loading indicator', () => {
wrapper = createWrapper();
expect(wrapper.findComponent(GlLoadingIcon).exists()).toBe(true);
expect(wrapper.findComponent(GlTableLite).exists()).not.toBe(true);
});
});
describe('when data is fetched', () => {
describe('and there are deployments', () => {
beforeEach(async () => {
wrapper = createWrapper();
await waitForPromises();
});
2023-06-20 00:43:36 +05:30
it('should render a table when query is loaded', () => {
2023-03-17 16:20:25 +05:30
expect(wrapper.findComponent(GlLoadingIcon).exists()).not.toBe(true);
expect(wrapper.findComponent(GlTableLite).exists()).toBe(true);
});
2023-07-09 08:55:56 +05:30
describe('on rollback', () => {
it('sets the page back to default', () => {
wrapper.findComponent(ConfirmRollbackModal).vm.$emit('rollback');
expect(routerMock.push).toHaveBeenCalledWith({ query: {} });
});
});
2023-03-17 16:20:25 +05:30
});
describe('and there are no deployments', () => {
beforeEach(async () => {
wrapper = createWrapper({ resolvedData: emptyEnvironmentDetails });
await waitForPromises();
});
2023-06-20 00:43:36 +05:30
it('should render empty state component', () => {
2023-03-17 16:20:25 +05:30
expect(wrapper.findComponent(GlTableLite).exists()).toBe(false);
expect(wrapper.findComponent(EmptyState).exists()).toBe(true);
});
});
});
});