diff --git a/cypress/integration/origin-save.spec.js b/cypress/integration/origin-save.spec.js --- a/cypress/integration/origin-save.spec.js +++ b/cypress/integration/origin-save.spec.js @@ -19,10 +19,10 @@ }; function makeOriginSaveRequest(originType, originUrl) { - cy.get('#swh-input-visit-type') - .select(originType) - .get('#swh-input-origin-url') + cy.get('#swh-input-origin-url') .type(originUrl) + .get('#swh-input-visit-type') + .select(originType) .get('#swh-save-origin-form') .submit(); } @@ -248,4 +248,31 @@ .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://github.com/user/repo'; + const badOriginType = 'hg'; + const goodOriginType = 'git'; + stubSaveRequest(this.Urls.origin_save_request(badOriginType, originUrl), + badOriginType, 'rejected', + originUrl, 'not created', 403, saveCodeMsg['rejected']); + + makeOriginSaveRequest(badOriginType, originUrl); + + cy.wait('@saveRequest').then(() => { + cy.get('#swh-origin-save-requests-list-tab').click(); + 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)); + }); + }); + }); + }); diff --git a/swh/web/assets/src/bundles/save/index.js b/swh/web/assets/src/bundles/save/index.js --- a/swh/web/assets/src/bundles/save/index.js +++ b/swh/web/assets/src/bundles/save/index.js @@ -448,12 +448,22 @@ } export function fillSaveRequestFormAndScroll(visitType, originUrl) { + $('#swh-input-origin-url').val(originUrl); + let originTypeFound = false; $('#swh-input-visit-type option').each(function() { let val = $(this).val(); - if (val === visitType) { + if (val && originUrl.includes(val)) { $(this).prop('selected', true); + originTypeFound = true; } }); - $('#swh-input-origin-url').val(originUrl); + if (!originTypeFound) { + $('#swh-input-visit-type option').each(function() { + let val = $(this).val(); + if (val === visitType) { + $(this).prop('selected', true); + } + }); + } window.scrollTo(0, 0); }