Commit b5cbec88 authored by Tom Quirk's avatar Tom Quirk

Improve design presentation specs for click drag

- test onPresentationMousedown in place of is DesignOverflowing
- minor cleanup
parent 1f435d6b
...@@ -39,13 +39,14 @@ export default { ...@@ -39,13 +39,14 @@ export default {
}, },
computed: { computed: {
overlayStyle() { overlayStyle() {
const baseStyle = { const cursor = this.disableCommenting ? 'unset' : undefined;
return {
cursor,
width: `${this.dimensions.width}px`, width: `${this.dimensions.width}px`,
height: `${this.dimensions.height}px`, height: `${this.dimensions.height}px`,
...this.position, ...this.position,
}; };
return this.disableCommenting ? Object.assign(baseStyle, { cursor: 'unset' }) : baseStyle;
}, },
isMovingCurrentComment() { isMovingCurrentComment() {
return Boolean(this.movingNoteStartPosition && !this.movingNoteStartPosition.noteId); return Boolean(this.movingNoteStartPosition && !this.movingNoteStartPosition.noteId);
......
...@@ -47,7 +47,6 @@ export default { ...@@ -47,7 +47,6 @@ export default {
}, },
initialLoad: true, initialLoad: true,
lastDragPosition: null, lastDragPosition: null,
isDraggingDesign: false,
}; };
}, },
computed: { computed: {
...@@ -58,11 +57,12 @@ export default { ...@@ -58,11 +57,12 @@ export default {
return (this.isAnnotating && this.currentAnnotationPosition) || null; return (this.isAnnotating && this.currentAnnotationPosition) || null;
}, },
presentationStyle() { presentationStyle() {
return this.isDraggingDesign return {
? { cursor: this.isDraggingDesign ? 'grabbing' : undefined,
cursor: 'grabbing', };
} },
: undefined; isDraggingDesign() {
return Boolean(this.lastDragPosition);
}, },
}, },
beforeDestroy() { beforeDestroy() {
...@@ -225,7 +225,6 @@ export default { ...@@ -225,7 +225,6 @@ export default {
}, },
onPresentationMousemove({ clientX, clientY }) { onPresentationMousemove({ clientX, clientY }) {
if (!this.lastDragPosition) return; if (!this.lastDragPosition) return;
this.isDraggingDesign = true;
const { presentationViewport } = this.$refs; const { presentationViewport } = this.$refs;
if (!presentationViewport) return; if (!presentationViewport) return;
...@@ -242,7 +241,6 @@ export default { ...@@ -242,7 +241,6 @@ export default {
}, },
onPresentationMouseup() { onPresentationMouseup() {
this.lastDragPosition = null; this.lastDragPosition = null;
this.isDraggingDesign = false;
}, },
isDesignOverflowing() { isDesignOverflowing() {
const { presentationContainer } = this.$refs; const { presentationContainer } = this.$refs;
......
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Design management design presentation component currentCommentForm currentCommentForm is equal to current annotation position when isAnnotating is true 1`] = ` exports[`Design management design presentation component currentCommentForm is equal to current annotation position when isAnnotating is true 1`] = `
<div <div
class="h-100 w-100 p-3 overflow-auto position-relative" class="h-100 w-100 p-3 overflow-auto position-relative"
> >
...@@ -23,7 +23,7 @@ exports[`Design management design presentation component currentCommentForm curr ...@@ -23,7 +23,7 @@ exports[`Design management design presentation component currentCommentForm curr
</div> </div>
`; `;
exports[`Design management design presentation component currentCommentForm currentCommentForm is null when isAnnotating is false 1`] = ` exports[`Design management design presentation component currentCommentForm is null when isAnnotating is false 1`] = `
<div <div
class="h-100 w-100 p-3 overflow-auto position-relative" class="h-100 w-100 p-3 overflow-auto position-relative"
> >
...@@ -45,7 +45,7 @@ exports[`Design management design presentation component currentCommentForm curr ...@@ -45,7 +45,7 @@ exports[`Design management design presentation component currentCommentForm curr
</div> </div>
`; `;
exports[`Design management design presentation component currentCommentForm currentCommentForm is null when isAnnotating is true but annotation position is falsey 1`] = ` exports[`Design management design presentation component currentCommentForm is null when isAnnotating is true but annotation position is falsey 1`] = `
<div <div
class="h-100 w-100 p-3 overflow-auto position-relative" class="h-100 w-100 p-3 overflow-auto position-relative"
> >
......
...@@ -128,7 +128,7 @@ describe('Design management design presentation component', () => { ...@@ -128,7 +128,7 @@ describe('Design management design presentation component', () => {
}); });
describe('currentCommentForm', () => { describe('currentCommentForm', () => {
it('currentCommentForm is null when isAnnotating is false', () => { it('is null when isAnnotating is false', () => {
createComponent( createComponent(
{ {
image: 'test.jpg', image: 'test.jpg',
...@@ -143,7 +143,7 @@ describe('Design management design presentation component', () => { ...@@ -143,7 +143,7 @@ describe('Design management design presentation component', () => {
}); });
}); });
it('currentCommentForm is null when isAnnotating is true but annotation position is falsey', () => { it('is null when isAnnotating is true but annotation position is falsey', () => {
createComponent( createComponent(
{ {
image: 'test.jpg', image: 'test.jpg',
...@@ -159,7 +159,7 @@ describe('Design management design presentation component', () => { ...@@ -159,7 +159,7 @@ describe('Design management design presentation component', () => {
}); });
}); });
it('currentCommentForm is equal to current annotation position when isAnnotating is true', () => { it('is equal to current annotation position when isAnnotating is true', () => {
createComponent( createComponent(
{ {
image: 'test.jpg', image: 'test.jpg',
...@@ -176,6 +176,7 @@ describe('Design management design presentation component', () => { ...@@ -176,6 +176,7 @@ describe('Design management design presentation component', () => {
}, },
}, },
); );
return wrapper.vm.$nextTick().then(() => { return wrapper.vm.$nextTick().then(() => {
expect(wrapper.vm.currentCommentForm).toEqual({ expect(wrapper.vm.currentCommentForm).toEqual({
x: 1, x: 1,
...@@ -384,21 +385,43 @@ describe('Design management design presentation component', () => { ...@@ -384,21 +385,43 @@ describe('Design management design presentation component', () => {
}); });
}); });
describe('isDesignOverflowing', () => { describe('onPresentationMousedown', () => {
it.each` it.each`
scenario | width | height | isOverflowing scenario | width | height
${'width overflows'} | ${101} | ${100} | ${true} ${'width overflows'} | ${101} | ${100}
${'height overflows'} | ${100} | ${101} | ${true} ${'height overflows'} | ${100} | ${101}
${'width and height overflows'} | ${200} | ${200} | ${true} ${'width and height overflows'} | ${200} | ${200}
${'is smaller than container'} | ${100} | ${100} | ${false} `('sets lastDragPosition when design $scenario', ({ width, height }) => {
`('returns $isOverflowing when design $scenario', ({ width, height, isOverflowing }) => {
createComponent(); createComponent();
mockRefDimensions( mockRefDimensions(
wrapper.vm.$refs.presentationContainer, wrapper.vm.$refs.presentationContainer,
{ width: 100, height: 100 }, { width: 100, height: 100 },
{ width, height }, { width, height },
); );
expect(wrapper.vm.isDesignOverflowing()).toBe(isOverflowing);
const newLastDragPosition = { x: 2, y: 2 };
wrapper.vm.onPresentationMousedown({
clientX: newLastDragPosition.x,
clientY: newLastDragPosition.y,
});
expect(wrapper.vm.lastDragPosition).toStrictEqual(newLastDragPosition);
});
it('does not set lastDragPosition if design does not overflow', () => {
const lastDragPosition = { x: 1, y: 1 };
createComponent({}, { lastDragPosition });
mockRefDimensions(
wrapper.vm.$refs.presentationContainer,
{ width: 100, height: 100 },
{ width: 50, height: 50 },
);
wrapper.vm.onPresentationMousedown({ clientX: 2, clientY: 2 });
// check lastDragPosition is unchanged
expect(wrapper.vm.lastDragPosition).toStrictEqual(lastDragPosition);
}); });
}); });
...@@ -416,7 +439,7 @@ describe('Design management design presentation component', () => { ...@@ -416,7 +439,7 @@ describe('Design management design presentation component', () => {
mockOverlayData, mockOverlayData,
); );
mockRefDimensions( mockRefDimensions(
wrapper.vm.$refs.presentationViewport, wrapper.vm.$refs.presentationContainer,
{ width: 10, height: 10 }, { width: 10, height: 10 },
{ width: 20, height: 20 }, { width: 20, height: 20 },
0, 0,
...@@ -424,7 +447,6 @@ describe('Design management design presentation component', () => { ...@@ -424,7 +447,6 @@ describe('Design management design presentation component', () => {
); );
wrapper.element.scrollTo = jest.fn(); wrapper.element.scrollTo = jest.fn();
wrapper.vm.isDesignOverflowing = jest.fn().mockReturnValue(true);
return clickDragExplore( return clickDragExplore(
{ clientX: 0, clientY: 0 }, { clientX: 0, clientY: 0 },
{ clientX: 10, clientY: 10 }, { clientX: 10, clientY: 10 },
......
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