Commit 82d57c8d authored by Kushal Pandya's avatar Kushal Pandya

Merge branch '328641-insert-images/image-node-view-wrapper' into 'master'

Image node view wrapper component

See merge request gitlab-org/gitlab!65765
parents 4df589b8 59e27567
<script>
import { GlLoadingIcon } from '@gitlab/ui';
import { NodeViewWrapper } from '@tiptap/vue-2';
export default {
name: 'ImageWrapper',
components: {
NodeViewWrapper,
GlLoadingIcon,
},
props: {
node: {
type: Object,
required: true,
},
},
};
</script>
<template>
<node-view-wrapper class="gl-display-inline-block">
<span class="gl-relative">
<img
data-testid="image"
class="gl-max-w-full gl-h-auto"
:class="{ 'gl-opacity-5': node.attrs.uploading }"
:src="node.attrs.src"
/>
<gl-loading-icon v-if="node.attrs.uploading" class="gl-absolute gl-left-50p gl-top-half" />
</span>
</node-view-wrapper>
</template>
import { GlLoadingIcon } from '@gitlab/ui';
import { NodeViewWrapper } from '@tiptap/vue-2';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import ImageWrapper from '~/content_editor/components/wrappers/image.vue';
describe('content/components/wrappers/image', () => {
let wrapper;
const createWrapper = async (nodeAttrs = {}) => {
wrapper = shallowMountExtended(ImageWrapper, {
propsData: {
node: {
attrs: nodeAttrs,
},
},
});
};
const findImage = () => wrapper.findByTestId('image');
const findLoadingIcon = () => wrapper.findComponent(GlLoadingIcon);
afterEach(() => {
wrapper.destroy();
});
it('renders a node-view-wrapper with display-inline-block class', () => {
createWrapper();
expect(wrapper.findComponent(NodeViewWrapper).classes()).toContain('gl-display-inline-block');
});
it('renders an image that displays the node src', () => {
const src = 'foobar.png';
createWrapper({ src });
expect(findImage().attributes().src).toBe(src);
});
describe('when uploading', () => {
beforeEach(() => {
createWrapper({ uploading: true });
});
it('renders a gl-loading-icon component', () => {
expect(findLoadingIcon().exists()).toBe(true);
});
it('adds gl-opacity-5 class selector to image', () => {
expect(findImage().classes()).toContain('gl-opacity-5');
});
});
describe('when not uploading', () => {
beforeEach(() => {
createWrapper({ uploading: false });
});
it('does not render a gl-loading-icon component', () => {
expect(findLoadingIcon().exists()).toBe(false);
});
it('does not add gl-opacity-5 class selector to image', () => {
expect(findImage().classes()).not.toContain('gl-opacity-5');
});
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment