@a11d/lit-application 0.8.2 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,92 +0,0 @@
1
- import { __decorate } from "tslib";
2
- import { ComponentTestFixture } from '@a11d/lit-testing';
3
- import { NotificationComponent, NotificationType } from './NotificationComponent.js';
4
- import { component } from '@a11d/lit';
5
- describe('NotificationComponent', () => {
6
- let TestNotificationComponent = class TestNotificationComponent extends NotificationComponent {
7
- show() {
8
- return Promise.resolve();
9
- }
10
- };
11
- TestNotificationComponent = __decorate([
12
- NotificationComponent.defaultComponent(),
13
- component('test-notification')
14
- ], TestNotificationComponent);
15
- const fixture = new ComponentTestFixture(() => new TestNotificationComponent());
16
- fixture;
17
- const all = [
18
- { method: 'notifyInfo', type: NotificationType.Info },
19
- { method: 'notifySuccess', type: NotificationType.Success },
20
- { method: 'notifyWarning', type: NotificationType.Warning },
21
- { method: 'notifyError', type: NotificationType.Error },
22
- ];
23
- const action = { title: 'Test', handleClick: () => { } };
24
- for (const { method, type } of all) {
25
- it(`should proxy "${method}" with shortened parameters to "notify" with correct parameters`, async () => {
26
- spyOn(TestNotificationComponent, 'notify').and.callThrough();
27
- await TestNotificationComponent[method]('Test', action);
28
- expect(TestNotificationComponent.notify).toHaveBeenCalledWith({
29
- type,
30
- message: 'Test',
31
- actions: [action],
32
- });
33
- });
34
- it(`should proxy "${method}" with full parameters to "notify" with correct parameters`, async () => {
35
- spyOn(TestNotificationComponent, 'notify').and.callThrough();
36
- await TestNotificationComponent[method]({
37
- message: 'Test',
38
- actions: [action],
39
- });
40
- expect(TestNotificationComponent.notify).toHaveBeenCalledWith({
41
- type,
42
- message: 'Test',
43
- actions: [action],
44
- });
45
- });
46
- it('should support non-string messages having the [Symbol.toPrimitive] method', async () => {
47
- spyOn(TestNotificationComponent, 'notify').and.callThrough();
48
- await TestNotificationComponent[method]({
49
- [Symbol.toPrimitive]: () => 'Test',
50
- }, action);
51
- expect(TestNotificationComponent.notify).toHaveBeenCalledWith({
52
- type,
53
- message: 'Test',
54
- actions: [action]
55
- });
56
- });
57
- }
58
- describe('notifyAndThrowError', () => {
59
- it('should throw and proxy on shorthand parameters with error', () => {
60
- spyOn(TestNotificationComponent, 'notify').and.callThrough();
61
- const error = new Error('Test');
62
- expect(() => TestNotificationComponent.notifyAndThrowError(error, action)).toThrow(error);
63
- expect(TestNotificationComponent.notify).toHaveBeenCalledWith({
64
- type: NotificationType.Error,
65
- message: 'Test',
66
- actions: [action],
67
- });
68
- });
69
- it('should throw and proxy on shorthand parameters with error-message', () => {
70
- spyOn(TestNotificationComponent, 'notify').and.callThrough();
71
- const errorMessage = 'Test';
72
- expect(() => TestNotificationComponent.notifyAndThrowError(errorMessage, action)).toThrow(new Error(errorMessage));
73
- expect(TestNotificationComponent.notify).toHaveBeenCalledWith({
74
- type: NotificationType.Error,
75
- message: errorMessage,
76
- actions: [action],
77
- });
78
- });
79
- it('should throw and proxy on shorthand parameters with notification parameters', () => {
80
- spyOn(TestNotificationComponent, 'notify').and.callThrough();
81
- expect(() => TestNotificationComponent.notifyAndThrowError({
82
- message: 'Test',
83
- actions: [action],
84
- })).toThrow(new Error('Test'));
85
- expect(TestNotificationComponent.notify).toHaveBeenCalledWith({
86
- type: NotificationType.Error,
87
- message: 'Test',
88
- actions: [action],
89
- });
90
- });
91
- });
92
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=RoutableComponent.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"RoutableComponent.test.d.ts","sourceRoot":"","sources":["../../Router/RoutableComponent.test.ts"],"names":[],"mappings":""}
@@ -1,138 +0,0 @@
1
- import { __decorate } from "tslib";
2
- import { RoutableComponent } from './RoutableComponent.js';
3
- import { route } from './route.js';
4
- import { component } from '@a11d/lit';
5
- let WithoutRoute = class WithoutRoute extends RoutableComponent {
6
- };
7
- WithoutRoute = __decorate([
8
- component('test-without-route')
9
- ], WithoutRoute);
10
- let HomePage = class HomePage extends RoutableComponent {
11
- };
12
- HomePage = __decorate([
13
- route('/'),
14
- component('test-homepage')
15
- ], HomePage);
16
- let WithNumericId = class WithNumericId extends RoutableComponent {
17
- };
18
- WithNumericId = __decorate([
19
- route('/with-numeric-id/:id'),
20
- component('test-with-numeric-id')
21
- ], WithNumericId);
22
- let WithSubRoute = class WithSubRoute extends RoutableComponent {
23
- };
24
- WithSubRoute = __decorate([
25
- route('/with-sub-route{/:subRoute}?'),
26
- component('test-with-sub-route')
27
- ], WithSubRoute);
28
- let WithNonRouteParameter = class WithNonRouteParameter extends RoutableComponent {
29
- };
30
- WithNonRouteParameter = __decorate([
31
- route('/with-non-route-parameter'),
32
- component('test-with-non-route-parameter')
33
- ], WithNonRouteParameter);
34
- let WithCatchAll = class WithCatchAll extends RoutableComponent {
35
- };
36
- WithCatchAll = __decorate([
37
- route('/catch-all/(.*)?'),
38
- component('test-catch-all')
39
- ], WithCatchAll);
40
- let SubCatchAll = class SubCatchAll extends RoutableComponent {
41
- };
42
- SubCatchAll = __decorate([
43
- route(WithCatchAll, '/catch-all/sub/route'),
44
- component('test-sub-catch-all')
45
- ], SubCatchAll);
46
- describe('RoutableComponent', () => {
47
- describe('routes', () => {
48
- it('should return the routes of the component', () => {
49
- expect(HomePage.routes).toEqual(['/']);
50
- expect(WithNumericId.routes).toEqual(['/with-numeric-id/:id']);
51
- expect(WithSubRoute.routes).toEqual(['/with-sub-route{/:subRoute}?']);
52
- expect(WithNonRouteParameter.routes).toEqual(['/with-non-route-parameter']);
53
- expect(WithCatchAll.routes).toEqual(['/catch-all/(.*)?']);
54
- expect(SubCatchAll.routes).toEqual(['/catch-all/sub/route']);
55
- });
56
- it('should return the routes of the component with base path', () => {
57
- RoutableComponent.basePath = '/base-path';
58
- expect(HomePage.routes).toEqual(['/base-path/']);
59
- expect(WithNumericId.routes).toEqual(['/base-path/with-numeric-id/:id']);
60
- expect(WithSubRoute.routes).toEqual(['/base-path/with-sub-route{/:subRoute}?']);
61
- expect(WithNonRouteParameter.routes).toEqual(['/base-path/with-non-route-parameter']);
62
- expect(WithCatchAll.routes).toEqual(['/base-path/catch-all/(.*)?']);
63
- expect(SubCatchAll.routes).toEqual(['/base-path/catch-all/sub/route']);
64
- RoutableComponent.basePath = '';
65
- });
66
- });
67
- describe('url', () => {
68
- it('should return undefined if the given routable does not match any route', () => {
69
- expect(new WithoutRoute().url).toBeUndefined();
70
- });
71
- it('should return the path that matches the given routable - PageWithNumericId', () => {
72
- expect(new HomePage().url.path).toBe('/');
73
- expect(new WithNumericId({ id: 1 }).url.path).toBe('/with-numeric-id/1');
74
- expect(new WithSubRoute({ subRoute: 'sub-route' }).url.path).toBe('/with-sub-route/sub-route');
75
- expect(new WithSubRoute({}).url.path).toBe('/with-sub-route');
76
- expect(new WithCatchAll().url.path).toBe('/catch-all');
77
- expect(new SubCatchAll().url.path).toBe('/catch-all/sub/route');
78
- });
79
- it('should put parameters part of the catch-all route in the path', () => {
80
- expect(new WithCatchAll({ '0': 'sub/route' }).url.path).toBe('/catch-all/sub/route');
81
- });
82
- it('should put the parameters not part of the route in the query string', () => {
83
- expect(new WithNonRouteParameter({ keyword: 'test' }).url.path).toBe('/with-non-route-parameter?keyword=test');
84
- expect(new WithNumericId({ id: 1, view: 'details' }).url.path).toBe('/with-numeric-id/1?view=details');
85
- });
86
- it('should encode the parameters in the query string', () => {
87
- expect(new WithNonRouteParameter({ keyword: 'test test' }).url.path).toBe('/with-non-route-parameter?keyword=test+test');
88
- expect(new WithNonRouteParameter({ keyword: 'test+test' }).url.path).toBe('/with-non-route-parameter?keyword=test%2Btest');
89
- expect(new WithNonRouteParameter({ keyword: 'tést' }).url.path).toBe('/with-non-route-parameter?keyword=t%C3%A9st');
90
- });
91
- });
92
- describe('urlMatches', () => {
93
- const url = (path) => new URL(path, globalThis.location.toString());
94
- describe('mode: all', () => {
95
- it('should return true when parameters absent', () => {
96
- expect(new HomePage().urlMatches({ url: url('/') })).toBe(true);
97
- expect(new WithSubRoute({}).urlMatches({ url: url('/with-sub-route') })).toBe(true);
98
- });
99
- it('should return true when parameters match', () => {
100
- expect(new WithNumericId({ id: 1 }).urlMatches({ url: url('/with-numeric-id/1') })).toBe(true);
101
- expect(new WithSubRoute({ subRoute: 'sub-route' }).urlMatches({ url: url('/with-sub-route/sub-route') })).toBe(true);
102
- expect(new WithNonRouteParameter({ keyword: 'test' }).urlMatches({ url: url('/with-non-route-parameter?keyword=test') })).toBe(true);
103
- expect(new WithNumericId({ id: 1, view: 'details' }).urlMatches({ url: url('/with-numeric-id/1?view=details') })).toBe(true);
104
- });
105
- it('should return false if the given routable does not match the route', () => {
106
- expect(new WithNumericId({ id: 1 }).urlMatches({ url: url('/with-numeric-id/2') })).toBe(false);
107
- expect(new WithSubRoute({ subRoute: 'sub-route' }).urlMatches({ url: url('/with-sub-route') })).toBe(false);
108
- expect(new WithSubRoute({}).urlMatches({ url: url('/with-sub-route/sub-route') })).toBe(false);
109
- expect(new WithNonRouteParameter({ keyword: 'test' }).urlMatches({ url: url('/with-non-route-parameter?keyword=other') })).toBe(false);
110
- expect(new WithNumericId({ id: 1, view: 'details' }).urlMatches({ url: url('/with-numeric-id/1?view=other') })).toBe(false);
111
- });
112
- });
113
- describe('mode: ignore-parameters', () => {
114
- const mode = 'ignore-parameters';
115
- it('should return true if the given routable matches the route', () => {
116
- expect(new WithNumericId({ id: 1 }).urlMatches({ mode, url: url('/with-numeric-id/1') })).toBe(true);
117
- expect(new WithNumericId({ id: 1 }).urlMatches({ mode, url: url('/with-numeric-id/2') })).toBe(true);
118
- expect(new WithSubRoute({ subRoute: 'sub-route' }).urlMatches({ mode, url: url('/with-sub-route/sub-route') })).toBe(true);
119
- expect(new WithSubRoute({ subRoute: 'sub-route' }).urlMatches({ mode, url: url('/with-sub-route') })).toBe(true);
120
- expect(new WithSubRoute({}).urlMatches({ mode, url: url('/with-sub-route') })).toBe(true);
121
- expect(new WithSubRoute({}).urlMatches({ mode, url: url('/with-sub-route/sub-route') })).toBe(true);
122
- expect(new WithNonRouteParameter({ keyword: 'test' }).urlMatches({ mode, url: url('/with-non-route-parameter?keyword=test') })).toBe(true);
123
- expect(new WithNonRouteParameter({ keyword: 'test' }).urlMatches({ mode, url: url('/with-non-route-parameter?keyword=other') })).toBe(true);
124
- expect(new WithNumericId({ id: 1, view: 'details' }).urlMatches({ mode, url: url('/with-numeric-id/1?view=details') })).toBe(true);
125
- expect(new WithNumericId({ id: 1, view: 'details' }).urlMatches({ mode, url: url('/with-numeric-id/1?view=other') })).toBe(true);
126
- });
127
- it('should return false if the given routable does not match the route', () => {
128
- expect(new WithNumericId({ id: 1 }).urlMatches({ mode, url: url('/xx-with-numeric-id') })).toBe(false);
129
- expect(new WithSubRoute({ subRoute: 'sub-route' }).urlMatches({ mode, url: url('/xx-with-sub-route/sub-route') })).toBe(false);
130
- expect(new WithSubRoute({}).urlMatches({ mode, url: url('/xx-with-sub-route') })).toBe(false);
131
- expect(new WithSubRoute({}).urlMatches({ mode, url: url('/xx-with-sub-route/sub-route') })).toBe(false);
132
- expect(new WithNonRouteParameter({ keyword: 'test' }).urlMatches({ mode, url: url('/xx-with-non-route-parameter?keyword=test') })).toBe(false);
133
- expect(new WithNonRouteParameter({ keyword: 'test' }).urlMatches({ mode, url: url('/xx-with-non-route-parameter?keyword=other') })).toBe(false);
134
- expect(new WithNumericId({ id: 1, view: 'details' }).urlMatches({ mode, url: url('/xx-with-numeric-id/1?view=details') })).toBe(false);
135
- });
136
- });
137
- });
138
- });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=path.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"path.test.d.ts","sourceRoot":"","sources":["../../Router/path.test.ts"],"names":[],"mappings":""}
@@ -1,17 +0,0 @@
1
- describe('URL', () => {
2
- describe('path', () => {
3
- it('should return the path of the URL', () => {
4
- const url = new URL('https://example.com/path/to/resource?query=param');
5
- expect(url.path).toBe('/path/to/resource?query=param');
6
- });
7
- it('should return the path of the URL without query parameters', () => {
8
- const url = new URL('https://example.com/path/to/resource');
9
- expect(url.path).toBe('/path/to/resource');
10
- });
11
- it('should return an empty string for a URL with no path', () => {
12
- const url = new URL('https://example.com');
13
- expect(url.path).toBe('/');
14
- });
15
- });
16
- });
17
- export {};