2021-03-11 19:13:27 +05:30
|
|
|
import { GlButton } from '@gitlab/ui';
|
2022-04-04 11:22:00 +05:30
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2023-05-27 22:25:52 +05:30
|
|
|
import Vue from 'vue';
|
|
|
|
import VueApollo from 'vue-apollo';
|
2020-05-24 23:13:21 +05:30
|
|
|
import VueRouter from 'vue-router';
|
2023-05-27 22:25:52 +05:30
|
|
|
import createMockApollo from 'helpers/mock_apollo_helper';
|
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
|
|
|
import permissionsQuery from 'shared_queries/design_management/design_permissions.query.graphql';
|
2020-05-24 23:13:21 +05:30
|
|
|
import DeleteButton from '~/design_management/components/delete_button.vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import Toolbar from '~/design_management/components/toolbar/index.vue';
|
2020-05-24 23:13:21 +05:30
|
|
|
import { DESIGNS_ROUTE_NAME } from '~/design_management/router/constants';
|
2023-05-27 22:25:52 +05:30
|
|
|
import { getPermissionsQueryResponse } from '../../mock_data/apollo_mock';
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
Vue.use(VueRouter);
|
2023-05-27 22:25:52 +05:30
|
|
|
Vue.use(VueApollo);
|
2020-05-24 23:13:21 +05:30
|
|
|
const router = new VueRouter();
|
|
|
|
|
|
|
|
const RouterLinkStub = {
|
|
|
|
props: {
|
|
|
|
to: {
|
|
|
|
type: Object,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
render(createElement) {
|
|
|
|
return createElement('a', {}, this.$slots.default);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('Design management toolbar component', () => {
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
function createComponent(isLoading = false, createDesign = true, props) {
|
|
|
|
const updatedAt = new Date();
|
|
|
|
updatedAt.setHours(updatedAt.getHours() - 1);
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
const mockApollo = createMockApollo([
|
|
|
|
[permissionsQuery, jest.fn().mockResolvedValue(getPermissionsQueryResponse(createDesign))],
|
|
|
|
]);
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
wrapper = shallowMount(Toolbar, {
|
2023-05-27 22:25:52 +05:30
|
|
|
apolloProvider: mockApollo,
|
2020-05-24 23:13:21 +05:30
|
|
|
router,
|
|
|
|
propsData: {
|
|
|
|
id: '1',
|
|
|
|
isLatestVersion: true,
|
|
|
|
isLoading,
|
|
|
|
isDeleting: false,
|
|
|
|
filename: 'test.jpg',
|
|
|
|
updatedAt: updatedAt.toString(),
|
|
|
|
updatedBy: {
|
|
|
|
name: 'Test Name',
|
|
|
|
},
|
|
|
|
image: '/-/designs/306/7f747adcd4693afadbe968d7ba7d983349b9012d',
|
|
|
|
...props,
|
|
|
|
},
|
|
|
|
stubs: {
|
|
|
|
'router-link': RouterLinkStub,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('renders design and updated data', async () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
createComponent();
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
await waitForPromises();
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
expect(wrapper.element).toMatchSnapshot();
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('links back to designs list', async () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
createComponent();
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
await waitForPromises();
|
2022-04-04 11:22:00 +05:30
|
|
|
const link = wrapper.find('a');
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
expect(link.props('to')).toEqual({
|
|
|
|
name: DESIGNS_ROUTE_NAME,
|
|
|
|
query: {
|
|
|
|
version: undefined,
|
|
|
|
},
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('renders delete button on latest designs version with logged in user', async () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
createComponent();
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
await waitForPromises();
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(wrapper.findComponent(DeleteButton).exists()).toBe(true);
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('does not render delete button on non-latest version', async () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
createComponent(false, true, { isLatestVersion: false });
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
await waitForPromises();
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(wrapper.findComponent(DeleteButton).exists()).toBe(false);
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('does not render delete button when user is not logged in', async () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
createComponent(false, false);
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
await waitForPromises();
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(wrapper.findComponent(DeleteButton).exists()).toBe(false);
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
it('emits `delete` event on deleteButton `delete-selected-designs` event', async () => {
|
2020-05-24 23:13:21 +05:30
|
|
|
createComponent();
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
await waitForPromises();
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
wrapper.findComponent(DeleteButton).vm.$emit('delete-selected-designs');
|
2022-10-11 01:57:18 +05:30
|
|
|
expect(wrapper.emitted().delete).toHaveLength(1);
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
it('renders download button with correct link', async () => {
|
2021-03-08 18:12:59 +05:30
|
|
|
createComponent();
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
await waitForPromises();
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
expect(wrapper.findComponent(GlButton).attributes('href')).toBe(
|
2020-05-24 23:13:21 +05:30
|
|
|
'/-/designs/306/7f747adcd4693afadbe968d7ba7d983349b9012d',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|