Skip to content

Commit

Permalink
Refactored code for link/unlink and fixed test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
KenyShah24 committed Aug 28, 2024
1 parent a41f409 commit f20a706
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 45 deletions.
25 changes: 24 additions & 1 deletion src/components/record/related-table-actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -513,10 +513,33 @@ const RelatedTableActions = ({
const deleteTuples = () => {
leafReference
.deleteBatchAssociationTuples(relatedModel.recordsetProps.parentTuple, selectedRows)
.then(()=>{
.then((response: any)=>{
setShowPureBinarySpinner(false);
if(response.failedTupleData.length>0){
response.clickOkToDismiss = true;

// TODO: - improve partial success and use TRS to check delete rights before giving a checkbox
// - some errors could have been because of row level security
dispatchError({
error: response,
isDismissible: true,
closeBtnCallback: () => {
// ask recordset to update the modal
if (!!containerRef.current) {
// NOTE: This feels very against React but the complexity of our flow control provider seems to warrant doing this
fireCustomEvent(CUSTOM_EVENTS.FORCE_UPDATE_RECORDSET, containerRef.current, {
cause: LogReloadCauses.ENTITY_BATCH_UNLINK,
pageStates: { updateResult: true, updateCount: true, updateFacets: true },
response: response,
});
}
},
});
}
else{
setUnlinkPureBinaryModalProps(null);
updateRecordPage(true, LogReloadCauses.RELATED_BATCH_UNLINK);
}
})
.catch((err: Error)=>{
setShowPureBinarySpinner(false);
Expand Down
32 changes: 8 additions & 24 deletions test/e2e/specs/all-features/record/related-table.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import moment from 'moment';
import { test, expect, Page } from '@playwright/test';
import ModalLocators from '@isrd-isi-edu/chaise/test/e2e/locators/modal';
import RecordsetLocators from '@isrd-isi-edu/chaise/test/e2e/locators/recordset';
import RecordLocators from '@isrd-isi-edu/chaise/test/e2e/locators/record';
import RecordeditLocators, { RecordeditInputType } from '@isrd-isi-edu/chaise/test/e2e/locators/recordedit';
import RecordsetLocators from '@isrd-isi-edu/chaise/test/e2e/locators/recordset';
import { getCatalogID, getEntityRow, importACLs } from '@isrd-isi-edu/chaise/test/e2e/utils/catalog-utils';
import { APP_NAMES, RESTRICTED_USER_STORAGE_STATE } from '@isrd-isi-edu/chaise/test/e2e/utils/constants';
import { testTooltip } from '@isrd-isi-edu/chaise/test/e2e/utils/page-utils';
import {
testAddAssociationTable, testAddRelatedTable, testBatchUnlinkAssociationTable,
testRelatedTablePresentation, testShareCiteModal
} from '@isrd-isi-edu/chaise/test/e2e/utils/record-utils';
import { APP_NAMES, RESTRICTED_USER_STORAGE_STATE } from '@isrd-isi-edu/chaise/test/e2e/utils/constants';
import { testRecordsetTableRowValues } from '@isrd-isi-edu/chaise/test/e2e/utils/recordset-utils';
import { testTooltip } from '@isrd-isi-edu/chaise/test/e2e/utils/page-utils';
import { expect, Page, test } from '@playwright/test';
import moment from 'moment';
import { testRecordsetTableRowValues } from '../../../utils/recordset-utils';

const testParams = {
schemaName: 'product-unordered-related-tables-links',
Expand Down Expand Up @@ -403,6 +403,7 @@ test.describe('Related tables', () => {

// click on submit
await ModalLocators.getSubmitButton(rsModal).click();
await page.pause();

// confirm the unlink
const confirmModal = ModalLocators.getConfirmDeleteModal(page);
Expand All @@ -414,23 +415,6 @@ test.describe('Related tables', () => {
await okBtn.click();
await expect.soft(confirmModal).not.toBeAttached();

// make sure summary modal shows up
const summaryModal = ModalLocators.getErrorModal(page);
await expect.soft(summaryModal).toBeVisible();
await expect.soft(ModalLocators.getModalTitle(summaryModal)).toHaveText('Batch Unlink Summary');
await expect.soft(ModalLocators.getModalText(summaryModal)).toHaveText(params.successPostDeleteMessage);

// close the summary modal
await ModalLocators.getCloseBtn(summaryModal).click();
await expect.soft(summaryModal).not.toBeAttached();

// make sure the recordset modal rows update
await expect.soft(RecordsetLocators.getRows(rsModal)).toHaveCount(params.rowValuesAfter.length);

// close the recordset modal
await ModalLocators.getCloseBtn(rsModal).click();
await expect.soft(rsModal).not.toBeAttached();

// make sure correct values are displayed
const currentEl = RecordLocators.getRelatedTableAccordion(page, params.displayname);
await testRecordsetTableRowValues(currentEl, params.rowValuesAfter, true);
Expand Down Expand Up @@ -544,7 +528,7 @@ test.describe('Related tables', () => {
rowViewPaths: [
[{ column: 'id', value: '1' }], [{ column: 'id', value: '3' }]
],
count: 2, // by load time it's one but when we add another related for the other table this should be updated too.
count: 1, // by load time it's one but when we add another related for the other table this should be updated too.
canEdit: true,
canCreate: false,
canDelete: true
Expand Down
23 changes: 3 additions & 20 deletions test/e2e/utils/record-utils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Locator, Page, TestInfo, expect, test } from '@playwright/test';

// locators
import RecordLocators from '@isrd-isi-edu/chaise/test/e2e/locators/record';
import RecordsetLocators from '@isrd-isi-edu/chaise/test/e2e/locators/recordset';
import ModalLocators from '@isrd-isi-edu/chaise/test/e2e/locators/modal';
import RecordLocators from '@isrd-isi-edu/chaise/test/e2e/locators/record';
import RecordeditLocators, { RecordeditInputType } from '@isrd-isi-edu/chaise/test/e2e/locators/recordedit';
import RecordsetLocators from '@isrd-isi-edu/chaise/test/e2e/locators/recordset';

import { getCatalogID, getEntityRow, EntityRowColumnValues } from '@isrd-isi-edu/chaise/test/e2e/utils/catalog-utils';
import { EntityRowColumnValues, getCatalogID, getEntityRow } from '@isrd-isi-edu/chaise/test/e2e/utils/catalog-utils';
import { APP_NAMES, PW_PROJECT_NAMES } from '@isrd-isi-edu/chaise/test/e2e/utils/constants';
import {
clickAndVerifyDownload, clickNewTabLink, getClipboardContent,
Expand Down Expand Up @@ -714,23 +714,6 @@ export const testBatchUnlinkAssociationTable = async (page: Page, params: BatchU
await okBtn.click();
await expect.soft(confirmModal).not.toBeAttached();

// make sure summary modal shows up
const summaryModal = ModalLocators.getErrorModal(page);
await expect.soft(summaryModal).toBeVisible();
await expect.soft(ModalLocators.getModalTitle(summaryModal)).toHaveText('Batch Unlink Summary');
await expect.soft(ModalLocators.getModalText(summaryModal)).toHaveText(params.postDeleteMessage);

// close the summary modal
await ModalLocators.getCloseBtn(summaryModal).click();
await expect.soft(summaryModal).not.toBeAttached();

// make sure the recordset modal rows update
await expect.soft(RecordsetLocators.getRows(rsModal)).toHaveCount(params.rowValuesAfter.length);

// close the recordset modal
await ModalLocators.getCloseBtn(rsModal).click();
await expect.soft(rsModal).not.toBeAttached();

// make sure correct values are displayed
const currentEl = RecordLocators.getRelatedTableContainer(page, params.displayname, params.isInline);
await testRecordsetTableRowValues(currentEl, params.rowValuesAfter, true);
Expand Down

0 comments on commit f20a706

Please sign in to comment.