diff --git a/cypress/e2e/settings/marc-authority/change-active-checkbox-state-of-folio-authority-file-with-assigned-record.cy.js b/cypress/e2e/settings/marc-authority/change-active-checkbox-state-of-folio-authority-file-with-assigned-record.cy.js new file mode 100644 index 0000000000..c3c1b34d1d --- /dev/null +++ b/cypress/e2e/settings/marc-authority/change-active-checkbox-state-of-folio-authority-file-with-assigned-record.cy.js @@ -0,0 +1,144 @@ +import Permissions from '../../../support/dictionary/permissions'; +import TopMenu from '../../../support/fragments/topMenu'; +import Users from '../../../support/fragments/users/users'; +import getRandomPostfix, { randomFourDigitNumber } from '../../../support/utils/stringTools'; +import DateTools from '../../../support/utils/dateTools'; +import ManageAuthorityFiles from '../../../support/fragments/settings/marc-authority/manageAuthorityFiles'; +import MarcAuthorities from '../../../support/fragments/marcAuthority/marcAuthorities'; +import MarcAuthority from '../../../support/fragments/marcAuthority/marcAuthority'; +import { DEFAULT_FOLIO_AUTHORITY_FILES } from '../../../support/constants'; + +describe('MARC', () => { + describe('MARC Authority', () => { + describe('Settings', () => { + const randomPostfix = getRandomPostfix(); + const title = `C436862 Test title ${randomPostfix}`; + const date = DateTools.getFormattedDateWithSlashes({ date: new Date() }); + const folioAuthorityFile = { + name: DEFAULT_FOLIO_AUTHORITY_FILES.FACETED_APPLICATION_OF_SUBJECT_TERMINOLOGY, + prefix: 'fst', + hridStartsWith: '', + baseUrl: 'http://id.worldcat.org/fast/', + }; + const controlNumber = `${randomFourDigitNumber()}`; + const fields = [ + { tag: '100', content: `$a ${title}`, indicators: ['\\', '\\'] }, + { + tag: '010', + content: `$a ${folioAuthorityFile.prefix}${controlNumber}`, + indicators: ['\\', '\\'], + }, + ]; + let user; + let createdAuthorityId; + + before('Create users, data', () => { + cy.getAdminToken(); + cy.createTempUser([Permissions.uiSettingsManageAuthorityFiles.gui]) + .then((userProperties) => { + user = userProperties; + }) + .then(() => { + ManageAuthorityFiles.setAuthorityFileToActiveViaApi( + DEFAULT_FOLIO_AUTHORITY_FILES.FACETED_APPLICATION_OF_SUBJECT_TERMINOLOGY, + ); + }) + .then(() => { + MarcAuthorities.createMarcAuthorityViaAPI( + `${folioAuthorityFile.prefix}`, + `${controlNumber}`, + fields, + ).then((createdRecordId) => { + createdAuthorityId = createdRecordId; + }); + }) + .then(() => { + ManageAuthorityFiles.unsetAuthorityFileAsActiveViaApi( + DEFAULT_FOLIO_AUTHORITY_FILES.FACETED_APPLICATION_OF_SUBJECT_TERMINOLOGY, + ); + }); + }); + + after('Delete users, data', () => { + cy.getAdminToken(); + Users.deleteViaApi(user.userId); + MarcAuthority.deleteViaAPI(createdAuthorityId, true); + }); + + it( + 'C436862 Change "Active" checkbox state of FOLIO "Authority file" which has assigned "MARC authority" records (spitfire)', + { tags: ['criticalPath', 'spitfire'] }, + () => { + // 1 Go to "Settings" app >> "MARC authority" >> "Manage authority files" + cy.login(user.username, user.password, { + path: TopMenu.settingsAuthorityFilesPath, + waiter: ManageAuthorityFiles.waitLoading, + }); + ManageAuthorityFiles.checkManageAuthorityFilesPaneExists(); + ManageAuthorityFiles.checkAuthorityFilesTableExists(); + ManageAuthorityFiles.checkDefaultSourceFilesExist(); + + // 2 Click on the "Edit" (pencil) icon of "Authority file" with source "FOLIO" which has assigned "MARC authority" records + ManageAuthorityFiles.clickEditButton(folioAuthorityFile.name); + ManageAuthorityFiles.checkRowEditableInEditModeInFolioFile( + folioAuthorityFile.name, + folioAuthorityFile.prefix, + folioAuthorityFile.hridStartsWith, + folioAuthorityFile.baseUrl, + false, + ); + ManageAuthorityFiles.checkNewButtonEnabled(false); + + // 3 Check "Active" checkbox + ManageAuthorityFiles.switchActiveCheckboxInFile(folioAuthorityFile.name, true); + ManageAuthorityFiles.checkSaveButtonEnabledInFile(folioAuthorityFile.name); + ManageAuthorityFiles.checkCancelButtonEnabledInFile(folioAuthorityFile.name); + + // 4 Click on the "Save" button + ManageAuthorityFiles.clickSaveButtonAfterEditingFile(folioAuthorityFile.name); + ManageAuthorityFiles.checkAfterSaveEditedFile(folioAuthorityFile.name); + ManageAuthorityFiles.checkSourceFileExists( + folioAuthorityFile.name, + folioAuthorityFile.prefix, + folioAuthorityFile.hridStartsWith, + folioAuthorityFile.baseUrl, + true, + `${date} by ${user.lastName}, ${user.firstName}`, + false, + ); + + // 5 Click on the "Edit" (pencil) icon of updated "FOLIO" authority file again + ManageAuthorityFiles.clickEditButton(folioAuthorityFile.name); + ManageAuthorityFiles.checkRowEditableInEditModeInFolioFile( + folioAuthorityFile.name, + folioAuthorityFile.prefix, + folioAuthorityFile.hridStartsWith, + folioAuthorityFile.baseUrl, + true, + ); + ManageAuthorityFiles.checkLastUpdatedByUser( + folioAuthorityFile.name, + `${date} by ${user.lastName}, ${user.firstName}`, + ); + ManageAuthorityFiles.checkNewButtonEnabled(false); + + // 6 Uncheck "Active" checkbox + ManageAuthorityFiles.switchActiveCheckboxInFile(folioAuthorityFile.name, false); + + // 7 Click on the "Save" button + ManageAuthorityFiles.clickSaveButtonAfterEditingFile(folioAuthorityFile.name); + ManageAuthorityFiles.checkAfterSaveEditedFile(folioAuthorityFile.name); + ManageAuthorityFiles.checkSourceFileExists( + folioAuthorityFile.name, + folioAuthorityFile.prefix, + folioAuthorityFile.hridStartsWith, + folioAuthorityFile.baseUrl, + false, + `${date} by ${user.lastName}, ${user.firstName}`, + false, + ); + }, + ); + }); + }); +}); diff --git a/cypress/support/fragments/settings/marc-authority/manageAuthorityFiles.js b/cypress/support/fragments/settings/marc-authority/manageAuthorityFiles.js index 279b3fb382..33fd6c7459 100644 --- a/cypress/support/fragments/settings/marc-authority/manageAuthorityFiles.js +++ b/cypress/support/fragments/settings/marc-authority/manageAuthorityFiles.js @@ -138,6 +138,87 @@ const getEditableListRow = (rowNumber) => { return EditableListRow({ index: +rowNumber.split('-')[1] }); }; +const getTargetRowWithFile = (authorityFileName) => { + return manageAuthorityFilesPane.find( + MultiColumnListRow({ innerHTML: including(authorityFileName) }), + ); +}; + +const defaultFolioAuthorityFiles = [ + { + name: DEFAULT_FOLIO_AUTHORITY_FILES.ART_AND_ARCHITECTURE_THESAURUS, + prefix: 'aatg,aat', + startsWith: '', + baseUrl: 'http://vocab.getty.edu/aat/', + }, + { + name: DEFAULT_FOLIO_AUTHORITY_FILES.FACETED_APPLICATION_OF_SUBJECT_TERMINOLOGY, + prefix: 'fst', + startsWith: '', + baseUrl: 'http://id.worldcat.org/fast/', + }, + { + name: DEFAULT_FOLIO_AUTHORITY_FILES.GSAFD_GENRE_TERMS, + prefix: 'gsafd', + startsWith: '', + baseUrl: 'https://vocabularyserver.com/gsafd/', + }, + { + name: DEFAULT_FOLIO_AUTHORITY_FILES.LC_CHILDREN_SUBJECT_HEADINGS, + prefix: 'sj', + startsWith: '', + baseUrl: 'http://id.loc.gov/authorities/childrensSubjects/', + }, + { + name: DEFAULT_FOLIO_AUTHORITY_FILES.LC_DEMOGRAPHIC_GROUP_TERMS, + prefix: 'dg', + startsWith: '', + baseUrl: 'http://id.loc.gov/authorities/demographicTerms/', + }, + { + name: DEFAULT_FOLIO_AUTHORITY_FILES.LC_GENRE_FORM_TERMS, + prefix: 'gf', + startsWith: '', + baseUrl: 'http://id.loc.gov/authorities/genreForms/', + }, + { + name: DEFAULT_FOLIO_AUTHORITY_FILES.LC_MEDIUM_OF_PERFORMANCE_THESAURUS_FOR_MUSIC, + prefix: 'mp', + startsWith: '', + baseUrl: 'http://id.loc.gov/authorities/performanceMediums/', + }, + { + name: DEFAULT_FOLIO_AUTHORITY_FILES.LC_NAME_AUTHORITY_FILE, + prefix: 'n,nb,nr,no,ns', + startsWith: '', + baseUrl: 'http://id.loc.gov/authorities/names/', + }, + { + name: DEFAULT_FOLIO_AUTHORITY_FILES.LC_SUBJECT_HEADINGS, + prefix: 'sh', + startsWith: '', + baseUrl: 'http://id.loc.gov/authorities/subjects/', + }, + { + name: DEFAULT_FOLIO_AUTHORITY_FILES.MEDICAL_SUBJECT_HEADINGS, + prefix: 'D', + startsWith: '', + baseUrl: 'https://id.nlm.nih.gov/mesh/', + }, + { + name: DEFAULT_FOLIO_AUTHORITY_FILES.RARE_BOOKS_AND_MANUSCRIPTS_SECTION, + prefix: 'rbmscv', + startsWith: '', + baseUrl: '', + }, + { + name: DEFAULT_FOLIO_AUTHORITY_FILES.THESAURUS_FOR_GRAPHIC_MATERIALS, + prefix: 'lcgtm,tgm', + startsWith: '', + baseUrl: 'http://id.loc.gov/vocabulary/graphicMaterials/', + }, +]; + export default { waitLoading, clickNewButton, @@ -168,7 +249,8 @@ export default { }, checkSourceFileExists(name, prefix, startsWith, baseUrl, isActive, lastUpdatedBy, isDeletable) { - const targetRow = manageAuthorityFilesPane.find(MultiColumnListRow(including(name))); + const targetRow = getTargetRowWithFile(name); + cy.expect([ targetRow.find(MultiColumnListCell(prefix)).exists(), targetRow.find(MultiColumnListCell(startsWith)).exists(), @@ -189,39 +271,28 @@ export default { }, checkErrorInField(authorityFileName, fieldName, errorMessage) { - cy.do( - TextField({ value: authorityFileName }).perform((element) => { - const rowNumber = element.closest('[data-row-index]').getAttribute('data-row-index'); - const targetRow = manageAuthorityFilesPane.find(getEditableListRow(rowNumber)); - - switch (fieldName) { - case AUTHORITY_FILE_TEXT_FIELD_NAMES.NAME: - cy.expect( - targetRow.find(nameTextField).has({ error: errorMessage, errorTextRed: true }), - ); - break; - case AUTHORITY_FILE_TEXT_FIELD_NAMES.PREFIX: - cy.expect( - targetRow.find(prefixTextField).has({ error: errorMessage, errorTextRed: true }), - ); - break; - case AUTHORITY_FILE_TEXT_FIELD_NAMES.HRID_STARTS_WITH: - cy.expect( - targetRow - .find(hridStartsWithTextField) - .has({ error: errorMessage, errorTextRed: true }), - ); - break; - case AUTHORITY_FILE_TEXT_FIELD_NAMES.BASE_URL: - cy.expect( - targetRow.find(baseUrlTextField).has({ error: errorMessage, errorTextRed: true }), - ); - break; - default: - break; - } - }), - ); + const targetRow = getTargetRowWithFile(authorityFileName); + + switch (fieldName) { + case AUTHORITY_FILE_TEXT_FIELD_NAMES.NAME: + cy.expect(targetRow.find(nameTextField).has({ error: errorMessage, errorTextRed: true })); + break; + case AUTHORITY_FILE_TEXT_FIELD_NAMES.PREFIX: + cy.expect(targetRow.find(prefixTextField).has({ error: errorMessage, errorTextRed: true })); + break; + case AUTHORITY_FILE_TEXT_FIELD_NAMES.HRID_STARTS_WITH: + cy.expect( + targetRow.find(hridStartsWithTextField).has({ error: errorMessage, errorTextRed: true }), + ); + break; + case AUTHORITY_FILE_TEXT_FIELD_NAMES.BASE_URL: + cy.expect( + targetRow.find(baseUrlTextField).has({ error: errorMessage, errorTextRed: true }), + ); + break; + default: + break; + } }, checkManageAuthorityFilesPaneExists(isExist = true) { @@ -233,25 +304,15 @@ export default { }, clickSaveButtonAfterEditingFile(authorityFileName) { - cy.do( - TextField({ value: authorityFileName }).perform((element) => { - const rowNumber = element.closest('[data-row-index]').getAttribute('data-row-index'); - cy.do( - manageAuthorityFilesPane.find(getEditableListRow(rowNumber)).find(saveButton).click(), - ); - }), - ); + const targetRow = getTargetRowWithFile(authorityFileName); + + cy.do(targetRow.find(saveButton).click()); }, clickCancelButtonAfterEditingFile(authorityFileName) { - cy.do( - TextField({ value: authorityFileName }).perform((element) => { - const rowNumber = element.closest('[data-row-index]').getAttribute('data-row-index'); - cy.do( - manageAuthorityFilesPane.find(getEditableListRow(rowNumber)).find(cancelButton).click(), - ); - }), - ); + const targetRow = getTargetRowWithFile(authorityFileName); + + cy.do(targetRow.find(cancelButton).click()); }, editField(authorityFileName, fieldName, fieldValue) { @@ -279,24 +340,46 @@ export default { isCancelButtonDisabled = false, isSaveButtonDisabled = true, ) { - cy.do( - TextField({ value: authorityFileName }).perform((element) => { - const rowNumber = element.closest('[data-row-index]').getAttribute('data-row-index'); - const targetRow = manageAuthorityFilesPane.find(getEditableListRow(rowNumber)); + const targetRow = getTargetRowWithFile(authorityFileName); - cy.expect(targetRow.find(nameTextField).has({ value: authorityFileName, disabled: false })); - cy.expect(targetRow.find(prefixTextField).has({ value: prefix, disabled: false })); - cy.expect( - targetRow.find(hridStartsWithTextField).has({ value: hridStartsWith, disabled: false }), - ); - cy.expect(targetRow.find(baseUrlTextField).has({ value: baseUrl, disabled: false })); - cy.expect(targetRow.find(activeCheckbox).has({ checked: isActive, disabled: false })); - cy.expect(targetRow.find(sourceCell).has({ content: source })); - cy.expect(targetRow.find(MultiColumnListCell(including(createdByUser))).exists()); - cy.expect(targetRow.find(cancelButton).has({ disabled: isCancelButtonDisabled })); - cy.expect(targetRow.find(saveButton).has({ disabled: isSaveButtonDisabled })); - }), - ); + cy.expect([ + targetRow.find(nameTextField).has({ value: authorityFileName, disabled: false }), + targetRow.find(prefixTextField).has({ value: prefix, disabled: false }), + targetRow.find(hridStartsWithTextField).has({ value: hridStartsWith, disabled: false }), + targetRow.find(baseUrlTextField).has({ value: baseUrl, disabled: false }), + targetRow.find(activeCheckbox).has({ checked: isActive, disabled: false }), + targetRow.find(sourceCell).has({ content: source }), + targetRow.find(MultiColumnListCell(including(createdByUser))).exists(), + targetRow.find(cancelButton).has({ disabled: isCancelButtonDisabled }), + targetRow.find(saveButton).has({ disabled: isSaveButtonDisabled }), + ]); + }, + + checkRowEditableInEditModeInFolioFile( + authorityFileName, + prefix, + hridStartsWith, + baseUrl, + isActive, + isCancelButtonDisabled = false, + isSaveButtonDisabled = true, + ) { + const targetRow = getTargetRowWithFile(authorityFileName); + + cy.expect([ + targetRow.find(MultiColumnListCell(prefix)).exists(), + targetRow.find(MultiColumnListCell(hridStartsWith)).exists(), + targetRow.find(baseUrlTextField).has({ value: baseUrl, disabled: false }), + targetRow.find(activeCheckbox).has({ checked: isActive, disabled: false }), + targetRow.find(cancelButton).has({ disabled: isCancelButtonDisabled }), + targetRow.find(saveButton).has({ disabled: isSaveButtonDisabled }), + ]); + }, + + checkLastUpdatedByUser(authorityFileName, userName) { + const targetRow = getTargetRowWithFile(authorityFileName); + + cy.expect(targetRow.find(MultiColumnListCell(including(userName))).exists()); }, checkActionTableHeaderExists() { @@ -312,37 +395,38 @@ export default { }, switchActiveCheckboxInFile(authorityFileName, isChecked) { - cy.do( - TextField({ value: authorityFileName }).perform((element) => { - const rowNumber = element.closest('[data-row-index]').getAttribute('data-row-index'); - const targetRow = manageAuthorityFilesPane.find(getEditableListRow(rowNumber)); + const targetRow = getTargetRowWithFile(authorityFileName); - cy.do(targetRow.find(activeCheckbox).click()); - cy.expect(targetRow.find(activeCheckbox).has({ checked: isChecked })); - }), - ); + cy.do(targetRow.find(activeCheckbox).click()); + cy.expect(targetRow.find(activeCheckbox).has({ checked: isChecked })); }, checkSaveButtonEnabledInFile(authorityFileName, isEnabled = true) { - cy.do( - TextField({ value: authorityFileName }).perform((element) => { - const rowNumber = element.closest('[data-row-index]').getAttribute('data-row-index'); - const targetRow = manageAuthorityFilesPane.find(getEditableListRow(rowNumber)); + const targetRow = getTargetRowWithFile(authorityFileName); - cy.expect(targetRow.find(saveButton).has({ disabled: !isEnabled })); - }), - ); + cy.expect(targetRow.find(saveButton).has({ disabled: !isEnabled })); }, checkCancelButtonEnabledInFile(authorityFileName, isEnabled = true) { - cy.do( - TextField({ value: authorityFileName }).perform((element) => { - const rowNumber = element.closest('[data-row-index]').getAttribute('data-row-index'); - const targetRow = manageAuthorityFilesPane.find(getEditableListRow(rowNumber)); + const targetRow = getTargetRowWithFile(authorityFileName); - cy.expect(targetRow.find(cancelButton).has({ disabled: !isEnabled })); - }), - ); + cy.expect(targetRow.find(cancelButton).has({ disabled: !isEnabled })); + }, + + checkDefaultSourceFilesExist() { + defaultFolioAuthorityFiles.forEach((defaultFolioAuthorityFile) => { + const targetRow = manageAuthorityFilesPane.find( + MultiColumnListRow(including(defaultFolioAuthorityFile.name)), + ); + cy.expect([ + targetRow.find(MultiColumnListCell(defaultFolioAuthorityFile.prefix)).exists(), + targetRow.find(MultiColumnListCell(defaultFolioAuthorityFile.startsWith)).exists(), + targetRow.find(MultiColumnListCell(defaultFolioAuthorityFile.baseUrl)).exists(), + targetRow.find(sourceCell).has({ content: 'FOLIO' }), + targetRow.find(activeCheckbox).has({ disabled: true }), + targetRow.find(editButton).exists(), + ]); + }); }, setAllDefaultFOLIOFilesToActiveViaAPI() { diff --git a/interactors/multi-column-list.js b/interactors/multi-column-list.js index 88c4382b81..8e4fa807ca 100644 --- a/interactors/multi-column-list.js +++ b/interactors/multi-column-list.js @@ -23,6 +23,7 @@ export const MultiColumnListRow = HTML.extend('multi column list row') // indexRow filter is a workaround for folio parts where we have data-row-inner=true (for some reason) indexRow: (el) => el.parentElement.getAttribute('data-row-index'), ariaRowIndex: (el) => +el.getAttribute('aria-rowindex'), + innerHTML: (el) => el.innerHTML, }); export const ListRow = HTML.extend('list row')