Changeset View
Changeset View
Standalone View
Standalone View
cypress/integration/origin-save.spec.js
Show All 13 Lines | const saveCodeMsg = { | ||||
'warning': 'The "save code now" request has been put in pending state and may be accepted for processing after manual review.', | 'warning': 'The "save code now" request has been put in pending state and may be accepted for processing after manual review.', | ||||
'rejected': 'The "save code now" request has been rejected because the provided origin url is blacklisted.', | 'rejected': 'The "save code now" request has been rejected because the provided origin url is blacklisted.', | ||||
'rateLimit': 'The rate limit for "save code now" requests has been reached. Please try again later.', | 'rateLimit': 'The rate limit for "save code now" requests has been reached. Please try again later.', | ||||
'unknownError': 'An unexpected error happened when submitting the "save code now request', | 'unknownError': 'An unexpected error happened when submitting the "save code now request', | ||||
'csrfError': 'CSRF Failed: Referrer checking failed - no Referrer.' | 'csrfError': 'CSRF Failed: Referrer checking failed - no Referrer.' | ||||
}; | }; | ||||
function makeOriginSaveRequest(originType, originUrl) { | function makeOriginSaveRequest(originType, originUrl) { | ||||
cy.get('#swh-input-visit-type') | cy.get('#swh-input-origin-url') | ||||
.select(originType) | |||||
.get('#swh-input-origin-url') | |||||
.type(originUrl) | .type(originUrl) | ||||
.get('#swh-input-visit-type') | |||||
.select(originType) | |||||
.get('#swh-save-origin-form') | .get('#swh-save-origin-form') | ||||
.submit(); | .submit(); | ||||
} | } | ||||
function checkAlertVisible(alertType, msg) { | function checkAlertVisible(alertType, msg) { | ||||
cy.get('#swh-origin-save-request-status') | cy.get('#swh-origin-save-request-status') | ||||
.should('be.visible') | .should('be.visible') | ||||
.find(`.alert-${alertType}`) | .find(`.alert-${alertType}`) | ||||
Show All 35 Lines | |||||
describe('Origin Save Tests', function() { | describe('Origin Save Tests', function() { | ||||
before(function() { | before(function() { | ||||
url = this.Urls.origin_save(); | url = this.Urls.origin_save(); | ||||
origin = this.origin[0]; | origin = this.origin[0]; | ||||
this.originSaveUrl = this.Urls.origin_save_request(origin.type, origin.url); | this.originSaveUrl = this.Urls.origin_save_request(origin.type, origin.url); | ||||
}); | }); | ||||
beforeEach(function() { | beforeEach(function() { | ||||
cy.fixture('origin-save').as('originSaveJSON'); | |||||
cy.fixture('save-task-info').as('saveTaskInfoJSON'); | |||||
cy.visit(url); | cy.visit(url); | ||||
cy.server(); | cy.server(); | ||||
}); | }); | ||||
it('should display accepted message when accepted', function() { | it('should display accepted message when accepted', function() { | ||||
stubSaveRequest(this.originSaveUrl, origin.type, 'accepted', | stubSaveRequest(this.originSaveUrl, origin.type, 'accepted', | ||||
origin.url, 'not yet scheduled'); | origin.url, 'not yet scheduled'); | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | it('should show error when unknown error occurs (status other than 200, 403, 429)', function() { | ||||
makeOriginSaveRequest(origin.type, origin.url); | makeOriginSaveRequest(origin.type, origin.url); | ||||
cy.wait('@saveRequest').then(() => { | cy.wait('@saveRequest').then(() => { | ||||
checkAlertVisible('danger', saveCodeMsg['unknownError']); | checkAlertVisible('danger', saveCodeMsg['unknownError']); | ||||
}); | }); | ||||
}); | }); | ||||
it('should display origin save info in the requests table', function() { | it('should display origin save info in the requests table', function() { | ||||
cy.fixture('origin-save').as('originSaveJSON'); | |||||
cy.route('GET', '/save/requests/list/**', '@originSaveJSON'); | cy.route('GET', '/save/requests/list/**', '@originSaveJSON'); | ||||
cy.get('#swh-origin-save-requests-list-tab').click(); | cy.get('#swh-origin-save-requests-list-tab').click(); | ||||
cy.get('tbody tr').then(rows => { | cy.get('tbody tr').then(rows => { | ||||
let i = 0; | let i = 0; | ||||
for (let row of rows) { | for (let row of rows) { | ||||
const cells = row.cells; | const cells = row.cells; | ||||
const requestDateStr = new Date(this.originSaveJSON.data[i].save_request_date).toLocaleString(); | const requestDateStr = new Date(this.originSaveJSON.data[i].save_request_date).toLocaleString(); | ||||
const saveStatus = this.originSaveJSON.data[i].save_task_status; | const saveStatus = this.originSaveJSON.data[i].save_task_status; | ||||
Show All 13 Lines | cy.get('tbody tr').then(rows => { | ||||
assert.equal($(cells[3]).text(), this.originSaveJSON.data[i].save_request_status); | assert.equal($(cells[3]).text(), this.originSaveJSON.data[i].save_request_status); | ||||
assert.equal($(cells[4]).text(), saveStatus); | assert.equal($(cells[4]).text(), saveStatus); | ||||
++i; | ++i; | ||||
} | } | ||||
}); | }); | ||||
}); | }); | ||||
it('should display/close task info popover when clicking on the info button', function() { | it('should display/close task info popover when clicking on the info button', function() { | ||||
cy.fixture('origin-save').as('originSaveJSON'); | |||||
cy.fixture('save-task-info').as('saveTaskInfoJSON'); | |||||
cy.route('GET', '/save/requests/list/**', '@originSaveJSON'); | cy.route('GET', '/save/requests/list/**', '@originSaveJSON'); | ||||
cy.route('GET', '/save/task/info/**', '@saveTaskInfoJSON'); | cy.route('GET', '/save/task/info/**', '@saveTaskInfoJSON'); | ||||
cy.get('#swh-origin-save-requests-list-tab').click(); | cy.get('#swh-origin-save-requests-list-tab').click(); | ||||
cy.get('.swh-save-request-info') | cy.get('.swh-save-request-info') | ||||
.eq(0) | .eq(0) | ||||
.click(); | .click(); | ||||
cy.get('.swh-save-request-info-popover') | cy.get('.swh-save-request-info-popover') | ||||
.should('be.visible'); | .should('be.visible'); | ||||
cy.get('.swh-save-request-info') | cy.get('.swh-save-request-info') | ||||
.eq(0) | .eq(0) | ||||
.click(); | .click(); | ||||
cy.get('.swh-save-request-info-popover') | cy.get('.swh-save-request-info-popover') | ||||
.should('not.be.visible'); | .should('not.be.visible'); | ||||
}); | }); | ||||
it('should hide task info popover when clicking on the close button', function() { | it('should hide task info popover when clicking on the close button', function() { | ||||
cy.fixture('origin-save').as('originSaveJSON'); | |||||
cy.fixture('save-task-info').as('saveTaskInfoJSON'); | |||||
cy.route('GET', '/save/requests/list/**', '@originSaveJSON'); | cy.route('GET', '/save/requests/list/**', '@originSaveJSON'); | ||||
cy.route('GET', '/save/task/info/**', '@saveTaskInfoJSON'); | cy.route('GET', '/save/task/info/**', '@saveTaskInfoJSON'); | ||||
cy.get('#swh-origin-save-requests-list-tab').click(); | cy.get('#swh-origin-save-requests-list-tab').click(); | ||||
cy.get('.swh-save-request-info') | cy.get('.swh-save-request-info') | ||||
.eq(0) | .eq(0) | ||||
.click(); | .click(); | ||||
cy.get('.swh-save-request-info-popover') | cy.get('.swh-save-request-info-popover') | ||||
.should('be.visible'); | .should('be.visible'); | ||||
cy.get('.swh-save-request-info-close') | cy.get('.swh-save-request-info-close') | ||||
.click(); | .click(); | ||||
cy.get('.swh-save-request-info-popover') | cy.get('.swh-save-request-info-popover') | ||||
.should('not.be.visible'); | .should('not.be.visible'); | ||||
}); | }); | ||||
it('should fill save request form when clicking on "Save again" button', function() { | it('should fill save request form when clicking on "Save again" button', function() { | ||||
cy.fixture('origin-save').as('originSaveJSON'); | |||||
cy.route('GET', '/save/requests/list/**', '@originSaveJSON'); | cy.route('GET', '/save/requests/list/**', '@originSaveJSON'); | ||||
cy.get('#swh-origin-save-requests-list-tab').click(); | cy.get('#swh-origin-save-requests-list-tab').click(); | ||||
cy.get('.swh-save-origin-again') | cy.get('.swh-save-origin-again') | ||||
.eq(0) | .eq(0) | ||||
.click(); | .click(); | ||||
cy.get('tbody tr').eq(0).then(row => { | cy.get('tbody tr').eq(0).then(row => { | ||||
const cells = row[0].cells; | const cells = row[0].cells; | ||||
cy.get('#swh-input-visit-type') | cy.get('#swh-input-visit-type') | ||||
.should('have.value', $(cells[1]).text()); | .should('have.value', $(cells[1]).text()); | ||||
cy.get('#swh-input-origin-url') | cy.get('#swh-input-origin-url') | ||||
.should('have.value', $(cells[2]).text().slice(0, -1)); | .should('have.value', $(cells[2]).text().slice(0, -1)); | ||||
}); | }); | ||||
}); | }); | ||||
it('should select correct origin type if possible when clicking on "Save again" button', function() { | |||||
const originUrl = 'https://gitlab.inria.fr/solverstack/maphys/maphys/'; | |||||
const badOriginType = 'hg'; | |||||
const goodOriginType = 'git'; | |||||
cy.route('GET', '/save/requests/list/**', '@originSaveJSON'); | |||||
stubSaveRequest(this.Urls.origin_save_request(badOriginType, originUrl), | |||||
badOriginType, 'accepted', | |||||
originUrl, 'failed', 200, saveCodeMsg['accepted']); | |||||
makeOriginSaveRequest(badOriginType, originUrl); | |||||
cy.get('#swh-origin-save-requests-list-tab').click(); | |||||
cy.wait('@saveRequest').then(() => { | |||||
cy.get('.swh-save-origin-again') | |||||
.eq(0) | |||||
.click(); | |||||
cy.get('tbody tr').eq(0).then(row => { | |||||
const cells = row[0].cells; | |||||
cy.get('#swh-input-visit-type') | |||||
.should('have.value', goodOriginType); | |||||
cy.get('#swh-input-origin-url') | |||||
.should('have.value', $(cells[2]).text().slice(0, -1)); | |||||
}); | |||||
}); | |||||
}); | |||||
}); | }); |