Skip to content

Commit 9418d35

Browse files
authored
Merge pull request #253 from newfold-labs/enhance/PRESS7-471-Integrate-Cypress-LinkPrefetch-with-Capabilities
LinkPrefetch - Add tests for Capabilities
2 parents 40c8d66 + 42155ef commit 9418d35

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

tests/cypress/integration/performance.cy.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,39 @@ describe( 'Performance Page', { testIsolation: true }, () => {
8484
data.requestCount
8585
);
8686
} );
87+
88+
it( 'hasLinkPrefetchClick capability', () => {
89+
cy.exec(
90+
`npx wp-env run cli wp option update nfd_link_prefetch_settings '{"activeOnDesktop": true, "behavior": "mouseDown"}' --format=json`
91+
);
92+
cy.exec(
93+
`npx wp-env run cli wp option update _transient_nfd_site_capabilities '{"hasLinkPrefetchClick": true, "hasLinkPrefetchHover": false}' --format=json`
94+
);
95+
cy.reload();
96+
performanceLocators.verifyIfLinkPreFetchIsDisplayed();
97+
performanceLocators.verifyIfToggleIsEnabled();
98+
performanceLocators.linkPrefetchCapabilityCheck('onlyMouseDown');
99+
} );
100+
101+
it( 'hasLinkPrefetchHover capability', () => {
102+
cy.exec(
103+
`npx wp-env run cli wp option update nfd_link_prefetch_settings '{"activeOnDesktop": true, "behavior": "mouseHover"}' --format=json`
104+
);
105+
cy.exec(
106+
`npx wp-env run cli wp option update _transient_nfd_site_capabilities '{"hasLinkPrefetchClick": true, "hasLinkPrefetchHover": true}' --format=json`
107+
);
108+
cy.reload();
109+
performanceLocators.verifyIfLinkPreFetchIsDisplayed();
110+
performanceLocators.verifyIfToggleIsEnabled();
111+
performanceLocators.linkPrefetchCapabilityCheck('both');
112+
} );
113+
114+
it( 'LinkPrefetch Capabilities to false', () => {
115+
cy.exec(
116+
`npx wp-env run cli wp option update _transient_nfd_site_capabilities '{"hasLinkPrefetchClick": false, "hasLinkPrefetchHover": false}' --format=json`
117+
);
118+
cy.reload();
119+
cy.get( performanceLocators._linkPrefetchText ).should( 'not.exist' );
120+
} );
121+
87122
} );

tests/cypress/support/pageObjects/performancePage.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,27 @@ class performancePage {
106106
this.getDesktopToggle().should( 'have.attr', 'aria-checked', 'true' );
107107
}
108108

109+
linkPrefetchCapabilityCheck( type ) {
110+
this.getDropDownForLinkPrefetch().click();
111+
this.getDropDownForLinkPrefetch()
112+
.invoke( 'text' )
113+
.then( ( buttonLabel ) => {
114+
if ( 'onlyMouseDown' === type ) {
115+
cy.get('[data-cy="link-prefetch-behavior-desktop"] .nfd-select__options > li')
116+
.should('have.length', 1)
117+
.invoke('text')
118+
.then(itemText => {
119+
const trimmedText = itemText.trim();
120+
cy.log('Found element text:', trimmedText);
121+
expect(trimmedText).to.equal('Prefetch on Mouse Down');
122+
});
123+
} else {
124+
cy.get('[data-cy="link-prefetch-behavior-desktop"] .nfd-select__options > li')
125+
.should('have.length', 2);
126+
}
127+
});
128+
}
129+
109130
compareDropdownLabelAndSelectedOption() {
110131
// Get the text from the dropdown button label
111132
this.getDropDownForLinkPrefetch()

0 commit comments

Comments
 (0)