@processmaker/cypress-utils
Advanced tools
Comparing version 1.0.365 to 1.0.366
{ | ||
"name": "@processmaker/cypress-utils", | ||
"version": "1.0.365", | ||
"version": "1.0.366", | ||
"description": "ProcessMaker Cypress Testing Utilities", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -104,2 +104,105 @@ //import selectors from "#selectors/dataValidation"; | ||
/** | ||
* Initiates the import process for a collection by clicking the import button, | ||
* attaching the specified file, and ensuring that the loading spinner and alerts are not visible. | ||
* @param {string} filePath - The path to the file to be imported. | ||
*/ | ||
importCollection(filePath) { | ||
cy.get("[id='import_collection']").click(); | ||
cy.get("[id='import_collection']").should('be.visible'); | ||
cy.get("[type='file']").attachFile(filePath); | ||
cy.get("[id='import_collection']").click(); | ||
cy.get("[class='fas fa-circle-notch fa-spin']").should('not.exist'); | ||
cy.get('[class="alert d-none d-lg-block alertBox alert-dismissible alert-danger"]').should('not.exist'); | ||
} | ||
/** | ||
* Imports a collection via API using the provided file path. | ||
* Converts the file to a Blob and sends it as form data to the API. | ||
* @param {string} filePath - The path to the file to be imported. | ||
* @returns {Promise} - A promise that resolves with the response data. | ||
*/ | ||
importCollectionAPI(filePath) { | ||
let formData = new FormData(); | ||
let win; | ||
return cy.fixture(filePath, null) | ||
.then(Cypress.Blob.arrayBufferToBlob) | ||
.then(fileBlob => { | ||
formData.append('file', fileBlob); | ||
return cy.window(); | ||
}) | ||
.then((win) => { | ||
const options = {}; | ||
const optionsBlob = new Blob([JSON.stringify(options)], { | ||
type: 'application/json' | ||
}); | ||
formData.append('options', optionsBlob); | ||
return win.ProcessMaker.apiClient.post('/collections/import', formData); | ||
}) | ||
.then(response => { | ||
return response.data; | ||
}); | ||
} | ||
/** | ||
* Retrieves a collection by its UUID and name via API. | ||
* @param {string} collection_uuid - The UUID of the collection to retrieve. | ||
* @param {string} collection_name - The name of the collection to filter by. | ||
* @returns {Promise} - A promise that resolves with the found collection. | ||
*/ | ||
getCollectionByUuidAPI(collection_uuid, collection_name){ | ||
return cy.window().then(win => { | ||
return win.ProcessMaker.apiClient.get('/collections', { params: {filter: collection_name,order_by:"id",order_direction:"asc", per_page:100} }).then(response => { | ||
const collection = response.data.data.find(collection => collection.uuid === collection_uuid); | ||
return collection; | ||
}); | ||
}); | ||
} | ||
/** | ||
* Deletes a collection by its ID via API. | ||
* @param {string} collectionID - The ID of the collection to delete. | ||
* @returns {Promise} - A promise that resolves with a confirmation message. | ||
*/ | ||
deleteCollectionByIdAPI(collectionID){ | ||
return cy.window().then(win => { | ||
return win.ProcessMaker.apiClient.delete('/collections/'+collectionID).then(response => { | ||
//console.log(JSON.stringify(response)); | ||
return "collection " + collectionID + " was deleted"; | ||
}); | ||
}); | ||
} | ||
/** | ||
* Retrieves a group by its name via API. | ||
* @param {string} groupName - The name of the group to retrieve. | ||
* @returns {Promise} - A promise that resolves with the found group. | ||
*/ | ||
getGroupByGroupNameAPI(groupName){ | ||
return cy.window().then(win => { | ||
return win.ProcessMaker.apiClient.get('/groups', { params: {filter: groupName} }).then(response => { | ||
const group = response.data.data.find(group => group.name === groupName); | ||
return group; | ||
}); | ||
}); | ||
} | ||
/** | ||
* Verifies the presence of a collection by its name and imports it if found. | ||
* @param {string} collectionName - The name of the collection to search for. | ||
* @param {string} filePath - The path to the file to be imported if the collection is found. | ||
*/ | ||
verifyPresenceOfCollectionAndImportCollection(collectionName, filePath) { | ||
cy.get('[id="search"] input]').should('be.visible').type(collectionName).should('have.value', collectionName); | ||
cy.wait(5000); | ||
cy.xpath('div[id="collectionIndex"] [class="data-table"] table tbody tr', { timeout: 10000 }) | ||
.find('td') | ||
.then(($loadedTable) => { | ||
if ($loadedTable.length === 1) { | ||
this.importCollection(filePath); | ||
} | ||
else return; | ||
}); | ||
} | ||
} |
1884242
34442