restore closed overview sections before testing (https://github.com/woocommerce/woocommerce-admin/pull/7652)

* restore closed overview sections before testing

* add changelog entry
This commit is contained in:
Ron Rennick 2021-10-06 13:24:10 -03:00 committed by GitHub
parent f35fae4482
commit 5a8a019465
3 changed files with 40 additions and 31 deletions

View File

@ -2,6 +2,7 @@
- Add Customers to analytics pages tested #7573 - Add Customers to analytics pages tested #7573
- Add `waitForTimeout` utility function #7572 - Add `waitForTimeout` utility function #7572
- Update analytics overview tests to allow re-running the tests.
# 0.1.1 # 0.1.1

View File

@ -44,6 +44,13 @@ export class AnalyticsOverview extends Analytics {
return sections.filter( isSection ); return sections.filter( isSection );
} }
async getSectionTitles() {
const sections = ( await this.getSections() ).map(
( section ) => section.title
);
return sections;
}
async openSectionEllipsis( sectionTitle: string ) { async openSectionEllipsis( sectionTitle: string ) {
const section = ( await this.getSections() ).find( const section = ( await this.getSections() ).find(
( thisSection ) => thisSection.title === sectionTitle ( thisSection ) => thisSection.title === sectionTitle

View File

@ -11,44 +11,45 @@ const testAdminAnalyticsOverview = () => {
describe( 'Analytics pages', () => { describe( 'Analytics pages', () => {
const analyticsPage = new AnalyticsOverview( page ); const analyticsPage = new AnalyticsOverview( page );
const login = new Login( page ); const login = new Login( page );
const sectionTitles = [ 'Performance', 'Charts', 'Leaderboards' ];
const titlesString = sectionTitles.join( ', ' );
beforeAll( async () => { beforeAll( async () => {
await login.login(); await login.login();
await analyticsPage.navigate(); await analyticsPage.navigate();
await analyticsPage.isDisplayed(); 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 () => { afterAll( async () => {
await login.logout(); await login.logout();
} ); } );
it( 'a user should see 3 sections by default - Performance, Charts, and Leaderboards', async () => { it( `a user should see ${ sectionTitles.length } sections by default - ${ titlesString }`, async () => {
const sections = ( await analyticsPage.getSections() ).map( const sections = await analyticsPage.getSectionTitles();
( section ) => section.title for ( let t = 0; t < sectionTitles.length; t++ ) {
); expect( sections ).toContain( sectionTitles[ t ] );
expect( sections ).toContain( 'Performance' ); }
expect( sections ).toContain( 'Charts' );
expect( sections ).toContain( 'Leaderboards' );
} ); } );
it( 'should allow a user to remove a section', async () => { it( 'should allow a user to remove a section', async () => {
await analyticsPage.removeSection( 'Performance' ); await analyticsPage.removeSection( sectionTitles[ 0 ] );
const sections = ( await analyticsPage.getSections() ).map( const sections = await analyticsPage.getSectionTitles();
( section ) => section.title expect( sections ).not.toContain( sectionTitles[ 0 ] );
);
expect( sections ).not.toContain( 'Performance' );
} ); } );
it( 'should allow a user to add a section back in', async () => { it( 'should allow a user to add a section back in', async () => {
let sections = ( await analyticsPage.getSections() ).map( let sections = await analyticsPage.getSectionTitles();
( section ) => section.title expect( sections ).not.toContain( sectionTitles[ 0 ] );
); await analyticsPage.addSection( sectionTitles[ 0 ] );
expect( sections ).not.toContain( 'Performance' );
await analyticsPage.addSection( 'Performance' );
sections = ( await analyticsPage.getSections() ).map( sections = await analyticsPage.getSectionTitles();
( section ) => section.title expect( sections ).toContain( sectionTitles[ 0 ] );
);
expect( sections ).toContain( 'Performance' );
} ); } );
describe( 'moving sections', () => { describe( 'moving sections', () => {
@ -76,19 +77,19 @@ const testAdminAnalyticsOverview = () => {
} ); } );
it( 'should allow a user to move a section down', async () => { it( 'should allow a user to move a section down', async () => {
const sections = await analyticsPage.getSections(); const sections = await analyticsPage.getSectionTitles();
await analyticsPage.moveSectionDown( sections[ 0 ].title ); await analyticsPage.moveSectionDown( sections[ 0 ] );
const newSections = await analyticsPage.getSections(); const newSections = await analyticsPage.getSectionTitles();
expect( sections[ 0 ].title ).toEqual( newSections[ 1 ].title ); expect( sections[ 0 ] ).toEqual( newSections[ 1 ] );
expect( sections[ 1 ].title ).toEqual( newSections[ 0 ].title ); expect( sections[ 1 ] ).toEqual( newSections[ 0 ] );
} ); } );
it( 'should allow a user to move a section up', async () => { it( 'should allow a user to move a section up', async () => {
const sections = await analyticsPage.getSections(); const sections = await analyticsPage.getSectionTitles();
await analyticsPage.moveSectionUp( sections[ 1 ].title ); await analyticsPage.moveSectionUp( sections[ 1 ] );
const newSections = await analyticsPage.getSections(); const newSections = await analyticsPage.getSectionTitles();
expect( sections[ 0 ].title ).toEqual( newSections[ 1 ].title ); expect( sections[ 0 ] ).toEqual( newSections[ 1 ] );
expect( sections[ 1 ].title ).toEqual( newSections[ 0 ].title ); expect( sections[ 1 ] ).toEqual( newSections[ 0 ] );
} ); } );
} ); } );
} ); } );