Skip to content

Commit f83f806

Browse files
committed
Add new highlight cypress tests
1 parent da38f34 commit f83f806

File tree

2 files changed

+58
-9
lines changed

2 files changed

+58
-9
lines changed

cypress/e2e/simple-jekyll-search.cy.ts

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ describe('Simple Jekyll Search', () => {
2525

2626
it('No results found', () => {
2727
cy.get('#search-input')
28-
.type('random');
28+
.type('xyzabc123notfound');
2929

3030
cy.get('#results-container')
31-
.contains('No results found');
31+
.should('contain', 'No results found');
3232
});
3333

3434
describe('Search Functionality Edge cases', () => {
@@ -61,24 +61,73 @@ describe('Simple Jekyll Search', () => {
6161
});
6262
});
6363

64-
describe('Highlighting Middleware', () => {
65-
it('should highlight search terms in results', () => {
64+
describe('Hybrid Strategy with Highlighting', () => {
65+
it('should use literal search and highlight exact matches', () => {
6666
cy.get('#search-input')
6767
.type('Lorem');
6868

6969
cy.get('#results-container')
7070
.should('be.visible');
7171

72+
// Should find the "This is just a test" post
73+
cy.get('#results-container').contains('This is just a test').should('exist');
74+
7275
cy.get('#results-container .search-desc .search-highlight')
7376
.should('exist')
7477
.should('have.css', 'background-color', 'rgb(255, 255, 0)');
7578

79+
// Find highlights that contain Lorem (may be in multiple results)
80+
cy.get('#results-container .search-desc .search-highlight')
81+
.filter(':contains("Lorem")')
82+
.should('have.length.at.least', 1);
83+
});
84+
85+
it('should use literal search for multi-word queries and highlight', () => {
86+
cy.get('#search-input')
87+
.type('Lorem ipsum');
88+
89+
cy.get('#results-container')
90+
.should('be.visible');
91+
92+
// Should find the "This is just a test" post
93+
cy.get('#results-container').contains('This is just a test').should('exist');
94+
95+
cy.get('#results-container .search-desc .search-highlight')
96+
.should('have.length.at.least', 1);
97+
98+
// Check that Lorem is highlighted somewhere in the results
7699
cy.get('#results-container .search-desc .search-highlight')
77-
.first()
78-
.should('contain', 'Lorem');
100+
.filter(':contains("Lorem")')
101+
.should('exist');
102+
});
103+
104+
it('should handle different search patterns with hybrid strategy', () => {
105+
// Test single word search (uses fuzzy/literal)
106+
cy.get('#search-input')
107+
.clear()
108+
.type('ipsum');
109+
110+
cy.get('#results-container li')
111+
.should('have.length.at.least', 1);
112+
113+
cy.get('#results-container')
114+
.should('contain.text', 'ipsum');
115+
});
116+
117+
it('should handle partial matches with hybrid strategy', () => {
118+
// Test another single word
119+
cy.get('#search-input')
120+
.clear()
121+
.type('technical');
122+
123+
cy.get('#results-container li')
124+
.should('have.length.at.least', 1);
125+
126+
cy.get('#results-container')
127+
.should('contain.text', 'Technical');
79128
});
80129

81-
it('should highlight multiple occurrences', () => {
130+
it('should highlight multiple occurrences in literal search', () => {
82131
cy.get('#search-input')
83132
.type('test');
84133

docs/_includes/search.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<ul id="results-container"></ul>
55
</div>
66

7-
<script src="{{ '/assets/js/simple-jekyll-search.min.js' | relative_url }}"></script>
7+
<script src="{{ '/assets/js/simple-jekyll-search.min.js' | relative_url }}?v={{ site.time | date: '%s' }}"></script>
88

99
<script>
1010
var highlightMiddleware = window.createHighlightTemplateMiddleware({
@@ -20,7 +20,7 @@
2020
templateMiddleware: highlightMiddleware,
2121
noResultsText: 'No results found',
2222
limit: 10,
23-
strategy: 'wildcard',
23+
strategy: 'hybrid',
2424
exclude: ['Welcome'],
2525
});
2626
</script>

0 commit comments

Comments
 (0)