Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 133 additions & 0 deletions cypress/e2e/lists/query-builder/search-query-builder-ui.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import Permissions from '../../../support/dictionary/permissions';
import CapabilitySets from '../../../support/dictionary/capabilitySets';
import QueryModal, {
instanceFieldValues,
itemFieldValues,
QUERY_OPERATIONS,
} from '../../../support/fragments/bulk-edit/query-modal';
import InventoryInstance from '../../../support/fragments/inventory/inventoryInstance';
import InventoryInstances from '../../../support/fragments/inventory/inventoryInstances';
import InstanceRecordView from '../../../support/fragments/inventory/instanceRecordView';
import { Lists } from '../../../support/fragments/lists/lists';
import ClassificationIdentifierTypes from '../../../support/fragments/settings/inventory/instances/classificationIdentifierTypes';
import Libraries from '../../../support/fragments/settings/tenant/location-setup/libraries';
import TopMenu from '../../../support/fragments/topMenu';
import Users from '../../../support/fragments/users/users';
import DateTools from '../../../support/utils/dateTools';
Expand Down Expand Up @@ -125,6 +127,12 @@ describe('Lists', () => {
});
};

const verifyQueryTextDoesNotContainUuids = (actualQueryText) => {
expect(actualQueryText).not.to.match(
/\b[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\b/i,
);
};

const verifyQueryBuilder = (
field,
operator,
Expand Down Expand Up @@ -542,6 +550,131 @@ describe('Lists', () => {
);
});

describe('Items', () => {
const recordType = 'Items';
const testData = {
effectiveLibraryCodeFieldName: 'loclibrary.code',
effectiveLibraryNameFieldName: 'loclibrary.name',
effectiveLibraryCodeLabels: [],
effectiveLibraryNameLabels: [],
folioInstances: InventoryInstances.generateFolioInstances({
instanceTitlePrefix: getTestEntityValue('C829880_Instance'),
}),
};

const getFieldLabels = (fieldName, matchingValue, matchingLabel) => {
return Lists.getEntityTypeIdByNameViaApi(recordType).then((entityTypeId) => {
return Lists.getEntityTypeFieldValuesViaApi(entityTypeId, fieldName).then((body) => {
const matchingFieldValue = body.content.find(({ label, value }) => {
return value === matchingValue || label === matchingLabel;
});
expect(matchingFieldValue, `Field value for ${fieldName}`).not.to.equal(undefined);

return [
matchingFieldValue,
body.content.find(({ value }) => value !== matchingFieldValue.value),
]
.filter(Boolean)
.map(({ label }) => label);
});
});
};

const selectMultipleValues = (values, row = 0) => {
values.forEach((value) => {
QueryModal.chooseFromValueMultiselect(value, row, { exactMatch: true });
});
};

before('Create test user and get field values', () => {
cy.getAdminToken();
InventoryInstances.getLocations({ limit: 1 }).then(([location]) => {
InventoryInstances.createFolioInstancesViaApi({
folioInstances: testData.folioInstances,
location,
});
Libraries.getViaApi().then(({ loclibs }) => {
const library = loclibs.find(({ id }) => id === location.libraryId);
expect(library, `Library for location ${location.name}`).not.to.equal(undefined);

getFieldLabels(
testData.effectiveLibraryCodeFieldName,
location.libraryId,
library.code,
).then((labels) => {
testData.effectiveLibraryCodeLabels = labels;
});
getFieldLabels(
testData.effectiveLibraryNameFieldName,
location.libraryId,
library.name,
).then((labels) => {
testData.effectiveLibraryNameLabels = labels;
});
});
});
createQueryBuilderUser(
[Permissions.listsEdit.gui, Permissions.listsDelete.gui, Permissions.inventoryAll.gui],
[CapabilitySets.uiInventory],
);
});

after('Delete test data', () => {
cy.getAdminToken();
InventoryInstances.deleteInstanceAndItsHoldingsAndItemsViaApi(
testData.folioInstances[0].instanceId,
);
deleteQueryBuilderUser();
});

afterEach('Delete test list', () => {
deleteTestList();
});

it(
'C829880 Verify that the fields "Item effective library — Code" and "Item effective library — Name" have correct labels in the user-friendly query for the "Items" ET (corsair)',
{ tags: ['extendedPath', 'corsair', 'C829880'] },
() => {
const expectedCodeQuery = `(${testData.effectiveLibraryCodeFieldName} in [${testData.effectiveLibraryCodeLabels.join(', ')}])`;
const expectedFullQuery = `${expectedCodeQuery} AND (${testData.effectiveLibraryNameFieldName} in [${testData.effectiveLibraryNameLabels.join(', ')}])`;

listName = getTestEntityValue('C829880_List');
openQueryBuilder(recordType);
QueryModal.verify();
QueryModal.verifyQueryTextboxReadOnly();
QueryModal.verifyQueryTextboxResizable();

QueryModal.selectField(itemFieldValues.itemEffectiveLibraryCode);
QueryModal.verifySelectedField(itemFieldValues.itemEffectiveLibraryCode);
QueryModal.selectOperator(QUERY_OPERATIONS.IN);
selectMultipleValues(testData.effectiveLibraryCodeLabels);
QueryModal.verifyQueryAreaContent(expectedCodeQuery);
QueryModal.getQueryAreaContent().then(verifyQueryTextDoesNotContainUuids);

QueryModal.addNewRow();
QueryModal.selectField(itemFieldValues.itemEffectiveLibraryName, 1);
QueryModal.verifySelectedField(itemFieldValues.itemEffectiveLibraryName, 1);
QueryModal.selectOperator(QUERY_OPERATIONS.IN, 1);
selectMultipleValues(testData.effectiveLibraryNameLabels, 1);
QueryModal.verifyQueryAreaContent(expectedFullQuery);
QueryModal.getQueryAreaContent().then(verifyQueryTextDoesNotContainUuids);

QueryModal.clickTestQuery();
QueryModal.verifyPreviewOfRecordsMatched();
QueryModal.clickRunQueryAndSave();
QueryModal.verifyClosed();
Lists.verifySuccessCalloutMessage(`List ${listName} saved.`);
Lists.waitForCompilingAnimationToDisappear();
cy.contains('Refresh complete with', { timeout: 90000 }).should('be.visible');
Lists.viewUpdatedList();
Lists.getQueryText().then((actualSavedQuery) => {
expect(actualSavedQuery).to.include(`Query: ${expectedFullQuery}`);
verifyQueryTextDoesNotContainUuids(actualSavedQuery);
});
},
);
});

describe('Instances', () => {
const recordType = 'Instances';
const resourceTypeColumn = 'Instance — Resource type';
Expand Down
2 changes: 2 additions & 0 deletions cypress/support/fragments/bulk-edit/query-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ export const itemFieldValues = {
itemStatus: 'Item — Status',
itemHrid: 'Item — Item HRID',
itemUuid: 'Item — Item UUID',
itemEffectiveLibraryCode: 'Item effective library — Code',
itemEffectiveLibraryName: 'Item effective library — Name',
holdingsId: 'Holdings — UUID',
holdingsHrid: 'Holdings — HRID',
temporaryLocation: 'Item temporary location — Name',
Expand Down