Skip to content

Commit

Permalink
Fix fetching quick actions (#10788)
Browse files Browse the repository at this point in the history
* #10765 properly construct quick actions request for the view below the modal

* #10765 add tests
  • Loading branch information
siemiatj committed Mar 10, 2021
1 parent f83d9f1 commit 8a9d378
Show file tree
Hide file tree
Showing 6 changed files with 755 additions and 14 deletions.
65 changes: 65 additions & 0 deletions frontend/src/__tests__/actions/Actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,69 @@ describe('QuickActions', () => {
done();
});
});

it(`fetch underlying view's actions when modal with included view is visible`, async (done) => {
const layoutResponse = gridLayoutFixtures.layout3_payments;
const rowResponse = gridRowFixtures.data4_payments;
const { windowId, viewId, result } = rowResponse;
const { includedViewId, includedWindowId, includedParentWindowId } = gridDataFixtures.data3_payments;
const id = getQuickActionsId({ windowId, viewId });
const tableId = getTableId({ windowId, viewId });
const selectedId = result[0].id;

const tableData_create = createTableData({
...layoutResponse,
...rowResponse,
keyProperty: 'id',
});

const initialStateData = createState({
viewHandler: {
includedView: {
viewId: includedViewId,
windowId: includedWindowId,
parentId: includedParentWindowId,
},
},
tables: {
length: 1,
[tableId]: {
...initialTableState,
...tableData_create,
selected: [selectedId],
},
},
actionsHandler: {
[id]: initialSingleActionsState,
},
});
const store = mockStore(initialStateData);

const payload1 = { id };
const payload2 = { id, actions: [] };

const expectedActions = [
{ type: ACTION_TYPES.FETCH_QUICK_ACTIONS, payload: payload1 },
{ type: ACTION_TYPES.FETCH_QUICK_ACTIONS_SUCCESS, payload: payload2 },
];

nock(config.API_URL)
.defaultReplyHeaders({ 'access-control-allow-origin': '*' })
.get(`/documentView/${windowId}/${viewId}/quickActions?selectedIds=${selectedId}`)
.reply(200, { actions: [] });

store
.dispatch(
fetchQuickActions({
windowId,
viewId,
})
).then((res) => {
expect(store.getActions()).toEqual(
expect.arrayContaining(expectedActions)
);

done();
});
});
});
30 changes: 16 additions & 14 deletions frontend/src/actions/Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,25 @@ export function fetchQuickActions({
);

actionPromises = [].concat(requests);
}
} else {
const tableId = getTableId({ windowId, viewId });
const table = getTable(state, tableId);

actionPromises = [
dispatch(
requestQuickActions({
windowId,
viewId,
selectedIds: table.selected,
viewProfileId,
})
),
];
return Promise.all(actionPromises);
}
}

const tableId = getTableId({ windowId, viewId });
const table = getTable(state, tableId);

actionPromises = [
dispatch(
requestQuickActions({
windowId,
viewId,
selectedIds: table.selected,
viewProfileId,
})
),
];

return Promise.all(actionPromises);
};
}
Expand Down
1 change: 1 addition & 0 deletions frontend/src/containers/DocumentList.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ class DocumentListContainer extends Component {
viewId,
selectedIds: table.selected,
viewProfileId,
isModal,
});
}

Expand Down
5 changes: 5 additions & 0 deletions frontend/test_setup/fixtures/grid/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,10 @@
],
"queryLimit": 5000,
"type": "540345"
},
"data3_payments": {
"includedViewId": "invoicesToAllocate-OY",
"includedWindowId": "invoicesToAllocate",
"includedParentWindowId": "540759"
}
}

0 comments on commit 8a9d378

Please sign in to comment.