Skip to content

Commit

Permalink
fix: object-selections
Browse files Browse the repository at this point in the history
don't clear an empty range select
disable clear and confirm button when the selection is cleared
  • Loading branch information
T-Wizard committed Nov 27, 2020
1 parent 5ec6a8a commit a2982de
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 15 deletions.
49 changes: 38 additions & 11 deletions apis/nucleus/src/hooks/__tests__/use-object-selections.spec.jsx
Expand Up @@ -153,7 +153,7 @@ describe('useObjectSelections', () => {
expect(res).to.equal(true);
});

it('should clear on non successful select', async () => {
it('should return false on non successful select', async () => {
await render();

appSel.isModal.returns(true);
Expand All @@ -162,6 +162,35 @@ describe('useObjectSelections', () => {
expect(res).to.equal(false);
});

it('should not emit cleared on non successful select', async () => {
await render();
const cleared = sandbox.stub();
objectSel.on('cleared', cleared);

appSel.isModal.returns(true);
object.select.returns(false);
await objectSel.select({ method: 'select', params: [] });
expect(cleared).to.not.be.called;
});

it('should call resetMadeSelections on non successful select', async () => {
await render();

appSel.isModal.returns(true);
object.select.returns(false);
await objectSel.select({ method: 'select', params: [] });
expect(object.resetMadeSelections).to.have.been.calledWithExactly();
});

it('should not be possible to clear after select has be called with resetMadeSelections', async () => {
await render();
appSel.isModal.returns(true);
object.select.returns(true);
await objectSel.select({ method: 'resetMadeSelections', params: [] });

expect(objectSel.canClear()).to.equal(false);
});

it('can clear', async () => {
await render();
layout = {
Expand All @@ -174,12 +203,11 @@ describe('useObjectSelections', () => {
objectSel.setLayout(layout);
expect(ref.current.result[0].canClear()).to.equal(true);

layout = {
qSelectionInfo: {
qMadeSelections: true,
},
};
layout = {};
objectSel.setLayout(layout);
appSel.isModal.returns(true);
object.select.returns(true);
await objectSel.select({ method: 'select', params: [] });
expect(ref.current.result[0].canClear()).to.equal(true);
});

Expand All @@ -195,12 +223,11 @@ describe('useObjectSelections', () => {
objectSel.setLayout(layout);
expect(ref.current.result[0].canConfirm()).to.equal(true);

layout = {
qSelectionInfo: {
qMadeSelections: true,
},
};
layout = {};
objectSel.setLayout(layout);
appSel.isModal.returns(true);
object.select.returns(true);
await objectSel.select({ method: 'select', params: [] });
expect(ref.current.result[0].canConfirm()).to.equal(true);
});

Expand Down
8 changes: 4 additions & 4 deletions apis/nucleus/src/hooks/useObjectSelections.js
Expand Up @@ -90,11 +90,11 @@ function createObjectSelections({ appSelections, appModal, model }) {
}
await b;
const qSuccess = await model[s.method](...s.params);
hasSelected = s.method !== 'resetMadeSelections';
if (!qSuccess) {
this.clear();
model.resetMadeSelections();
return false;
}
hasSelected = true;
return true;
},
/**
Expand All @@ -104,7 +104,7 @@ function createObjectSelections({ appSelections, appModal, model }) {
if (layout && layout.qListObject && layout.qListObject.qDimensionInfo) {
return !layout.qListObject.qDimensionInfo.qLocked;
}
return hasSelected || (layout && layout.qSelectionInfo.qMadeSelections);
return hasSelected;
},
/**
* @returns {boolean}
Expand All @@ -113,7 +113,7 @@ function createObjectSelections({ appSelections, appModal, model }) {
if (layout && layout.qListObject && layout.qListObject.qDimensionInfo) {
return !layout.qListObject.qDimensionInfo.qLocked;
}
return hasSelected || (layout && layout.qSelectionInfo.qMadeSelections);
return hasSelected;
},
/**
* @returns {boolean}
Expand Down

0 comments on commit a2982de

Please sign in to comment.