diff --git a/web/cypress.config.ts b/web/cypress.config.ts index baf744ac4..8588f3846 100644 --- a/web/cypress.config.ts +++ b/web/cypress.config.ts @@ -9,6 +9,7 @@ export default defineConfig({ baseUrl: 'http://localhost:9000', video: false, defaultCommandTimeout: 25000, + retries: 3, setupNodeEvents(on, config) { // implement node event listeners here }, diff --git a/web/cypress/e2e/autopruning.cy.ts b/web/cypress/e2e/autopruning.cy.ts index f1ed720a7..38dbbda9e 100644 --- a/web/cypress/e2e/autopruning.cy.ts +++ b/web/cypress/e2e/autopruning.cy.ts @@ -262,6 +262,18 @@ describe('Namespace settings - autoprune policies', () => { // second policy form should not exist cy.get('#autoprune-policy-form-1').should('not.exist'); + + // Delete first policy + cy.get('#autoprune-policy-form-0').within(() => { + cy.get('[data-testid="auto-prune-method"]').select('None'); + cy.contains('Save').click(); + }); + + cy.contains('Successfully deleted auto-prune policy'); + cy.get('[data-testid="auto-prune-method"]').contains('None'); + + // second policy form should not exist + cy.get('#autoprune-policy-form-1').should('not.exist'); }); it('display multiple namespace auto-pruning policies', () => { diff --git a/web/cypress/e2e/repository-autopruning.cy.ts b/web/cypress/e2e/repository-autopruning.cy.ts index 1bf1f296e..707946bab 100644 --- a/web/cypress/e2e/repository-autopruning.cy.ts +++ b/web/cypress/e2e/repository-autopruning.cy.ts @@ -38,7 +38,7 @@ describe('Repository settings - Repository autoprune policies', () => { cy.contains('Successfully created repository auto-prune policy'); cy.get('input[aria-label="number of tags"]').should('have.value', '25'); - cy.contains('Add Policy').click(); + cy.contains('Add Policy').trigger('click'); cy.get('#autoprune-policy-form-1', {timeout: 3000}).should('be.visible'); // Create second policy @@ -281,5 +281,17 @@ describe('Repository settings - Repository autoprune policies', () => { // second policy form should not exist cy.get('#autoprune-policy-form-1').should('not.exist'); + + // Delete first policy + cy.get('#autoprune-policy-form-0').within(() => { + cy.get('[data-testid="auto-prune-method"]').select('None'); + cy.contains('Save').click(); + }); + + cy.contains('Successfully deleted repository auto-prune policy'); + cy.get('[data-testid="auto-prune-method"]').contains('None'); + + // second policy form should not exist + cy.get('#autoprune-policy-form-1').should('not.exist'); }); }); diff --git a/web/src/routes/OrganizationsList/Organization/Tabs/Settings/AutoPruning.tsx b/web/src/routes/OrganizationsList/Organization/Tabs/Settings/AutoPruning.tsx index ce6de71ce..10fd95651 100644 --- a/web/src/routes/OrganizationsList/Organization/Tabs/Settings/AutoPruning.tsx +++ b/web/src/routes/OrganizationsList/Organization/Tabs/Settings/AutoPruning.tsx @@ -60,11 +60,11 @@ export default function AutoPruning(props: AutoPruning) { useEffect(() => { if (successFetchingPolicies) { - if (nsPolicies.length > 0) { - setPolicies(nsPolicies); - } else { - addNewPolicy(); + if (nsPolicies.length == 0) { + addNewPolicy(true); + return; } + setPolicies(nsPolicies); } }, [successFetchingPolicies, dataUpdatedAt]); @@ -125,17 +125,29 @@ export default function AutoPruning(props: AutoPruning) { } }, [errorDeletePolicy]); - const addNewPolicy = () => { - setPolicies([ - ...policies, - { - method: AutoPruneMethod.NONE, - uuid: null, - value: null, - tagPattern: null, - tagPatternMatches: true, - }, - ]); + const addNewPolicy = (clear_existing = false) => { + if (clear_existing) { + setPolicies([ + { + method: AutoPruneMethod.NONE, + uuid: null, + value: null, + tagPattern: null, + tagPatternMatches: true, + }, + ]); + } else { + setPolicies([ + ...policies, + { + method: AutoPruneMethod.NONE, + uuid: null, + value: null, + tagPattern: null, + tagPatternMatches: true, + }, + ]); + } }; const onSave = (method, value, uuid, tagPattern, tagPatternMatches) => { @@ -201,7 +213,7 @@ export default function AutoPruning(props: AutoPruning) { /> ))}
- diff --git a/web/src/routes/RepositoryDetails/Settings/RepositoryAutoPruning.tsx b/web/src/routes/RepositoryDetails/Settings/RepositoryAutoPruning.tsx index 9e07f3add..8dd9ec36e 100644 --- a/web/src/routes/RepositoryDetails/Settings/RepositoryAutoPruning.tsx +++ b/web/src/routes/RepositoryDetails/Settings/RepositoryAutoPruning.tsx @@ -73,26 +73,38 @@ export default function RepositoryAutoPruning(props: RepositoryAutoPruning) { props.repoName, ); - const addNewPolicy = () => { - setPolicies([ - ...policies, - { - method: AutoPruneMethod.NONE, - uuid: null, - value: null, - tagPattern: null, - tagPatternMatches: true, - }, - ]); + const addNewPolicy = (clear_existing = false) => { + if (clear_existing) { + setPolicies([ + { + method: AutoPruneMethod.NONE, + uuid: null, + value: null, + tagPattern: null, + tagPatternMatches: true, + }, + ]); + } else { + setPolicies([ + ...policies, + { + method: AutoPruneMethod.NONE, + uuid: null, + value: null, + tagPattern: null, + tagPatternMatches: true, + }, + ]); + } }; useEffect(() => { if (successFetchingRepoPolicies) { - if (repoPolicies.length > 0) { - setPolicies(repoPolicies); - } else if (policies.length == 0) { - addNewPolicy(); + if (repoPolicies.length == 0) { + addNewPolicy(true); + return; } + setPolicies(repoPolicies); } }, [ successFetchingRepoPolicies, @@ -227,7 +239,7 @@ export default function RepositoryAutoPruning(props: RepositoryAutoPruning) { /> ))}
-