Skip to content

Commit

Permalink
fix(router-lite): URL generation in child component (#1778)
Browse files Browse the repository at this point in the history
* chore: wip

* fix(router-lite): broken tests

* test: router-lite

* chore: deepscan issue
  • Loading branch information
Sayan751 committed Jun 14, 2023
1 parent 07689bf commit fd4de06
Show file tree
Hide file tree
Showing 8 changed files with 457 additions and 33 deletions.
2 changes: 1 addition & 1 deletion packages/__tests__/router-lite/ast.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ describe('router-lite/ast.spec.ts', function () {
it(path, function () {
const actual = RouteExpression.parse(path, false);
assert.deepStrictEqual(actual, expected[0]);
assert.strictEqual(actual.toInstructionTree(NavigationOptions.create(RouterOptions.create({}), {})).toUrl(), expected[1]);
assert.strictEqual(actual.toInstructionTree(NavigationOptions.create(RouterOptions.create({}), {})).toUrl(false, false), expected[1]);
});
}

Expand Down
20 changes: 10 additions & 10 deletions packages/__tests__/router-lite/events.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ describe('router-lite/events.spec.ts', function () {
public constructor(@IRouterEvents events: IRouterEvents) {
this.subscriptions = [
events.subscribe('au:router:navigation-start', (event) => {
this.log.push(`${event.name} - ${event.id} - '${event.instructions.toUrl()}'`);
this.log.push(`${event.name} - ${event.id} - '${event.instructions.toUrl(false, false)}'`);
}),
events.subscribe('au:router:navigation-end', (event) => {
this.log.push(`${event.name} - ${event.id} - '${event.instructions.toUrl()}'`);
this.log.push(`${event.name} - ${event.id} - '${event.instructions.toUrl(false, false)}'`);
}),
events.subscribe('au:router:navigation-cancel', (event) => {
this.log.push(`${event.name} - ${event.id} - '${event.instructions.toUrl()}' - ${String(event.reason)}`);
this.log.push(`${event.name} - ${event.id} - '${event.instructions.toUrl(false, false)}' - ${String(event.reason)}`);
}),
events.subscribe('au:router:navigation-error', (event) => {
this.log.push(`${event.name} - ${event.id} - '${event.instructions.toUrl()}' - ${String(event.error)}`);
this.log.push(`${event.name} - ${event.id} - '${event.instructions.toUrl(false, false)}' - ${String(event.error)}`);
}),
];
}
Expand All @@ -74,8 +74,8 @@ describe('router-lite/events.spec.ts', function () {

@route({
routes: [
{ path: ['', 'c1'], component: ChildOne },
{ path: 'c2', component: ChildTwo },
{ id:'r1', path: ['', 'c1'], component: ChildOne },
{ id:'r2', path: 'c2', component: ChildTwo },
]
})
@customElement({ name: 'ro-ot', template: '<au-viewport></au-viewport>' })
Expand Down Expand Up @@ -207,8 +207,8 @@ describe('router-lite/events.spec.ts', function () {

@route({
routes: [
{ path: ['', 'c1'], component: ChildOne },
{ path: 'c2', component: ChildTwo },
{ id:'r1', path: ['', 'c1'], component: ChildOne },
{ id:'r2', path: 'c2', component: ChildTwo },
]
})
@customElement({ name: 'ro-ot', template: '<au-viewport></au-viewport>' })
Expand Down Expand Up @@ -253,8 +253,8 @@ describe('router-lite/events.spec.ts', function () {

@route({
routes: [
{ path: ['', 'c1'], component: ChildOne },
{ path: 'c2', component: ChildTwo },
{ id:'r1', path: ['', 'c1'], component: ChildOne },
{ id:'r2', path: 'c2', component: ChildTwo },
]
})
@customElement({ name: 'ro-ot', template: '<au-viewport></au-viewport>' })
Expand Down
17 changes: 9 additions & 8 deletions packages/__tests__/router-lite/location-manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ describe('router-lite/location-manager.spec.ts', function () {
{ path: 'gc-2', component: GC2 },
]
})
@customElement({ name: 'c-1', template: '<a href="gc-2"></a> c1 <au-viewport></au-viewport>' })
@customElement({ name: 'c-1', template: '<a load="gc-2"></a> c1 <au-viewport></au-viewport>' })
class C1 { }
@customElement({ name: 'c-2', template: 'c2' })
class C2 { }
Expand Down Expand Up @@ -162,7 +162,8 @@ describe('router-lite/location-manager.spec.ts', function () {
assert.html.textContent(host, 'c1 gc1', 'nav2');
assert.deepStrictEqual(eventLog, [], 'nav2 event log');

host.querySelector('a').click();
const anchor = host.querySelector('a');
anchor.click();
await queue.yield();
assert.html.textContent(host, 'c1 gc2', 'nav3');
assert.deepStrictEqual(eventLog, [], 'nav1 event log');
Expand All @@ -172,7 +173,7 @@ describe('router-lite/location-manager.spec.ts', function () {
history.back();
await queue.yield();

assert.html.textContent(host, 'c1 gc1', 'back');
assert.html.textContent(host, 'c1 gc1', 'back1');
assert.strictEqual(eventLog.length, 1, 'back event log length');
assert.strictEqual(eventLog[0][0], event, 'back event log trigger');
assert.match(eventLog[0][1], /c1$/, 'back event log path');
Expand All @@ -181,7 +182,7 @@ describe('router-lite/location-manager.spec.ts', function () {
history.forward();
await queue.yield();

assert.html.textContent(host, 'c1 gc2', 'forward');
assert.html.textContent(host, 'c1 gc2', 'forward1');
assert.strictEqual(eventLog.length, 1, 'back event log length');
assert.strictEqual(eventLog[0][0], event, 'back event log trigger');
assert.match(eventLog[0][1], /c1\/gc-2$/, 'back event log path');
Expand All @@ -191,7 +192,7 @@ describe('router-lite/location-manager.spec.ts', function () {
history.back();
await queue.yield();

assert.html.textContent(host, 'c1 gc1', 'back');
assert.html.textContent(host, 'c1 gc1', 'back2');
assert.strictEqual(eventLog.length, 1, 'back event log length');
assert.strictEqual(eventLog[0][0], event, 'back event log trigger');
assert.match(eventLog[0][1], /c1$/, 'back event log path');
Expand All @@ -200,7 +201,7 @@ describe('router-lite/location-manager.spec.ts', function () {
history.forward();
await queue.yield();

assert.html.textContent(host, 'c1 gc2', 'forward');
assert.html.textContent(host, 'c1 gc2', 'forward2');
assert.strictEqual(eventLog.length, 1, 'back event log length');
assert.strictEqual(eventLog[0][0], event, 'back event log trigger');
assert.match(eventLog[0][1], /c1\/gc-2$/, 'back event log path');
Expand All @@ -210,7 +211,7 @@ describe('router-lite/location-manager.spec.ts', function () {
history.back();
await queue.yield();

assert.html.textContent(host, 'c1 gc1', 'back');
assert.html.textContent(host, 'c1 gc1', 'back3');
assert.strictEqual(eventLog.length, 1, 'back event log length');
assert.strictEqual(eventLog[0][0], event, 'back event log trigger');
assert.match(eventLog[0][1], /c1$/, 'back event log path');
Expand All @@ -219,7 +220,7 @@ describe('router-lite/location-manager.spec.ts', function () {
history.forward();
await queue.yield();

assert.html.textContent(host, 'c1 gc2', 'forward');
assert.html.textContent(host, 'c1 gc2', 'forward3');
assert.strictEqual(eventLog.length, 1, 'back event log length');
assert.strictEqual(eventLog[0][0], event, 'back event log trigger');
assert.match(eventLog[0][1], /c1\/gc-2$/, 'back event log path');
Expand Down

0 comments on commit fd4de06

Please sign in to comment.