Skip to content

Commit

Permalink
Merge "Rewrite input tests to more generic selectors"
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed Sep 26, 2024
2 parents c745c94 + d186299 commit ead4cb9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
8 changes: 4 additions & 4 deletions cypress/e2e/component-interaction.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe( 'Component interaction test', () => {
cy.wait( '@hasPetRequest' );
cy.get( '.query-condition__property-lookup .wikit-OptionsMenu__item' ).click();

cy.get( '.query-condition__value-input .wikit-Input' )
cy.get( '.query-condition__value-input input' )
.type( 'house cat' );
cy.wait( '@houseCatRequest' );
cy.get( '.query-condition__value-input .wikit-OptionsMenu__item' )
Expand All @@ -84,7 +84,7 @@ describe( 'Component interaction test', () => {

// clear out values from specified input components
cy.get( '.query-condition__property-lookup .wikit-Input' ).clear();
cy.get( '.query-condition__value-input .wikit-Input' ).clear();
cy.get( '.query-condition__value-input input' ).clear();

// set value to 'not matching' from dropdown. NotMatching => 'without',
cy.get( '.querybuilder-dropdown .cdx-select-vue' ).first().click();
Expand All @@ -96,7 +96,7 @@ describe( 'Component interaction test', () => {

cy.get( '.query-condition__property-lookup .wikit-OptionsMenu__item' ).first().click();

cy.get( '.query-condition__value-input .wikit-Input' )
cy.get( '.query-condition__value-input input' )
.type( 'house cat' );
cy.wait( '@houseCatRequest' );

Expand Down Expand Up @@ -140,7 +140,7 @@ describe( 'Component interaction test', () => {
cy.get( '.query-condition__property-lookup:nth(1) .wikit-OptionsMenu__item' ).click();

// Assert input value component is disabled when user selects 'regardless of value'
cy.get( '.query-condition__value-input:nth(1) .wikit-Input' ).should( 'be.disabled' );
cy.get( '.query-condition__value-input:nth(1) input' ).should( 'be.disabled' );

// click 'Add condition' button and expand to a second block
cy.get( '.querybuilder__add-condition button' ).click();
Expand Down
18 changes: 15 additions & 3 deletions cypress/e2e/error-handling.cy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
// for some reason Cypress keeps quotes around env vars coming from docker through `.env`
const API_URL = Cypress.env( 'API_URL' ).replace( /(^')|('$)/g, '' );

// TODO: Rewrite these tests to use messages instead of class name selectors

// Ignore no-missing-require, as this is properly loads during tests
// eslint-disable-next-line n/no-missing-require
const messages = require( 'public/i18n/en.json' );

function wikibaseApiRequest( query ) {
return {
url: API_URL + '*',
Expand Down Expand Up @@ -44,7 +50,7 @@ describe( 'Test error handling of the Query Builder', () => {
cy.get( '.wikit.wikit-ValidationMessage.wikit-ValidationMessage--error' ).should( 'be.visible' );

// Add some value to the value input component
cy.get( '.query-condition__value-input .wikit-Input' )
cy.get( '.query-condition__value-input input' )
.type( 'house cat' );
cy.wait( '@houseCatRequest' );

Expand All @@ -63,8 +69,14 @@ describe( 'Test error handling of the Query Builder', () => {
cy.get( '.query-condition:nth(0) .wikit.wikit-ValidationMessage' )
.should( 'not.exist' );

cy.get( '.query-condition:nth(1) .wikit.wikit-ValidationMessage' )
.should( 'have.length', 2 )
cy.get( '.query-condition:nth(1)' )
.contains( messages[ 'query-builder-result-error-missing-property' ] )
.should( 'have.length', 1 )
.should( 'be.visible' );

cy.get( '.query-condition:nth(1)' )
.contains( messages[ 'query-builder-result-error-missing-value' ] )
.should( 'have.length', 1 )
.should( 'be.visible' );

// Delete the second query condition
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/restore-from-url.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe( 'restore state from URL', () => {
.then( ( element ) => {
expect( element[ 0 ].value ).to.equal( 'instance of' );
} );
cy.get( '.query-condition__value-input .wikit-Input' )
cy.get( '.query-condition__value-input input' )
.then( ( element ) => {
expect( element[ 0 ].value ).to.equal( 'house cat' );
} );
Expand Down

0 comments on commit ead4cb9

Please sign in to comment.