Commit 9c51c8d5 authored by Thomas Randolph's avatar Thomas Randolph Committed by Phil Hughes

Show file sizes for image diffs

This changeset literally just passes a size value down to
the 2-Up viewer, which passes the sizes down to the
image-viewer.
parent 9f8071ad
...@@ -124,8 +124,10 @@ export default { ...@@ -124,8 +124,10 @@ export default {
:diff-viewer-mode="diffViewerMode" :diff-viewer-mode="diffViewerMode"
:new-path="diffFile.new_path" :new-path="diffFile.new_path"
:new-sha="diffFile.diff_refs.head_sha" :new-sha="diffFile.diff_refs.head_sha"
:new-size="diffFile.new_size"
:old-path="diffFile.old_path" :old-path="diffFile.old_path"
:old-sha="diffFile.diff_refs.base_sha" :old-sha="diffFile.diff_refs.base_sha"
:old-size="diffFile.old_size"
:file-hash="diffFileHash" :file-hash="diffFileHash"
:project-path="projectPath" :project-path="projectPath"
:a-mode="diffFile.a_mode" :a-mode="diffFile.a_mode"
......
...@@ -23,6 +23,11 @@ export default { ...@@ -23,6 +23,11 @@ export default {
type: String, type: String,
required: true, required: true,
}, },
newSize: {
type: Number,
required: false,
default: 0,
},
oldPath: { oldPath: {
type: String, type: String,
required: true, required: true,
...@@ -31,6 +36,11 @@ export default { ...@@ -31,6 +36,11 @@ export default {
type: String, type: String,
required: true, required: true,
}, },
oldSize: {
type: Number,
required: false,
default: 0,
},
projectPath: { projectPath: {
type: String, type: String,
required: false, required: false,
...@@ -85,6 +95,8 @@ export default { ...@@ -85,6 +95,8 @@ export default {
:diff-mode="diffMode" :diff-mode="diffMode"
:new-path="fullNewPath" :new-path="fullNewPath"
:old-path="fullOldPath" :old-path="fullOldPath"
:old-size="oldSize"
:new-size="newSize"
:project-path="projectPath" :project-path="projectPath"
:a-mode="aMode" :a-mode="aMode"
:b-mode="bMode" :b-mode="bMode"
......
...@@ -14,6 +14,16 @@ export default { ...@@ -14,6 +14,16 @@ export default {
type: String, type: String,
required: true, required: true,
}, },
newSize: {
type: Number,
required: false,
default: 0,
},
oldSize: {
type: Number,
required: false,
default: 0,
},
}, },
}; };
</script> </script>
...@@ -22,12 +32,14 @@ export default { ...@@ -22,12 +32,14 @@ export default {
<div class="two-up view d-flex"> <div class="two-up view d-flex">
<image-viewer <image-viewer
:path="oldPath" :path="oldPath"
:file-size="oldSize"
:render-info="true" :render-info="true"
inner-css-classes="frame deleted" inner-css-classes="frame deleted"
class="wrap w-50" class="wrap w-50"
/> />
<image-viewer <image-viewer
:path="newPath" :path="newPath"
:file-size="newSize"
:render-info="true" :render-info="true"
:inner-css-classes="['frame', 'added']" :inner-css-classes="['frame', 'added']"
class="wrap w-50" class="wrap w-50"
......
...@@ -22,6 +22,16 @@ export default { ...@@ -22,6 +22,16 @@ export default {
type: String, type: String,
required: true, required: true,
}, },
newSize: {
type: Number,
required: false,
default: 0,
},
oldSize: {
type: Number,
required: false,
default: 0,
},
}, },
data() { data() {
return { return {
......
---
title: Re-add missing file sizes in 2-Up diff file viewer
merge_request: 19710
author:
type: fixed
import { shallowMount } from '@vue/test-utils';
import ImageViewer from '~/vue_shared/components/content_viewer/viewers/image_viewer.vue';
import { GREEN_BOX_IMAGE_URL } from 'spec/test_constants';
describe('Image Viewer', () => {
const requiredProps = {
path: GREEN_BOX_IMAGE_URL,
renderInfo: true,
};
let wrapper;
let imageInfo;
function createElement({ props, includeRequired = true } = {}) {
const data = includeRequired ? { ...requiredProps, ...props } : { ...props };
wrapper = shallowMount(ImageViewer, {
propsData: data,
});
imageInfo = wrapper.find('.image-info');
}
describe('file sizes', () => {
it('should show the humanized file size when `renderInfo` is true and there is size info', () => {
createElement({ props: { fileSize: 1024 } });
expect(imageInfo.text()).toContain('1.00 KiB');
});
it('should not show the humanized file size when `renderInfo` is true and there is no size', () => {
const FILESIZE_RE = /\d+(\.\d+)?\s*([KMGTP]i)*B/;
createElement({ props: { fileSize: 0 } });
// It shouldn't show any filesize info
expect(imageInfo.text()).not.toMatch(FILESIZE_RE);
});
it('should not show any image information when `renderInfo` is false', () => {
createElement({ props: { renderInfo: false } });
expect(imageInfo.exists()).toBe(false);
});
});
});
import Vue from 'vue'; import Vue from 'vue';
import diffViewer from '~/vue_shared/components/diff_viewer/diff_viewer.vue'; import diffViewer from '~/vue_shared/components/diff_viewer/diff_viewer.vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper'; import mountComponent from 'spec/helpers/vue_mount_component_helper';
import { GREEN_BOX_IMAGE_URL, RED_BOX_IMAGE_URL } from 'spec/test_constants'; import { GREEN_BOX_IMAGE_URL, RED_BOX_IMAGE_URL } from 'spec/test_constants';
describe('DiffViewer', () => { describe('DiffViewer', () => {
const requiredProps = {
diffMode: 'replaced',
diffViewerMode: 'image',
newPath: GREEN_BOX_IMAGE_URL,
newSha: 'ABC',
oldPath: RED_BOX_IMAGE_URL,
oldSha: 'DEF',
};
let vm; let vm;
function createComponent(props) { function createComponent(props) {
const DiffViewer = Vue.extend(diffViewer); const DiffViewer = Vue.extend(diffViewer);
vm = mountComponent(DiffViewer, props); vm = mountComponent(DiffViewer, props);
} }
...@@ -20,15 +30,11 @@ describe('DiffViewer', () => { ...@@ -20,15 +30,11 @@ describe('DiffViewer', () => {
relative_url_root: '', relative_url_root: '',
}; };
createComponent({ createComponent(
diffMode: 'replaced', Object.assign({}, requiredProps, {
diffViewerMode: 'image', projectPath: '',
newPath: GREEN_BOX_IMAGE_URL, }),
newSha: 'ABC', );
oldPath: RED_BOX_IMAGE_URL,
oldSha: 'DEF',
projectPath: '',
});
setTimeout(() => { setTimeout(() => {
expect(vm.$el.querySelector('.deleted img').getAttribute('src')).toBe( expect(vm.$el.querySelector('.deleted img').getAttribute('src')).toBe(
...@@ -44,14 +50,13 @@ describe('DiffViewer', () => { ...@@ -44,14 +50,13 @@ describe('DiffViewer', () => {
}); });
it('renders fallback download diff display', done => { it('renders fallback download diff display', done => {
createComponent({ createComponent(
diffMode: 'replaced', Object.assign({}, requiredProps, {
diffViewerMode: 'added', diffViewerMode: 'added',
newPath: 'test.abc', newPath: 'test.abc',
newSha: 'ABC', oldPath: 'testold.abc',
oldPath: 'testold.abc', }),
oldSha: 'DEF', );
});
setTimeout(() => { setTimeout(() => {
expect(vm.$el.querySelector('.deleted .file-info').textContent.trim()).toContain( expect(vm.$el.querySelector('.deleted .file-info').textContent.trim()).toContain(
...@@ -72,29 +77,28 @@ describe('DiffViewer', () => { ...@@ -72,29 +77,28 @@ describe('DiffViewer', () => {
}); });
it('renders renamed component', () => { it('renders renamed component', () => {
createComponent({ createComponent(
diffMode: 'renamed', Object.assign({}, requiredProps, {
diffViewerMode: 'renamed', diffMode: 'renamed',
newPath: 'test.abc', diffViewerMode: 'renamed',
newSha: 'ABC', newPath: 'test.abc',
oldPath: 'testold.abc', oldPath: 'testold.abc',
oldSha: 'DEF', }),
}); );
expect(vm.$el.textContent).toContain('File moved'); expect(vm.$el.textContent).toContain('File moved');
}); });
it('renders mode changed component', () => { it('renders mode changed component', () => {
createComponent({ createComponent(
diffMode: 'mode_changed', Object.assign({}, requiredProps, {
diffViewerMode: 'image', diffMode: 'mode_changed',
newPath: 'test.abc', newPath: 'test.abc',
newSha: 'ABC', oldPath: 'testold.abc',
oldPath: 'testold.abc', aMode: '123',
oldSha: 'DEF', bMode: '321',
aMode: '123', }),
bMode: '321', );
});
expect(vm.$el.textContent).toContain('File mode changed from 123 to 321'); expect(vm.$el.textContent).toContain('File mode changed from 123 to 321');
}); });
......
...@@ -4,6 +4,11 @@ import mountComponent from 'spec/helpers/vue_mount_component_helper'; ...@@ -4,6 +4,11 @@ import mountComponent from 'spec/helpers/vue_mount_component_helper';
import { GREEN_BOX_IMAGE_URL, RED_BOX_IMAGE_URL } from 'spec/test_constants'; import { GREEN_BOX_IMAGE_URL, RED_BOX_IMAGE_URL } from 'spec/test_constants';
describe('ImageDiffViewer', () => { describe('ImageDiffViewer', () => {
const requiredProps = {
diffMode: 'replaced',
newPath: GREEN_BOX_IMAGE_URL,
oldPath: RED_BOX_IMAGE_URL,
};
let vm; let vm;
function createComponent(props) { function createComponent(props) {
...@@ -45,11 +50,7 @@ describe('ImageDiffViewer', () => { ...@@ -45,11 +50,7 @@ describe('ImageDiffViewer', () => {
}); });
it('renders image diff for replaced', done => { it('renders image diff for replaced', done => {
createComponent({ createComponent(requiredProps);
diffMode: 'replaced',
newPath: GREEN_BOX_IMAGE_URL,
oldPath: RED_BOX_IMAGE_URL,
});
setTimeout(() => { setTimeout(() => {
expect(vm.$el.querySelector('.added img').getAttribute('src')).toBe(GREEN_BOX_IMAGE_URL); expect(vm.$el.querySelector('.added img').getAttribute('src')).toBe(GREEN_BOX_IMAGE_URL);
...@@ -70,11 +71,12 @@ describe('ImageDiffViewer', () => { ...@@ -70,11 +71,12 @@ describe('ImageDiffViewer', () => {
}); });
it('renders image diff for new', done => { it('renders image diff for new', done => {
createComponent({ createComponent(
diffMode: 'new', Object.assign({}, requiredProps, {
newPath: GREEN_BOX_IMAGE_URL, diffMode: 'new',
oldPath: '', oldPath: '',
}); }),
);
setTimeout(() => { setTimeout(() => {
expect(vm.$el.querySelector('.added img').getAttribute('src')).toBe(GREEN_BOX_IMAGE_URL); expect(vm.$el.querySelector('.added img').getAttribute('src')).toBe(GREEN_BOX_IMAGE_URL);
...@@ -84,11 +86,12 @@ describe('ImageDiffViewer', () => { ...@@ -84,11 +86,12 @@ describe('ImageDiffViewer', () => {
}); });
it('renders image diff for deleted', done => { it('renders image diff for deleted', done => {
createComponent({ createComponent(
diffMode: 'deleted', Object.assign({}, requiredProps, {
newPath: '', diffMode: 'deleted',
oldPath: RED_BOX_IMAGE_URL, newPath: '',
}); }),
);
setTimeout(() => { setTimeout(() => {
expect(vm.$el.querySelector('.deleted img').getAttribute('src')).toBe(RED_BOX_IMAGE_URL); expect(vm.$el.querySelector('.deleted img').getAttribute('src')).toBe(RED_BOX_IMAGE_URL);
...@@ -119,11 +122,7 @@ describe('ImageDiffViewer', () => { ...@@ -119,11 +122,7 @@ describe('ImageDiffViewer', () => {
describe('swipeMode', () => { describe('swipeMode', () => {
beforeEach(done => { beforeEach(done => {
createComponent({ createComponent(requiredProps);
diffMode: 'replaced',
newPath: GREEN_BOX_IMAGE_URL,
oldPath: RED_BOX_IMAGE_URL,
});
setTimeout(() => { setTimeout(() => {
done(); done();
...@@ -142,11 +141,7 @@ describe('ImageDiffViewer', () => { ...@@ -142,11 +141,7 @@ describe('ImageDiffViewer', () => {
describe('onionSkin', () => { describe('onionSkin', () => {
beforeEach(done => { beforeEach(done => {
createComponent({ createComponent(requiredProps);
diffMode: 'replaced',
newPath: GREEN_BOX_IMAGE_URL,
oldPath: RED_BOX_IMAGE_URL,
});
setTimeout(() => { setTimeout(() => {
done(); done();
......
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