2018-02-17 22:27:15 +03:00
|
|
|
describe('Search', () => {
|
2018-03-19 17:34:37 +03:00
|
|
|
const getSearchInput = () => cy.get('[role="search"] input');
|
|
|
|
const getSearchResults = () => cy.get('[data-role="search:results"]');
|
|
|
|
const getResult = i => cy.get('[role=search] [role=menuitem]').eq(i);
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2018-02-17 22:27:15 +03:00
|
|
|
cy.visit('e2e/standalone.html');
|
|
|
|
});
|
|
|
|
|
2018-07-16 18:29:36 +03:00
|
|
|
it('should correctly show and hide search results box', () => {
|
2018-03-19 17:34:37 +03:00
|
|
|
getSearchResults().should('not.exist');
|
2018-02-17 22:27:15 +03:00
|
|
|
|
2018-03-19 17:34:37 +03:00
|
|
|
// should not open for less than 3 symbols
|
2018-07-18 13:05:19 +03:00
|
|
|
getSearchInput().type('in', { force: true });
|
2018-03-19 17:34:37 +03:00
|
|
|
getSearchResults().should('not.exist');
|
2018-02-17 22:27:15 +03:00
|
|
|
|
2018-07-18 13:05:19 +03:00
|
|
|
getSearchInput().type('t', { force: true });
|
2018-07-16 18:29:36 +03:00
|
|
|
cy.get('[role=search] [role=menuitem]')
|
2018-02-17 22:27:15 +03:00
|
|
|
.should('have.length', 3)
|
|
|
|
.first()
|
|
|
|
.should('contain', 'Introduction');
|
2018-03-19 17:34:37 +03:00
|
|
|
|
2018-07-18 13:05:19 +03:00
|
|
|
getSearchInput().type('{esc}', { force: true });
|
2018-03-19 17:34:37 +03:00
|
|
|
getSearchResults().should('not.exist');
|
2018-02-17 22:27:15 +03:00
|
|
|
});
|
|
|
|
|
2018-07-16 18:29:36 +03:00
|
|
|
it('should support arrow navigation', () => {
|
2018-07-18 13:05:19 +03:00
|
|
|
getSearchInput().type('int', { force: true });
|
2018-03-19 17:34:37 +03:00
|
|
|
|
2020-03-16 17:01:21 +03:00
|
|
|
cy.wait(500);
|
|
|
|
|
2018-07-18 13:05:19 +03:00
|
|
|
getSearchInput().type('{downarrow}', { force: true });
|
2018-03-19 17:34:37 +03:00
|
|
|
getResult(0).should('have.class', 'active');
|
|
|
|
|
2018-07-18 13:05:19 +03:00
|
|
|
getSearchInput().type('{downarrow}', { force: true });
|
2018-03-19 17:34:37 +03:00
|
|
|
getResult(1).should('have.class', 'active');
|
|
|
|
getResult(0).should('not.have.class', 'active');
|
|
|
|
|
2018-07-18 13:05:19 +03:00
|
|
|
getSearchInput().type('{uparrow}', { force: true });
|
2018-03-19 17:34:37 +03:00
|
|
|
getResult(1).should('not.have.class', 'active');
|
|
|
|
getResult(0).should('have.class', 'active');
|
|
|
|
|
2018-07-18 13:05:19 +03:00
|
|
|
getSearchInput().type('{uparrow}', { force: true });
|
2018-03-19 17:34:37 +03:00
|
|
|
getResult(0).should('have.class', 'active');
|
|
|
|
|
2018-07-18 13:05:19 +03:00
|
|
|
getSearchInput().type('{enter}', { force: true });
|
2018-03-19 17:34:37 +03:00
|
|
|
|
2022-06-20 13:30:25 +03:00
|
|
|
cy.contains('[role=menu] [role=menuitem]', 'Introduction').should('have.class', 'active');
|
2018-03-19 17:34:37 +03:00
|
|
|
});
|
|
|
|
|
2018-07-16 18:29:36 +03:00
|
|
|
it('should mark search results', () => {
|
2018-03-19 17:34:37 +03:00
|
|
|
cy.get('[data-markjs]').should('not.exist');
|
2018-07-18 13:05:19 +03:00
|
|
|
getSearchInput().type('int', { force: true });
|
2018-03-19 17:34:37 +03:00
|
|
|
cy.get('[data-markjs]').should('exist');
|
2018-02-17 22:27:15 +03:00
|
|
|
});
|
2021-10-11 17:34:20 +03:00
|
|
|
|
|
|
|
it('should show proper message when no search results are found', () => {
|
|
|
|
getSearchResults().should('not.exist');
|
2022-01-05 18:11:05 +03:00
|
|
|
getSearchInput().type('xzss', { force: true });
|
2021-10-11 17:34:20 +03:00
|
|
|
getSearchResults().should('exist').should('contain', 'No results found');
|
2022-01-05 18:11:05 +03:00
|
|
|
});
|
2022-09-06 12:24:55 +03:00
|
|
|
|
|
|
|
it('should allow search by path or keywords in path', () => {
|
|
|
|
getSearchInput().clear().type('uploadImage', { force: true });
|
|
|
|
cy.get('[role=search] [role=menuitem]')
|
|
|
|
.should('have.length', 1)
|
|
|
|
.first()
|
|
|
|
.should('contain', 'uploads an image');
|
|
|
|
|
|
|
|
getSearchInput()
|
|
|
|
.clear()
|
|
|
|
.type('/pet/{petId}/uploadImage', { force: true, parseSpecialCharSequences: false });
|
|
|
|
cy.get('[role=search] [role=menuitem]')
|
|
|
|
.should('have.length', 1)
|
|
|
|
.first()
|
|
|
|
.should('contain', 'uploads an image');
|
|
|
|
});
|
2018-02-17 22:27:15 +03:00
|
|
|
});
|