import { PageableRequest } from '@empathyco/x-adapter' ; import { Given , Then , When } from 'cypress-cucumber-preprocessor/steps' ; import '../cucumber/global-definitions' ; let resultsList = [ ] ; param facetName param nthFilter internal function clickFacetNthFilter ( facetName , nthFilter ) { getElementBy ( facetName ) . eq ( nthFilter ) . click ( ) . invoke ( 'text' ) . as ( `clickedFilter${ nthFilter }` ) ; } param facetName returns function getElementBy ( facetName ) { return facetName === 'hierarchical_category' ? cy . getByDataTest ( `${ facetName }-filter` ) . getByDataTest ( 'filter' ) : cy . getByDataTest ( `${ facetName }-filter` ) ; } Given ( 'no special config for layout view' , ( ) => { cy . visit ( '/?useMockedAdapter=true' ) ; } ) ; When ( 'start button is clicked' , ( ) => { cy . getByDataTest ( 'open-modal' ) . click ( ) ; } ) ; When ( 'filter number {int} is clicked in facet {string}' , ( filterNumber , facetName ) => { clickFacetNthFilter ( facetName , filterNumber ) ; } ) ; Then ( 'search request contains selected filter number {int} is {boolean}' , function ( this , simpleFilterIndex , isContained ) { cy . wait ( '@requestWithFilter' ) . its ( 'request.body' ) . should ( `${ isContained ? '' : 'not.' }contain` , this [ `clickedFilter${ simpleFilterIndex }` ] ) ; } ) ; Then ( 'selection status of filter number {int} in facet {string} is {boolean}' , function ( this , simpleFilterIndex , facetName , isSelected ) { cy . getByDataTest ( `${ facetName }-filter` ) . contains ( this [ `clickedFilter${ simpleFilterIndex }` ] ) . should ( `${ isSelected ? '' : 'not.' }to.have.class` , 'x-filter--is-selected' ) ; } ) ; When ( 'clear history queries button is clicked' , ( ) => { cy . getByDataTest ( 'clear-history-queries' ) . click ( ) ; } ) ; Then ( 'history queries are displayed' , ( ) => { cy . getByDataTest ( 'history-query' ) . should ( 'have.length.at.least' , 1 ) ; } ) ; Then ( 'the searched query is displayed in history queries' , function ( this ) { cy . getByDataTest ( 'history-query' ) . should ( 'have.length.at.least' , 1 ) . each ( historyQuery => expect ( historyQuery ) . to . contain ( this . searchedQuery ) ) . invoke ( 'text' ) . as ( 'historicalQuery' ) ; } ) ; Then ( 'next queries are displayed' , ( ) => { cy . getByDataTest ( 'next-query' ) . should ( 'have.length.at.least' , 1 ) . invoke ( 'text' ) . as ( 'nextQueries' ) ; } ) ; Then ( 'query suggestions are displayed' , ( ) => { cy . getByDataTest ( 'query-suggestion' ) . should ( 'have.length.at.least' , 1 ) ; } ) ; Then ( 'related tags are displayed' , ( ) => { cy . getByDataTest ( 'related-tag' ) . should ( 'have.length.at.least' , 1 ) ; } ) ; Then ( 'related results are displayed' , ( ) => { resultsList = [ ] ; cy . getByDataTest ( 'search-result' ) . should ( 'be.visible' ) . should ( 'have.length.at.least' , 1 ) . getByDataTest ( 'result-title' ) . each ( $resultTitle => { resultsList . push ( $resultTitle . text ( ) ) ; } ) ; } ) ; Then ( 'related results have changed' , ( ) => { cy . getByDataTest ( 'search-result' ) . should ( 'be.visible' ) . should ( $results => { const compoundResultsList = $results . toArray ( ) . map ( resultElement => resultElement . textContent ) ; expect ( compoundResultsList . every ( item => resultsList . includes ( item ! ) ) ) . to . eq ( false ) ; } ) ; } ) ; When ( 'search-input is focused' , ( ) => { cy . focusSearchInput ( ) ; } ) ; When ( 'a {string} with results is typed' , ( query ) => { cy . typeQuery ( query ) . then ( ( ) => { cy . getByDataTest ( 'search-input' ) . invoke ( 'val' ) . as ( 'searchedQuery' ) ; } ) ; } ) ; When ( '{string} is searched' , ( query ) => { cy . searchQuery ( query ) . then ( ( ) => { cy . getByDataTest ( 'search-input' ) . invoke ( 'val' ) . as ( 'searchedQuery' ) ; } ) ; } ) ; When ( 'clear search button is pressed' , ( ) => { cy . clearSearchInput ( ) ; } ) ; Then ( 'the searched query is displayed in the search-box' , function ( this ) { cy . getByDataTest ( 'search-input' ) . should ( 'have.value' , this . searchedQuery ) ; } ) ; Then ( 'number of rows requested in {string} is {int}' , ( request , maxItemsToRequest ) => { cy . wait ( `@${ request }` ) . then ( ( { request } ) => { const { rows } = JSON . parse ( request . body ) as PageableRequest ; expect ( rows ) . to . equal ( maxItemsToRequest ) ; } ) ; } ) ; When ( 'tab is reloaded' , ( ) => { cy . reload ( ) ; } ) ;