Skip to content

Commit 566d7b9

Browse files
authored
Merge pull request #273 from newfold-labs/fixn/link-prefetch-test
Fix Link Prefetch Test
2 parents 0dc64f2 + 9c20c23 commit 566d7b9

File tree

2 files changed

+33
-25
lines changed

2 files changed

+33
-25
lines changed

tests/cypress/integration/performance.cy.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ describe( 'Performance Page', { testIsolation: true }, () => {
6262
} );
6363

6464
it( 'Mouse down-> without exclude: Verify if "Link Prefetch" is displayed and intercept the network call', () => {
65+
cy.exec(
66+
`npx wp-env run cli wp option update _transient_nfd_site_capabilities '{"hasLinkPrefetchClick": true, "hasLinkPrefetchHover": true}' --format=json`
67+
);
68+
cy.reload();
6569
performanceLocators.verifyIfLinkPreFetchIsDisplayed();
6670
performanceLocators.verifyIfToggleIsEnabled();
6771
performanceLocators.interceptCallForMouseDownWithoutExcludeRunTimeURL(
@@ -90,33 +94,32 @@ describe( 'Performance Page', { testIsolation: true }, () => {
9094
`npx wp-env run cli wp option update nfd_link_prefetch_settings '{"activeOnDesktop": true, "behavior": "mouseDown"}' --format=json`
9195
);
9296
cy.exec(
93-
`npx wp-env run cli wp option update _transient_nfd_site_capabilities '{"hasLinkPrefetchClick": true, "hasLinkPrefetchHover": false}' --format=json`
97+
`npx wp-env run cli wp option update _transient_nfd_site_capabilities '{"hasLinkPrefetchClick": true, "hasLinkPrefetchHover": false}' --format=json`
9498
);
9599
cy.reload();
96100
performanceLocators.verifyIfLinkPreFetchIsDisplayed();
97101
performanceLocators.verifyIfToggleIsEnabled();
98-
performanceLocators.linkPrefetchCapabilityCheck('onlyMouseDown');
102+
performanceLocators.linkPrefetchCapabilityCheck( 'onlyMouseDown' );
99103
} );
100104

101105
it( 'hasLinkPrefetchHover capability', () => {
102106
cy.exec(
103-
`npx wp-env run cli wp option update nfd_link_prefetch_settings '{"activeOnDesktop": true, "behavior": "mouseHover"}' --format=json`
107+
`npx wp-env run cli wp option update nfd_link_prefetch_settings '{"activeOnDesktop": true, "behavior": "mouseHover"}' --format=json`
104108
);
105109
cy.exec(
106-
`npx wp-env run cli wp option update _transient_nfd_site_capabilities '{"hasLinkPrefetchClick": true, "hasLinkPrefetchHover": true}' --format=json`
110+
`npx wp-env run cli wp option update _transient_nfd_site_capabilities '{"hasLinkPrefetchClick": true, "hasLinkPrefetchHover": true}' --format=json`
107111
);
108112
cy.reload();
109113
performanceLocators.verifyIfLinkPreFetchIsDisplayed();
110114
performanceLocators.verifyIfToggleIsEnabled();
111-
performanceLocators.linkPrefetchCapabilityCheck('both');
115+
performanceLocators.linkPrefetchCapabilityCheck( 'both' );
112116
} );
113117

114118
it( 'LinkPrefetch Capabilities to false', () => {
115119
cy.exec(
116-
`npx wp-env run cli wp option update _transient_nfd_site_capabilities '{"hasLinkPrefetchClick": false, "hasLinkPrefetchHover": false}' --format=json`
120+
`npx wp-env run cli wp option update _transient_nfd_site_capabilities '{"hasLinkPrefetchClick": false, "hasLinkPrefetchHover": false}' --format=json`
117121
);
118122
cy.reload();
119123
cy.get( performanceLocators._linkPrefetchText ).should( 'not.exist' );
120124
} );
121-
122125
} );

tests/cypress/support/pageObjects/performancePage.js

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class performancePage {
44
// in site-info box
55
_visitSiteButton = '#wp-admin-bar-view-site a';
66
// sample page link on front end of site
7-
_samplePageButton = '.wp-block-pages-list__item__link[href*="sample-page"]';
7+
_samplePageButton = 'main a';
88
_linkPrefetchText = '[data-cy="link-prefetch-settings"]';
99
_dropDownForLinkPrefetch =
1010
'[data-cy="link-prefetch-behavior-desktop"] .nfd-select__button-label';
@@ -27,7 +27,7 @@ class performancePage {
2727
}
2828

2929
getSamplePageButton() {
30-
return cy.get( this._samplePageButton ).first();
30+
return cy.get( this._samplePageButton ).eq( 1 );
3131
}
3232

3333
getMouseHoverElement() {
@@ -146,22 +146,27 @@ class performancePage {
146146
linkPrefetchCapabilityCheck( type ) {
147147
this.getDropDownForLinkPrefetch().click();
148148
this.getDropDownForLinkPrefetch()
149-
.invoke( 'text' )
150-
.then( ( buttonLabel ) => {
151-
if ( 'onlyMouseDown' === type ) {
152-
cy.get('[data-cy="link-prefetch-behavior-desktop"] .nfd-select__options > li')
153-
.should('have.length', 1)
154-
.invoke('text')
155-
.then(itemText => {
156-
const trimmedText = itemText.trim();
157-
cy.log('Found element text:', trimmedText);
158-
expect(trimmedText).to.equal('Prefetch on Mouse Down');
159-
});
160-
} else {
161-
cy.get('[data-cy="link-prefetch-behavior-desktop"] .nfd-select__options > li')
162-
.should('have.length', 2);
163-
}
164-
});
149+
.invoke( 'text' )
150+
.then( ( buttonLabel ) => {
151+
if ( 'onlyMouseDown' === type ) {
152+
cy.get(
153+
'[data-cy="link-prefetch-behavior-desktop"] .nfd-select__options > li'
154+
)
155+
.should( 'have.length', 1 )
156+
.invoke( 'text' )
157+
.then( ( itemText ) => {
158+
const trimmedText = itemText.trim();
159+
cy.log( 'Found element text:', trimmedText );
160+
expect( trimmedText ).to.equal(
161+
'Prefetch on Mouse Down'
162+
);
163+
} );
164+
} else {
165+
cy.get(
166+
'[data-cy="link-prefetch-behavior-desktop"] .nfd-select__options > li'
167+
).should( 'have.length', 2 );
168+
}
169+
} );
165170
}
166171

167172
compareDropdownLabelAndSelectedOption() {

0 commit comments

Comments
 (0)