Skip to content

Commit 4f11660

Browse files
authored
fix: global search regression with wagtail 7.2 (#842)
`content_type` field was renamed to `_django_content_type` https://docs.wagtail.org/en/latest/releases/7.2.html#elasticsearch-and-opensearch-users-should-run-update-index-after-upgrading also adds simple e2e tests for global search
1 parent efdc6b6 commit 4f11660

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

django/home/jinja2/home/search.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
{% block content %}
1717
{% for result in results %}
18-
<div class="card">
18+
<div data-cy="search-result" class="card">
1919
<div class="card-header">{{ result.type.title() }} - <a href="{{ result.url }}">{{ result.title|default("Not
2020
available") }}</a></div>
2121
<div class="card-body">

django/home/search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020

2121
def get_content_type(result):
22-
content_type_strs = result["_source"]["content_type"]
22+
content_type_strs = result["_source"]["_django_content_type"]
2323
model = apps.get_model(content_type_strs[-1])
2424
return model
2525

e2e/cypress/tests/search.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { getDataCy } from "../support/util";
2+
3+
describe("Sitewide search tests", () => {
4+
it("should display search results for a common query", () => {
5+
cy.visit("/search/?query=model");
6+
// should have at least one result
7+
getDataCy("search-result").should("have.length.greaterThan", 0);
8+
});
9+
10+
it("should show no results message for nonsense query", () => {
11+
cy.visit("/search/?query=xyznonexistentquerythatshouldfindnothing123");
12+
// should have no results
13+
getDataCy("search-result").should("not.exist");
14+
});
15+
});

0 commit comments

Comments
 (0)