Skip to content

Commit

Permalink
[@lit-labs/router] add Routes.link tests (#3348)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewJakubowicz committed Oct 15, 2022
1 parent a432c38 commit 2906369
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .changeset/selfish-keys-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
55 changes: 55 additions & 0 deletions packages/labs/router/src/test/router_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,61 @@ const canTest =
'<h2>Not Found</h2>'
);
});

test('link() returns URL string including parent route', async () => {
await loadTestModule('./router_test.html');
const el = container.contentDocument!.createElement(
'router-test-1'
) as Test1;
const {contentWindow, contentDocument} = container;

// Set the iframe URL before appending the element
contentWindow!.history.pushState({}, '', '/child1/def');
contentDocument!.body.append(el);
await el.updateComplete;
const child1 = el.shadowRoot!.querySelector('child-1') as Child1;
await child1.updateComplete;

assert.equal(el._router.link(), '/child1/');
assert.equal(child1._routes.link(), '/child1/def');
});

test('link() can replace local path', async () => {
await loadTestModule('./router_test.html');
const el = container.contentDocument!.createElement(
'router-test-1'
) as Test1;
const {contentWindow, contentDocument} = container;

// Set the iframe URL before appending the element
contentWindow!.history.pushState({}, '', '/child1/def');
contentDocument!.body.append(el);
await el.updateComplete;
const child1 = el.shadowRoot!.querySelector('child-1') as Child1;
await child1.updateComplete;

assert.equal(child1._routes.link('local_path'), `/child1/local_path`);
});

test(`link() with local absolute path doesn't include parent route`, async () => {
await loadTestModule('./router_test.html');
const el = container.contentDocument!.createElement(
'router-test-1'
) as Test1;
const {contentWindow, contentDocument} = container;

// Set the iframe URL before appending the element
contentWindow!.history.pushState({}, '', '/child1/def');
contentDocument!.body.append(el);
await el.updateComplete;
const child1 = el.shadowRoot!.querySelector('child-1') as Child1;
await child1.updateComplete;

assert.equal(
child1._routes.link('/local_absolute_path'),
'/local_absolute_path'
);
});
});

export const stripExpressionComments = (html: string) =>
Expand Down

0 comments on commit 2906369

Please sign in to comment.