mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-25 10:03:45 +03:00
tests: add more search tests
This commit is contained in:
parent
5b136c1a2f
commit
0fa72a55ce
|
@ -1,38 +1,55 @@
|
||||||
describe('Search', () => {
|
describe('Search', () => {
|
||||||
before(() => {
|
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(() => {
|
||||||
cy.visit('e2e/standalone.html');
|
cy.visit('e2e/standalone.html');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be closed by default', function() {
|
it('should correctly show and hide search results box', function() {
|
||||||
cy
|
getSearchResults().should('not.exist');
|
||||||
.get('.menu-content div')
|
|
||||||
.filter('.search-box')
|
|
||||||
.should('have.length', 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not open for less than 3 symbols', function() {
|
// should not open for less than 3 symbols
|
||||||
cy.get('.search-input').type('in', { force: true });
|
getSearchInput().type('in', { force: true });
|
||||||
cy
|
getSearchResults().should('not.exist');
|
||||||
.get('.menu-content div')
|
|
||||||
.filter('.search-box')
|
|
||||||
.should('have.length', 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should find 3 results when typed int', function() {
|
getSearchInput().type('t', { force: true });
|
||||||
cy.get('.search-input').type('t', { force: true });
|
|
||||||
cy
|
cy
|
||||||
.get('.search-results')
|
.get('[role=search] [role=menuitem]')
|
||||||
.find('li')
|
|
||||||
.should('have.length', 3)
|
.should('have.length', 3)
|
||||||
.first()
|
.first()
|
||||||
.should('contain', 'Introduction');
|
.should('contain', 'Introduction');
|
||||||
|
|
||||||
|
getSearchInput().type('{esc}', { force: true });
|
||||||
|
getSearchResults().should('not.exist');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should clear when ESQ is pressed', function() {
|
it('should support arrow navigation', function() {
|
||||||
cy.get('.search-input').type('{esc}', { force: true });
|
getSearchInput().type('int', { force: true });
|
||||||
cy
|
|
||||||
.get('.menu-content div')
|
getSearchInput().type('{downarrow}', { force: true });
|
||||||
.filter('.search-box')
|
getResult(0).should('have.class', 'active');
|
||||||
.should('have.length', 0);
|
|
||||||
|
getSearchInput().type('{downarrow}', { force: true });
|
||||||
|
getResult(1).should('have.class', 'active');
|
||||||
|
getResult(0).should('not.have.class', 'active');
|
||||||
|
|
||||||
|
getSearchInput().type('{uparrow}', { force: true });
|
||||||
|
getResult(1).should('not.have.class', 'active');
|
||||||
|
getResult(0).should('have.class', 'active');
|
||||||
|
|
||||||
|
getSearchInput().type('{uparrow}', { force: true });
|
||||||
|
getResult(0).should('have.class', 'active');
|
||||||
|
|
||||||
|
getSearchInput().type('{enter}', { force: true });
|
||||||
|
|
||||||
|
cy.contains('[role=navigation] [role=menuitem]', 'Introduction').should('have.class', 'active');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should mark search results', function() {
|
||||||
|
cy.get('[data-markjs]').should('not.exist');
|
||||||
|
getSearchInput().type('int', { force: true });
|
||||||
|
cy.get('[data-markjs]').should('exist');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user