-
Notifications
You must be signed in to change notification settings - Fork 35
Check and redirect to search query from 404 page, if results exist #1291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jcscottiii
merged 7 commits into
GoogleChrome:main
from
suprith-hub:show-similar-results-404-page
Apr 18, 2025
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
94028d6
Check and redirect to search query from 404 page, if results exist
suprith-hub f4cd864
Add tests and 404 html page
suprith-hub 1310faf
Combine tests and implement lit tasks for similar features fetch
suprith-hub bacb36b
Move e2e 404 test utility functions to specific file
suprith-hub dd8aed6
Refactor redeability webstatus not found error page
suprith-hub b94ca9e
Linting fix 404 page playwright tests
suprith-hub cf7d186
Use mock API in unit tests, typo correction 404 page
suprith-hub File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
-289 Bytes
(98%)
e2e/tests/404.spec.ts-snapshots/not-found-error-page-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-215 Bytes
(99%)
e2e/tests/404.spec.ts-snapshots/not-found-error-page-firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+24.8 KB
...s/404.spec.ts-snapshots/not-found-error-page-similar-results-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+35.2 KB
...ts/404.spec.ts-snapshots/not-found-error-page-similar-results-firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+27.2 KB
...sts/404.spec.ts-snapshots/not-found-error-page-similar-results-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+49 Bytes
(100%)
e2e/tests/404.spec.ts-snapshots/not-found-error-page-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
176 changes: 176 additions & 0 deletions
176
frontend/src/static/js/components/test/webstatus-notfound-error-page.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,176 @@ | ||
| /** | ||
| * Copyright 2025 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import {expect, fixture, html} from '@open-wc/testing'; | ||
| import '../webstatus-not-found-error-page.js'; | ||
| import {WebstatusNotFoundErrorPage} from '../webstatus-notfound-error-page.js'; | ||
| import {Task} from '@lit/task'; | ||
| import {APIClient} from '../../contexts/api-client-context.js'; | ||
|
|
||
| type SimilarFeature = {name: string; url: string}; | ||
|
|
||
| const GITHUB_REPO_ISSUE_LINK = 'https://github.com/example/repo/issues'; | ||
|
|
||
| describe('webstatus-not-found-error-page', () => { | ||
| it('renders the correct error message when featureId is missing', async () => { | ||
| const component = await fixture<WebstatusNotFoundErrorPage>( | ||
| html`<webstatus-not-found-error-page></webstatus-not-found-error-page>`, | ||
| ); | ||
|
|
||
| expect( | ||
| component.shadowRoot | ||
| ?.querySelector('#error-status-code') | ||
| ?.textContent?.trim(), | ||
| ).to.equal('404'); | ||
|
|
||
| expect( | ||
| component.shadowRoot | ||
| ?.querySelector('#error-headline') | ||
| ?.textContent?.trim(), | ||
| ).to.equal('Page not found'); | ||
|
|
||
| expect( | ||
| component.shadowRoot | ||
| ?.querySelector('#error-detailed-message .error-message') | ||
| ?.textContent?.trim(), | ||
| ).to.equal("We couldn't find the page you're looking for."); | ||
| }); | ||
|
|
||
| it('renders the correct error message when featureId is provided', async () => { | ||
| const component = await fixture<WebstatusNotFoundErrorPage>(html` | ||
| <webstatus-not-found-error-page | ||
| .location=${{search: '?q=test-feature'}} | ||
| ></webstatus-not-found-error-page> | ||
| `); | ||
|
|
||
| expect( | ||
| component.shadowRoot?.querySelector('#error-detailed-message') | ||
| ?.textContent, | ||
| ).to.include('We could not find Feature ID: test-feature'); | ||
| }); | ||
|
|
||
| it('displays "Loading similar features..." when the API request is pending', async () => { | ||
| const component = await fixture<WebstatusNotFoundErrorPage>(html` | ||
| <webstatus-not-found-error-page | ||
| .location=${{search: '?q=test-feature'}} | ||
| ></webstatus-not-found-error-page> | ||
| `); | ||
|
|
||
| // Override the _similarResults with a fake pending Task | ||
| component._similarResults = new Task(component, { | ||
| args: () => [undefined as unknown as APIClient, 'test-feature'], // no-op args | ||
| task: async () => { | ||
| return new Promise(() => {}); // never resolves = stays pending | ||
| }, | ||
| }); | ||
|
|
||
| // Trigger the task manually | ||
| component._similarResults.run(); | ||
| await component.updateComplete; | ||
|
|
||
| const loadingMessage = | ||
| component.shadowRoot?.querySelector('.loading-message'); | ||
| expect(loadingMessage).to.exist; | ||
| expect(loadingMessage?.textContent?.trim()).to.equal( | ||
| 'Loading similar features...', | ||
| ); | ||
| }); | ||
|
|
||
| it('renders similar features when API returns results', async () => { | ||
| const mockData = [ | ||
| {name: 'Feature One', url: '/features/dignissimos44'}, | ||
| {name: 'Feature Two', url: '/features/fugiat37'}, | ||
| ]; | ||
|
|
||
| const component = await fixture<WebstatusNotFoundErrorPage>(html` | ||
| <webstatus-not-found-error-page | ||
| .location=${{search: '?q=g'}} | ||
| ></webstatus-not-found-error-page> | ||
| `); | ||
|
|
||
| // Patch _similarResults manually | ||
| component._similarResults = new Task<[APIClient, string], SimilarFeature[]>( | ||
| component, | ||
| { | ||
| args: () => [undefined as unknown as APIClient, 'g'], | ||
| task: async () => mockData, | ||
| }, | ||
| ); | ||
|
|
||
| component._similarResults.run(); // force task to execute | ||
| await component.updateComplete; | ||
|
|
||
| const featureList = | ||
| component.shadowRoot?.querySelectorAll('.feature-list li'); | ||
| expect(featureList?.length).to.equal(2); | ||
| expect(featureList?.[0]?.textContent?.trim()).to.equal('Feature One'); | ||
| expect(featureList?.[1]?.textContent?.trim()).to.equal('Feature Two'); | ||
| }); | ||
|
|
||
| it('renders all three buttons when featureId and similar results exist', async () => { | ||
| const component = await fixture<WebstatusNotFoundErrorPage>(html` | ||
| <webstatus-not-found-error-page | ||
| .location=${{search: '?q=g'}} | ||
| ></webstatus-not-found-error-page> | ||
| `); | ||
|
|
||
| expect(component.shadowRoot?.querySelector('#error-action-search-btn')).to | ||
| .exist; | ||
| expect(component.shadowRoot?.querySelector('#error-action-home-btn')).to | ||
| .exist; | ||
| expect(component.shadowRoot?.querySelector('#error-action-report')).to | ||
| .exist; | ||
| }); | ||
|
|
||
| it('renders only two buttons when featureId does not exist', async () => { | ||
| const component = await fixture<WebstatusNotFoundErrorPage>(html` | ||
| <webstatus-not-found-error-page | ||
| .location=${{search: ''}} | ||
| ></webstatus-not-found-error-page> | ||
| `); | ||
|
|
||
| expect(component.shadowRoot?.querySelector('#error-action-search-btn')).to | ||
| .not.exist; | ||
| expect(component.shadowRoot?.querySelector('#error-action-home-btn')).to | ||
| .exist; | ||
| expect(component.shadowRoot?.querySelector('#error-action-report')).to | ||
| .exist; | ||
| }); | ||
|
|
||
| it('search button contains the correct query parameter', async () => { | ||
| const component = await fixture<WebstatusNotFoundErrorPage>(html` | ||
| <webstatus-not-found-error-page | ||
| .location=${{search: '?q=correct-query'}} | ||
| ></webstatus-not-found-error-page> | ||
| `); | ||
|
|
||
| const searchButton = component.shadowRoot?.querySelector( | ||
| '#error-action-search-btn', | ||
| ); | ||
| expect(searchButton?.getAttribute('href')).to.equal('/?q=correct-query'); | ||
| }); | ||
|
|
||
| it('report issue button links to GitHub', async () => { | ||
| const component = await fixture<WebstatusNotFoundErrorPage>(html` | ||
| <webstatus-not-found-error-page></webstatus-not-found-error-page> | ||
| `); | ||
|
|
||
| const reportButton = component.shadowRoot?.querySelector( | ||
| '#error-action-report', | ||
| ); | ||
| expect(reportButton?.getAttribute('href')).to.equal(GITHUB_REPO_ISSUE_LINK); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.