Skip to content
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

Require that links clicked are defined in the app, this means that @properLinks would no longer be required #6

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test-app/app/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ export default class Router extends EmberRouter {

Router.map(function () {
// Add route declarations here
this.route('*any');
this.route('foo');
});
3 changes: 2 additions & 1 deletion test-app/app/templates/application.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@

{{outlet}}

<a href="/foo">here</a>
<a href="/foo">here</a>
<a href="/does-not-exist">here</a>
28 changes: 25 additions & 3 deletions test-support/src/routing/visit-all.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { assert as debugAssert } from '@ember/debug';
import { click, currentURL, findAll } from '@ember/test-helpers';
import { visit } from '@ember/test-helpers';
import { find } from '@ember/test-helpers';
import {
visit,
find,
getContext,
click,
currentURL,
findAll,
} from '@ember/test-helpers';
import QUnit from 'qunit';
import type Owner from '@ember/owner';
import type RouterService from '@ember/routing/router-service';

function findInAppLinks(): string[] {
return (findAll('a')
Expand All @@ -25,6 +32,11 @@ export async function visitAllLinks() {
const inAppLinks = findInAppLinks();
const queue: (string | { changeReturnTo: string })[] = [...inAppLinks];

const ctx = getContext() as unknown as { owner: Owner };
const router = ctx?.owner?.lookup('service:router') as RouterService;

debugAssert(`Could not find the router service`, router);

while (queue.length > 0) {
const toVisit = queue.shift();

Expand All @@ -39,6 +51,16 @@ export async function visitAllLinks() {

if (visited.has(key)) continue;

const result = router.recognize(toVisit);

if (!result) {
assert.ok(
true,
`${toVisit} on page ${returnTo} is not recognized by this app and will be skipped`,
);
continue;
}

await visit(returnTo);

const link = find(`a[href="${toVisit}"]`);
Expand Down