From 5a8a019465fc04f553ab750bcb29928f9ef06f30 Mon Sep 17 00:00:00 2001 From: Ron Rennick Date: Wed, 6 Oct 2021 13:24:10 -0300 Subject: [PATCH] restore closed overview sections before testing (https://github.com/woocommerce/woocommerce-admin/pull/7652) * restore closed overview sections before testing * add changelog entry --- .../packages/admin-e2e-tests/CHANGELOG.md | 1 + .../src/pages/AnalyticsOverview.ts | 7 +++ .../src/specs/analytics/analytics-overview.ts | 63 ++++++++++--------- 3 files changed, 40 insertions(+), 31 deletions(-) diff --git a/plugins/woocommerce-admin/packages/admin-e2e-tests/CHANGELOG.md b/plugins/woocommerce-admin/packages/admin-e2e-tests/CHANGELOG.md index 6dfb886f341..63d6e492b10 100644 --- a/plugins/woocommerce-admin/packages/admin-e2e-tests/CHANGELOG.md +++ b/plugins/woocommerce-admin/packages/admin-e2e-tests/CHANGELOG.md @@ -2,6 +2,7 @@ - Add Customers to analytics pages tested #7573 - Add `waitForTimeout` utility function #7572 +- Update analytics overview tests to allow re-running the tests. # 0.1.1 diff --git a/plugins/woocommerce-admin/packages/admin-e2e-tests/src/pages/AnalyticsOverview.ts b/plugins/woocommerce-admin/packages/admin-e2e-tests/src/pages/AnalyticsOverview.ts index 181ade843c8..ac3d7dcc82a 100644 --- a/plugins/woocommerce-admin/packages/admin-e2e-tests/src/pages/AnalyticsOverview.ts +++ b/plugins/woocommerce-admin/packages/admin-e2e-tests/src/pages/AnalyticsOverview.ts @@ -44,6 +44,13 @@ export class AnalyticsOverview extends Analytics { return sections.filter( isSection ); } + async getSectionTitles() { + const sections = ( await this.getSections() ).map( + ( section ) => section.title + ); + return sections; + } + async openSectionEllipsis( sectionTitle: string ) { const section = ( await this.getSections() ).find( ( thisSection ) => thisSection.title === sectionTitle diff --git a/plugins/woocommerce-admin/packages/admin-e2e-tests/src/specs/analytics/analytics-overview.ts b/plugins/woocommerce-admin/packages/admin-e2e-tests/src/specs/analytics/analytics-overview.ts index c6321c6a6c4..2e47c12f794 100644 --- a/plugins/woocommerce-admin/packages/admin-e2e-tests/src/specs/analytics/analytics-overview.ts +++ b/plugins/woocommerce-admin/packages/admin-e2e-tests/src/specs/analytics/analytics-overview.ts @@ -11,44 +11,45 @@ const testAdminAnalyticsOverview = () => { describe( 'Analytics pages', () => { const analyticsPage = new AnalyticsOverview( page ); const login = new Login( page ); + const sectionTitles = [ 'Performance', 'Charts', 'Leaderboards' ]; + const titlesString = sectionTitles.join( ', ' ); beforeAll( async () => { await login.login(); await analyticsPage.navigate(); await analyticsPage.isDisplayed(); + // Restore original order to sections + for ( let t = 0; t < sectionTitles.length; t++ ) { + const visibleSections = await analyticsPage.getSectionTitles(); + if ( visibleSections.indexOf( sectionTitles[ t ] ) < 0 ) { + await analyticsPage.addSection( sectionTitles[ t ] ); + } + } } ); afterAll( async () => { await login.logout(); } ); - it( 'a user should see 3 sections by default - Performance, Charts, and Leaderboards', async () => { - const sections = ( await analyticsPage.getSections() ).map( - ( section ) => section.title - ); - expect( sections ).toContain( 'Performance' ); - expect( sections ).toContain( 'Charts' ); - expect( sections ).toContain( 'Leaderboards' ); + it( `a user should see ${ sectionTitles.length } sections by default - ${ titlesString }`, async () => { + const sections = await analyticsPage.getSectionTitles(); + for ( let t = 0; t < sectionTitles.length; t++ ) { + expect( sections ).toContain( sectionTitles[ t ] ); + } } ); it( 'should allow a user to remove a section', async () => { - await analyticsPage.removeSection( 'Performance' ); - const sections = ( await analyticsPage.getSections() ).map( - ( section ) => section.title - ); - expect( sections ).not.toContain( 'Performance' ); + await analyticsPage.removeSection( sectionTitles[ 0 ] ); + const sections = await analyticsPage.getSectionTitles(); + expect( sections ).not.toContain( sectionTitles[ 0 ] ); } ); it( 'should allow a user to add a section back in', async () => { - let sections = ( await analyticsPage.getSections() ).map( - ( section ) => section.title - ); - expect( sections ).not.toContain( 'Performance' ); - await analyticsPage.addSection( 'Performance' ); + let sections = await analyticsPage.getSectionTitles(); + expect( sections ).not.toContain( sectionTitles[ 0 ] ); + await analyticsPage.addSection( sectionTitles[ 0 ] ); - sections = ( await analyticsPage.getSections() ).map( - ( section ) => section.title - ); - expect( sections ).toContain( 'Performance' ); + sections = await analyticsPage.getSectionTitles(); + expect( sections ).toContain( sectionTitles[ 0 ] ); } ); describe( 'moving sections', () => { @@ -76,19 +77,19 @@ const testAdminAnalyticsOverview = () => { } ); it( 'should allow a user to move a section down', async () => { - const sections = await analyticsPage.getSections(); - await analyticsPage.moveSectionDown( sections[ 0 ].title ); - const newSections = await analyticsPage.getSections(); - expect( sections[ 0 ].title ).toEqual( newSections[ 1 ].title ); - expect( sections[ 1 ].title ).toEqual( newSections[ 0 ].title ); + const sections = await analyticsPage.getSectionTitles(); + await analyticsPage.moveSectionDown( sections[ 0 ] ); + const newSections = await analyticsPage.getSectionTitles(); + expect( sections[ 0 ] ).toEqual( newSections[ 1 ] ); + expect( sections[ 1 ] ).toEqual( newSections[ 0 ] ); } ); it( 'should allow a user to move a section up', async () => { - const sections = await analyticsPage.getSections(); - await analyticsPage.moveSectionUp( sections[ 1 ].title ); - const newSections = await analyticsPage.getSections(); - expect( sections[ 0 ].title ).toEqual( newSections[ 1 ].title ); - expect( sections[ 1 ].title ).toEqual( newSections[ 0 ].title ); + const sections = await analyticsPage.getSectionTitles(); + await analyticsPage.moveSectionUp( sections[ 1 ] ); + const newSections = await analyticsPage.getSectionTitles(); + expect( sections[ 0 ] ).toEqual( newSections[ 1 ] ); + expect( sections[ 1 ] ).toEqual( newSections[ 0 ] ); } ); } ); } );