2021-12-15 13:13:38 -05:00
|
|
|
import { GlModal } from '@gitlab/ui';
|
|
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
import Vue, { nextTick } from 'vue';
|
|
|
|
import VueApollo from 'vue-apollo';
|
|
|
|
import { s__, sprintf } from '~/locale';
|
|
|
|
import DeleteEnvironmentModal from '~/environments/components/delete_environment_modal.vue';
|
|
|
|
import createMockApollo from 'helpers/mock_apollo_helper';
|
2022-02-21 13:18:42 -05:00
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
|
|
|
import createFlash from '~/flash';
|
2021-12-15 13:13:38 -05:00
|
|
|
import { resolvedEnvironment } from './graphql/mock_data';
|
|
|
|
|
2022-02-21 13:18:42 -05:00
|
|
|
jest.mock('~/flash');
|
2021-12-15 13:13:38 -05:00
|
|
|
Vue.use(VueApollo);
|
|
|
|
|
|
|
|
describe('~/environments/components/delete_environment_modal.vue', () => {
|
|
|
|
let mockApollo;
|
|
|
|
let deleteResolver;
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const createComponent = ({ props = {}, apolloProvider } = {}) => {
|
|
|
|
wrapper = shallowMount(DeleteEnvironmentModal, {
|
|
|
|
propsData: {
|
|
|
|
graphql: true,
|
|
|
|
environment: resolvedEnvironment,
|
|
|
|
...props,
|
|
|
|
},
|
|
|
|
apolloProvider,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
deleteResolver = jest.fn();
|
|
|
|
mockApollo = createMockApollo([], {
|
|
|
|
Mutation: { deleteEnvironment: deleteResolver },
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should confirm the environment to delete', () => {
|
|
|
|
createComponent({ apolloProvider: mockApollo });
|
|
|
|
|
|
|
|
expect(wrapper.text()).toBe(
|
|
|
|
sprintf(
|
|
|
|
s__(
|
|
|
|
`Environments|Deleting the '%{environmentName}' environment cannot be undone. Do you want to delete it anyway?`,
|
|
|
|
),
|
|
|
|
{
|
|
|
|
environmentName: resolvedEnvironment.name,
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should send the delete mutation on primary', async () => {
|
|
|
|
createComponent({ apolloProvider: mockApollo });
|
|
|
|
|
|
|
|
wrapper.findComponent(GlModal).vm.$emit('primary');
|
|
|
|
|
|
|
|
await nextTick();
|
|
|
|
|
2022-02-21 13:18:42 -05:00
|
|
|
expect(createFlash).not.toHaveBeenCalled();
|
|
|
|
|
|
|
|
expect(deleteResolver).toHaveBeenCalledWith(
|
|
|
|
expect.anything(),
|
|
|
|
{ environment: resolvedEnvironment },
|
|
|
|
expect.anything(),
|
|
|
|
expect.anything(),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should flash a message on error', async () => {
|
|
|
|
createComponent({ apolloProvider: mockApollo });
|
|
|
|
|
|
|
|
deleteResolver.mockRejectedValue();
|
|
|
|
|
|
|
|
wrapper.findComponent(GlModal).vm.$emit('primary');
|
|
|
|
|
|
|
|
await waitForPromises();
|
|
|
|
|
|
|
|
expect(createFlash).toHaveBeenCalledWith(
|
|
|
|
expect.objectContaining({
|
|
|
|
message: s__(
|
|
|
|
'Environments|An error occurred while deleting the environment. Check if the environment stopped; if not, stop it and try again.',
|
|
|
|
),
|
|
|
|
captureError: true,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
2021-12-15 13:13:38 -05:00
|
|
|
expect(deleteResolver).toHaveBeenCalledWith(
|
|
|
|
expect.anything(),
|
|
|
|
{ environment: resolvedEnvironment },
|
|
|
|
expect.anything(),
|
|
|
|
expect.anything(),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|