Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure fetch is not called when navigating backwards #11986

Merged
merged 5 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions cypress/e2e/tests/pages/explorer/apps/charts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,48 @@ describe('Apps/Charts', { tags: ['@explorer', '@adminUser'] }, () => {
// checking the warning banner to be visible
chartPage.deprecationAndExperimentalWarning().banner().should('exist').and('be.visible');
});

it('should call fetch when route query changes with valid parameters', () => {
const chartName = 'Logging';

chartsPage.getChartByName(chartName)
.should('exist')
.scrollIntoView()
.should('be.visible')
.click();

const chartPage = new ChartPage();

chartPage.waitForPage();

// Set up intercept for the network request triggered by $fetch
cy.intercept('GET', '**/v1/catalog.cattle.io.clusterrepos/**').as('fetchChartData');

chartPage.selectVersion('103.1.1+up4.4.0');

cy.wait('@fetchChartData').its('response.statusCode').should('eq', 200);
});

it('should not call fetch when navigating back to charts page', () => {
const chartName = 'Logging';

chartsPage.getChartByName(chartName)
.should('exist')
.scrollIntoView()
.should('be.visible')
.click();

const chartPage = new ChartPage();

chartPage.waitForPage();

// Navigate back to the charts page
cy.go('back');
chartsPage.waitForPage();

// Set up intercept after navigating back
cy.intercept('GET', '**/v1/catalog.cattle.io.clusterrepos/**').as('fetchChartDataAfterBack');

cy.get('@fetchChartDataAfterBack.all').should('have.length', 0);
});
});
4 changes: 3 additions & 1 deletion shell/pages/c/_cluster/apps/charts/chart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ export default {

watch: {
'$route.query'(neu, old) {
if ( !isEqual(neu, old) ) {
// If the query changes, refetch the chart
// When going back to app list, the query is empty and we don't want to refetch
if ( !isEqual(neu, old) && Object.keys(neu).length > 0 ) {
jordojordo marked this conversation as resolved.
Show resolved Hide resolved
this.$fetch();
}
},
Expand Down
4 changes: 3 additions & 1 deletion shell/pages/c/_cluster/apps/charts/install.vue
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,9 @@ export default {

watch: {
'$route.query'(neu, old) {
if ( !isEqual(neu, old) ) {
// If the query changes, refetch the chart
// When going back to app list, the query is empty and we don't want to refetch
if ( !isEqual(neu, old) && Object.keys(neu).length > 0 ) {
this.$fetch();
this.showSlideIn = false;
}
Expand Down
Loading