@storybook/angular 9.0.0-beta.6 → 9.0.0-beta.7
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.
- package/dist/builders/build-storybook/index.mjs +78 -0
- package/dist/builders/build-storybook/index.spec.mjs +187 -0
- package/dist/builders/start-storybook/index.mjs +99 -0
- package/dist/builders/start-storybook/index.spec.mjs +186 -0
- package/dist/builders/utils/error-handler.mjs +33 -0
- package/dist/builders/utils/run-compodoc.mjs +31 -0
- package/dist/builders/utils/run-compodoc.spec.mjs +74 -0
- package/dist/builders/utils/standalone-options.mjs +1 -0
- package/dist/client/angular-beta/AbstractRenderer.mjs +164 -0
- package/dist/client/angular-beta/CanvasRenderer.mjs +9 -0
- package/dist/client/angular-beta/ComputesTemplateFromComponent.mjs +154 -0
- package/dist/client/angular-beta/ComputesTemplateFromComponent.test.mjs +728 -0
- package/dist/client/angular-beta/DocsRenderer.mjs +35 -0
- package/dist/client/angular-beta/RendererFactory.mjs +50 -0
- package/dist/client/angular-beta/RendererFactory.test.mjs +233 -0
- package/dist/client/angular-beta/StorybookModule.mjs +23 -0
- package/dist/client/angular-beta/StorybookModule.test.mjs +319 -0
- package/dist/client/angular-beta/StorybookProvider.mjs +22 -0
- package/dist/client/angular-beta/StorybookWrapperComponent.mjs +123 -0
- package/dist/client/angular-beta/__testfixtures__/input.component.mjs +73 -0
- package/dist/client/angular-beta/__testfixtures__/test.module.mjs +17 -0
- package/dist/client/angular-beta/utils/BootstrapQueue.mjs +49 -0
- package/dist/client/angular-beta/utils/BootstrapQueue.test.mjs +162 -0
- package/dist/client/angular-beta/utils/NgComponentAnalyzer.mjs +84 -0
- package/dist/client/angular-beta/utils/NgComponentAnalyzer.test.mjs +386 -0
- package/dist/client/angular-beta/utils/NgModulesAnalyzer.mjs +37 -0
- package/dist/client/angular-beta/utils/NgModulesAnalyzer.test.mjs +22 -0
- package/dist/client/angular-beta/utils/PropertyExtractor.mjs +158 -0
- package/dist/client/angular-beta/utils/PropertyExtractor.test.mjs +175 -0
- package/dist/client/angular-beta/utils/StoryUID.mjs +38 -0
- package/dist/client/argsToTemplate.mjs +55 -0
- package/dist/client/argsToTemplate.test.mjs +100 -0
- package/dist/client/config.mjs +4 -0
- package/dist/client/decorateStory.mjs +45 -0
- package/dist/client/decorateStory.test.mjs +301 -0
- package/dist/client/decorators.mjs +63 -0
- package/dist/client/decorators.test.mjs +157 -0
- package/dist/client/docs/__testfixtures__/doc-button/input.mjs +201 -0
- package/dist/client/docs/angular-properties.test.mjs +34 -0
- package/dist/client/docs/compodoc.mjs +244 -0
- package/dist/client/docs/compodoc.test.mjs +130 -0
- package/dist/client/docs/config.mjs +16 -0
- package/dist/client/docs/index.mjs +1 -0
- package/dist/client/docs/sourceDecorator.mjs +48 -0
- package/dist/client/docs/types.mjs +1 -0
- package/dist/client/globals.mjs +31 -0
- package/dist/client/index.mjs +9 -0
- package/dist/client/portable-stories.mjs +26 -0
- package/dist/client/preview-prod.mjs +2 -0
- package/dist/client/public-types.mjs +1 -0
- package/dist/client/render.mjs +14 -0
- package/dist/client/types.mjs +1 -0
- package/dist/node/index.mjs +3 -0
- package/dist/server/__mocks-ng-workspace__/minimal-config/src/main.mjs +2 -0
- package/dist/server/__mocks-ng-workspace__/some-config/src/main.mjs +2 -0
- package/dist/server/__mocks-ng-workspace__/with-angularBrowserTarget/src/main.mjs +2 -0
- package/dist/server/__mocks-ng-workspace__/with-lib/projects/pattern-lib/src/main.mjs +2 -0
- package/dist/server/__mocks-ng-workspace__/with-nx/src/main.mjs +2 -0
- package/dist/server/__mocks-ng-workspace__/with-nx-workspace/src/main.mjs +2 -0
- package/dist/server/__mocks-ng-workspace__/with-options-styles/src/main.mjs +2 -0
- package/dist/server/__mocks-ng-workspace__/without-projects-entry/projects/pattern-lib/src/main.mjs +2 -0
- package/dist/server/__mocks-ng-workspace__/without-tsConfig/src/main.mjs +2 -0
- package/dist/server/angular-cli-webpack.mjs +80 -0
- package/dist/server/framework-preset-angular-cli.mjs +81 -0
- package/dist/server/framework-preset-angular-docs.mjs +6 -0
- package/dist/server/framework-preset-angular-ivy.mjs +56 -0
- package/dist/server/plugins/storybook-normalize-angular-entry-plugin.mjs +52 -0
- package/dist/server/preset-options.mjs +1 -0
- package/dist/server/utils/filter-out-styling-rules.mjs +13 -0
- package/dist/server/utils/module-is-available.mjs +9 -0
- package/package.json +4 -4
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { Component, Input, Output } from '@angular/core';
|
|
11
|
+
import { describe, expect, it } from 'vitest';
|
|
12
|
+
import { componentWrapperDecorator } from './decorators';
|
|
13
|
+
import decorateStory from './decorateStory';
|
|
14
|
+
// TODO: Fix. Test is infinitely running.
|
|
15
|
+
describe.skip('decorateStory', () => {
|
|
16
|
+
describe('angular behavior', () => {
|
|
17
|
+
it('should use componentWrapperDecorator with args', () => {
|
|
18
|
+
const decorators = [
|
|
19
|
+
componentWrapperDecorator(ParentComponent, ({ args }) => args),
|
|
20
|
+
componentWrapperDecorator((story) => `<grandparent [grandparentInput]="grandparentInput">${story}</grandparent>`, ({ args }) => args),
|
|
21
|
+
componentWrapperDecorator((story) => `<great-grandparent>${story}</great-grandparent>`),
|
|
22
|
+
];
|
|
23
|
+
const decorated = decorateStory(() => ({ template: '</child>' }), decorators);
|
|
24
|
+
expect(decorated(makeContext({
|
|
25
|
+
component: FooComponent,
|
|
26
|
+
args: {
|
|
27
|
+
parentInput: 'Parent input',
|
|
28
|
+
grandparentInput: 'grandparent input',
|
|
29
|
+
parentOutput: () => { },
|
|
30
|
+
},
|
|
31
|
+
}))).toEqual({
|
|
32
|
+
props: {
|
|
33
|
+
parentInput: 'Parent input',
|
|
34
|
+
grandparentInput: 'grandparent input',
|
|
35
|
+
parentOutput: expect.any(Function),
|
|
36
|
+
},
|
|
37
|
+
template: '<great-grandparent><grandparent [grandparentInput]="grandparentInput"><parent [parentInput]="parentInput" (parentOutput)="parentOutput($event)"></child></parent></grandparent></great-grandparent>',
|
|
38
|
+
userDefinedTemplate: true,
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
it('should use componentWrapperDecorator with input / output', () => {
|
|
42
|
+
const decorators = [
|
|
43
|
+
componentWrapperDecorator(ParentComponent, {
|
|
44
|
+
parentInput: 'Parent input',
|
|
45
|
+
parentOutput: () => { },
|
|
46
|
+
}),
|
|
47
|
+
componentWrapperDecorator((story) => `<grandparent [grandparentInput]="grandparentInput">${story}</grandparent>`, {
|
|
48
|
+
grandparentInput: 'Grandparent input',
|
|
49
|
+
sameInput: 'Should be override by story props',
|
|
50
|
+
}),
|
|
51
|
+
componentWrapperDecorator((story) => `<great-grandparent>${story}</great-grandparent>`),
|
|
52
|
+
];
|
|
53
|
+
const decorated = decorateStory(() => ({ template: '</child>', props: { sameInput: 'Story input' } }), decorators);
|
|
54
|
+
expect(decorated(makeContext({
|
|
55
|
+
component: FooComponent,
|
|
56
|
+
}))).toEqual({
|
|
57
|
+
props: {
|
|
58
|
+
parentInput: 'Parent input',
|
|
59
|
+
parentOutput: expect.any(Function),
|
|
60
|
+
grandparentInput: 'Grandparent input',
|
|
61
|
+
sameInput: 'Story input',
|
|
62
|
+
},
|
|
63
|
+
template: '<great-grandparent><grandparent [grandparentInput]="grandparentInput"><parent [parentInput]="parentInput" (parentOutput)="parentOutput($event)"></child></parent></grandparent></great-grandparent>',
|
|
64
|
+
userDefinedTemplate: true,
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
it('should use componentWrapperDecorator', () => {
|
|
68
|
+
const decorators = [
|
|
69
|
+
componentWrapperDecorator(ParentComponent),
|
|
70
|
+
componentWrapperDecorator((story) => `<grandparent>${story}</grandparent>`),
|
|
71
|
+
componentWrapperDecorator((story) => `<great-grandparent>${story}</great-grandparent>`),
|
|
72
|
+
];
|
|
73
|
+
const decorated = decorateStory(() => ({ template: '</child>' }), decorators);
|
|
74
|
+
expect(decorated(makeContext({ component: FooComponent }))).toEqual({
|
|
75
|
+
template: '<great-grandparent><grandparent><parent></child></parent></grandparent></great-grandparent>',
|
|
76
|
+
userDefinedTemplate: true,
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
it('should use template in preference to component parameters', () => {
|
|
80
|
+
const decorators = [
|
|
81
|
+
(s) => {
|
|
82
|
+
const story = s();
|
|
83
|
+
return {
|
|
84
|
+
...story,
|
|
85
|
+
template: `<parent>${story.template}</parent>`,
|
|
86
|
+
};
|
|
87
|
+
},
|
|
88
|
+
(s) => {
|
|
89
|
+
const story = s();
|
|
90
|
+
return {
|
|
91
|
+
...story,
|
|
92
|
+
template: `<grandparent>${story.template}</grandparent>`,
|
|
93
|
+
};
|
|
94
|
+
},
|
|
95
|
+
(s) => {
|
|
96
|
+
const story = s();
|
|
97
|
+
return {
|
|
98
|
+
...story,
|
|
99
|
+
template: `<great-grandparent>${story.template}</great-grandparent>`,
|
|
100
|
+
};
|
|
101
|
+
},
|
|
102
|
+
];
|
|
103
|
+
const decorated = decorateStory(() => ({ template: '</child>' }), decorators);
|
|
104
|
+
expect(decorated(makeContext({ component: FooComponent }))).toEqual({
|
|
105
|
+
template: '<great-grandparent><grandparent><parent></child></parent></grandparent></great-grandparent>',
|
|
106
|
+
userDefinedTemplate: true,
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
it('should include story templates in decorators', () => {
|
|
110
|
+
const decorators = [
|
|
111
|
+
(s) => {
|
|
112
|
+
const story = s();
|
|
113
|
+
return {
|
|
114
|
+
...story,
|
|
115
|
+
template: `<parent>${story.template}</parent>`,
|
|
116
|
+
};
|
|
117
|
+
},
|
|
118
|
+
(s) => {
|
|
119
|
+
const story = s();
|
|
120
|
+
return {
|
|
121
|
+
...story,
|
|
122
|
+
template: `<grandparent>${story.template}</grandparent>`,
|
|
123
|
+
};
|
|
124
|
+
},
|
|
125
|
+
(s) => {
|
|
126
|
+
const story = s();
|
|
127
|
+
return {
|
|
128
|
+
...story,
|
|
129
|
+
template: `<great-grandparent>${story.template}</great-grandparent>`,
|
|
130
|
+
};
|
|
131
|
+
},
|
|
132
|
+
];
|
|
133
|
+
const decorated = decorateStory(() => ({ template: '</child>' }), decorators);
|
|
134
|
+
expect(decorated(makeContext({}))).toEqual({
|
|
135
|
+
template: '<great-grandparent><grandparent><parent></child></parent></grandparent></great-grandparent>',
|
|
136
|
+
userDefinedTemplate: true,
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
it('should include story components in decorators', () => {
|
|
140
|
+
const decorators = [
|
|
141
|
+
(s) => {
|
|
142
|
+
const story = s();
|
|
143
|
+
return {
|
|
144
|
+
...story,
|
|
145
|
+
template: `<parent>${story.template}</parent>`,
|
|
146
|
+
};
|
|
147
|
+
},
|
|
148
|
+
(s) => {
|
|
149
|
+
const story = s();
|
|
150
|
+
return {
|
|
151
|
+
...story,
|
|
152
|
+
template: `<grandparent>${story.template}</grandparent>`,
|
|
153
|
+
};
|
|
154
|
+
},
|
|
155
|
+
(s) => {
|
|
156
|
+
const story = s();
|
|
157
|
+
return {
|
|
158
|
+
...story,
|
|
159
|
+
template: `<great-grandparent>${story.template}</great-grandparent>`,
|
|
160
|
+
};
|
|
161
|
+
},
|
|
162
|
+
];
|
|
163
|
+
const decorated = decorateStory(() => ({}), decorators);
|
|
164
|
+
expect(decorated(makeContext({ component: FooComponent }))).toEqual({
|
|
165
|
+
template: '<great-grandparent><grandparent><parent><foo></foo></parent></grandparent></great-grandparent>',
|
|
166
|
+
userDefinedTemplate: false,
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
it('should keep template with an empty value', () => {
|
|
170
|
+
const decorators = [
|
|
171
|
+
componentWrapperDecorator(ParentComponent),
|
|
172
|
+
];
|
|
173
|
+
const decorated = decorateStory(() => ({ template: '' }), decorators);
|
|
174
|
+
expect(decorated(makeContext({ component: FooComponent }))).toEqual({
|
|
175
|
+
template: '<parent></parent>',
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
it('should only keeps args with a control or an action in argTypes', () => {
|
|
179
|
+
const decorated = decorateStory((context) => ({
|
|
180
|
+
template: `Args available in the story : ${Object.keys(context.args).join()}`,
|
|
181
|
+
}), []);
|
|
182
|
+
expect(decorated(makeContext({
|
|
183
|
+
component: FooComponent,
|
|
184
|
+
argTypes: {
|
|
185
|
+
withControl: { control: { type: 'object' }, name: 'withControl' },
|
|
186
|
+
withAction: { action: 'onClick', name: 'withAction' },
|
|
187
|
+
toRemove: { name: 'toRemove' },
|
|
188
|
+
},
|
|
189
|
+
args: {
|
|
190
|
+
withControl: 'withControl',
|
|
191
|
+
withAction: () => ({}),
|
|
192
|
+
toRemove: 'toRemove',
|
|
193
|
+
},
|
|
194
|
+
}))).toEqual({
|
|
195
|
+
template: 'Args available in the story : withControl,withAction',
|
|
196
|
+
userDefinedTemplate: true,
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
describe('default behavior', () => {
|
|
201
|
+
it('calls decorators in out to in order', () => {
|
|
202
|
+
const decorators = [
|
|
203
|
+
(s) => {
|
|
204
|
+
const story = s();
|
|
205
|
+
return { ...story, props: { a: [...story.props.a, 1] } };
|
|
206
|
+
},
|
|
207
|
+
(s) => {
|
|
208
|
+
const story = s();
|
|
209
|
+
return { ...story, props: { a: [...story.props.a, 2] } };
|
|
210
|
+
},
|
|
211
|
+
(s) => {
|
|
212
|
+
const story = s();
|
|
213
|
+
return { ...story, props: { a: [...story.props.a, 3] } };
|
|
214
|
+
},
|
|
215
|
+
];
|
|
216
|
+
const decorated = decorateStory(() => ({ props: { a: [0] } }), decorators);
|
|
217
|
+
expect(decorated(makeContext({}))).toEqual({ props: { a: [0, 1, 2, 3] } });
|
|
218
|
+
});
|
|
219
|
+
it('passes context through to sub decorators', () => {
|
|
220
|
+
const decorators = [
|
|
221
|
+
(s, c) => {
|
|
222
|
+
const story = s({ ...c, k: 1 });
|
|
223
|
+
return { ...story, props: { a: [...story.props.a, c.k] } };
|
|
224
|
+
},
|
|
225
|
+
(s, c) => {
|
|
226
|
+
const story = s({ ...c, k: 2 });
|
|
227
|
+
return { ...story, props: { a: [...story.props.a, c.k] } };
|
|
228
|
+
},
|
|
229
|
+
(s, c) => {
|
|
230
|
+
const story = s({ ...c, k: 3 });
|
|
231
|
+
return { ...story, props: { a: [...story.props.a, c.k] } };
|
|
232
|
+
},
|
|
233
|
+
];
|
|
234
|
+
const decorated = decorateStory((c) => ({ props: { a: [c.k] } }), decorators);
|
|
235
|
+
expect(decorated(makeContext({ k: 0 }))).toEqual({ props: { a: [1, 2, 3, 0] } });
|
|
236
|
+
});
|
|
237
|
+
it('DOES NOT merge parameter or pass through parameters key in context', () => {
|
|
238
|
+
const decorators = [
|
|
239
|
+
(s, c) => {
|
|
240
|
+
const story = s({ ...c, k: 1, parameters: { p: 1 } });
|
|
241
|
+
return {
|
|
242
|
+
...story,
|
|
243
|
+
props: { a: [...story.props.a, c.k], p: [...story.props.p, c.parameters.p] },
|
|
244
|
+
};
|
|
245
|
+
},
|
|
246
|
+
(s, c) => {
|
|
247
|
+
const story = s({ ...c, k: 2, parameters: { p: 2 } });
|
|
248
|
+
return {
|
|
249
|
+
...story,
|
|
250
|
+
props: { a: [...story.props.a, c.k], p: [...story.props.p, c.parameters.p] },
|
|
251
|
+
};
|
|
252
|
+
},
|
|
253
|
+
(s, c) => {
|
|
254
|
+
const story = s({ ...c, k: 3, parameters: { p: 3 } });
|
|
255
|
+
return {
|
|
256
|
+
...story,
|
|
257
|
+
props: { a: [...story.props.a, c.k], p: [...story.props.p, c.parameters.p] },
|
|
258
|
+
};
|
|
259
|
+
},
|
|
260
|
+
];
|
|
261
|
+
const decorated = decorateStory((c) => ({ props: { a: [c.k], p: [c.parameters.p] } }), decorators);
|
|
262
|
+
expect(decorated(makeContext({ k: 0, parameters: { p: 0 } }))).toEqual({
|
|
263
|
+
props: { a: [1, 2, 3, 0], p: [0, 0, 0, 0] },
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
function makeContext(input) {
|
|
269
|
+
return {
|
|
270
|
+
id: 'id',
|
|
271
|
+
kind: 'kind',
|
|
272
|
+
name: 'name',
|
|
273
|
+
viewMode: 'story',
|
|
274
|
+
parameters: {},
|
|
275
|
+
...input,
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
let FooComponent = class FooComponent {
|
|
279
|
+
};
|
|
280
|
+
FooComponent = __decorate([
|
|
281
|
+
Component({
|
|
282
|
+
selector: 'foo',
|
|
283
|
+
template: `foo`,
|
|
284
|
+
})
|
|
285
|
+
], FooComponent);
|
|
286
|
+
let ParentComponent = class ParentComponent {
|
|
287
|
+
};
|
|
288
|
+
__decorate([
|
|
289
|
+
Input(),
|
|
290
|
+
__metadata("design:type", String)
|
|
291
|
+
], ParentComponent.prototype, "parentInput", void 0);
|
|
292
|
+
__decorate([
|
|
293
|
+
Output(),
|
|
294
|
+
__metadata("design:type", Object)
|
|
295
|
+
], ParentComponent.prototype, "parentOutput", void 0);
|
|
296
|
+
ParentComponent = __decorate([
|
|
297
|
+
Component({
|
|
298
|
+
selector: 'parent',
|
|
299
|
+
template: `<ng-content></ng-content>`,
|
|
300
|
+
})
|
|
301
|
+
], ParentComponent);
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { computesTemplateFromComponent } from './angular-beta/ComputesTemplateFromComponent';
|
|
2
|
+
import { isComponent } from './angular-beta/utils/NgComponentAnalyzer';
|
|
3
|
+
// We use `any` here as the default type rather than `Args` because we need something that is
|
|
4
|
+
// castable to any component-specific args type when the user is being careful.
|
|
5
|
+
export const moduleMetadata = (metadata) => (storyFn) => {
|
|
6
|
+
const story = storyFn();
|
|
7
|
+
const storyMetadata = story.moduleMetadata || {};
|
|
8
|
+
metadata = metadata || {};
|
|
9
|
+
return {
|
|
10
|
+
...story,
|
|
11
|
+
moduleMetadata: {
|
|
12
|
+
declarations: [...(metadata.declarations || []), ...(storyMetadata.declarations || [])],
|
|
13
|
+
entryComponents: [
|
|
14
|
+
...(metadata.entryComponents || []),
|
|
15
|
+
...(storyMetadata.entryComponents || []),
|
|
16
|
+
],
|
|
17
|
+
imports: [...(metadata.imports || []), ...(storyMetadata.imports || [])],
|
|
18
|
+
schemas: [...(metadata.schemas || []), ...(storyMetadata.schemas || [])],
|
|
19
|
+
providers: [...(metadata.providers || []), ...(storyMetadata.providers || [])],
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Decorator to set the config options which are available during the application bootstrap
|
|
25
|
+
* operation
|
|
26
|
+
*/
|
|
27
|
+
export function applicationConfig(
|
|
28
|
+
/** Set of config options available during the application bootstrap operation. */
|
|
29
|
+
config) {
|
|
30
|
+
return (storyFn) => {
|
|
31
|
+
const story = storyFn();
|
|
32
|
+
const storyConfig = story.applicationConfig;
|
|
33
|
+
return {
|
|
34
|
+
...story,
|
|
35
|
+
applicationConfig: storyConfig || config
|
|
36
|
+
? {
|
|
37
|
+
...config,
|
|
38
|
+
...storyConfig,
|
|
39
|
+
providers: [...(config?.providers || []), ...(storyConfig?.providers || [])],
|
|
40
|
+
}
|
|
41
|
+
: undefined,
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export const componentWrapperDecorator = (element, props) => (storyFn, storyContext) => {
|
|
46
|
+
const story = storyFn();
|
|
47
|
+
const currentProps = typeof props === 'function' ? props(storyContext) : props;
|
|
48
|
+
const template = isComponent(element)
|
|
49
|
+
? computesTemplateFromComponent(element, currentProps ?? {}, story.template)
|
|
50
|
+
: element(story.template);
|
|
51
|
+
return {
|
|
52
|
+
...story,
|
|
53
|
+
template,
|
|
54
|
+
...(currentProps || story.props
|
|
55
|
+
? {
|
|
56
|
+
props: {
|
|
57
|
+
...currentProps,
|
|
58
|
+
...story.props,
|
|
59
|
+
},
|
|
60
|
+
}
|
|
61
|
+
: {}),
|
|
62
|
+
};
|
|
63
|
+
};
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { vi, expect, describe, it } from 'vitest';
|
|
8
|
+
import { Component } from '@angular/core';
|
|
9
|
+
import { moduleMetadata, applicationConfig } from './decorators';
|
|
10
|
+
const defaultContext = {
|
|
11
|
+
componentId: 'unspecified',
|
|
12
|
+
kind: 'unspecified',
|
|
13
|
+
title: 'unspecified',
|
|
14
|
+
id: 'unspecified',
|
|
15
|
+
name: 'unspecified',
|
|
16
|
+
story: 'unspecified',
|
|
17
|
+
tags: [],
|
|
18
|
+
parameters: {},
|
|
19
|
+
initialArgs: {},
|
|
20
|
+
args: {},
|
|
21
|
+
argTypes: {},
|
|
22
|
+
globals: {},
|
|
23
|
+
globalTypes: {},
|
|
24
|
+
storyGlobals: {},
|
|
25
|
+
reporting: {
|
|
26
|
+
reports: [],
|
|
27
|
+
addReport: vi.fn(),
|
|
28
|
+
},
|
|
29
|
+
hooks: {},
|
|
30
|
+
loaded: {},
|
|
31
|
+
originalStoryFn: vi.fn(),
|
|
32
|
+
viewMode: 'story',
|
|
33
|
+
abortSignal: undefined,
|
|
34
|
+
canvasElement: undefined,
|
|
35
|
+
step: undefined,
|
|
36
|
+
context: undefined,
|
|
37
|
+
canvas: undefined,
|
|
38
|
+
userEvent: undefined,
|
|
39
|
+
mount: undefined,
|
|
40
|
+
};
|
|
41
|
+
defaultContext.context = defaultContext;
|
|
42
|
+
class MockModule {
|
|
43
|
+
}
|
|
44
|
+
class MockModuleTwo {
|
|
45
|
+
}
|
|
46
|
+
class MockService {
|
|
47
|
+
}
|
|
48
|
+
let MockComponent = class MockComponent {
|
|
49
|
+
};
|
|
50
|
+
MockComponent = __decorate([
|
|
51
|
+
Component({})
|
|
52
|
+
], MockComponent);
|
|
53
|
+
describe('applicationConfig', () => {
|
|
54
|
+
const provider1 = () => { };
|
|
55
|
+
const provider2 = () => { };
|
|
56
|
+
it('should apply global config', () => {
|
|
57
|
+
expect(applicationConfig({
|
|
58
|
+
providers: [provider1],
|
|
59
|
+
})(() => ({}), defaultContext)).toEqual({
|
|
60
|
+
applicationConfig: {
|
|
61
|
+
providers: [provider1],
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
it('should apply story config', () => {
|
|
66
|
+
expect(applicationConfig({
|
|
67
|
+
providers: [],
|
|
68
|
+
})(() => ({
|
|
69
|
+
applicationConfig: {
|
|
70
|
+
providers: [provider2],
|
|
71
|
+
},
|
|
72
|
+
}), {
|
|
73
|
+
...defaultContext,
|
|
74
|
+
})).toEqual({
|
|
75
|
+
applicationConfig: {
|
|
76
|
+
providers: [provider2],
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
it('should merge global and story config', () => {
|
|
81
|
+
expect(applicationConfig({
|
|
82
|
+
providers: [provider1],
|
|
83
|
+
})(() => ({
|
|
84
|
+
applicationConfig: {
|
|
85
|
+
providers: [provider2],
|
|
86
|
+
},
|
|
87
|
+
}), {
|
|
88
|
+
...defaultContext,
|
|
89
|
+
})).toEqual({
|
|
90
|
+
applicationConfig: {
|
|
91
|
+
providers: [provider1, provider2],
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
describe('moduleMetadata', () => {
|
|
97
|
+
it('should add metadata to a story without it', () => {
|
|
98
|
+
const result = moduleMetadata({
|
|
99
|
+
imports: [MockModule],
|
|
100
|
+
providers: [MockService],
|
|
101
|
+
})(() => ({}),
|
|
102
|
+
// deepscan-disable-next-line
|
|
103
|
+
defaultContext);
|
|
104
|
+
expect(result).toEqual({
|
|
105
|
+
moduleMetadata: {
|
|
106
|
+
declarations: [],
|
|
107
|
+
entryComponents: [],
|
|
108
|
+
imports: [MockModule],
|
|
109
|
+
schemas: [],
|
|
110
|
+
providers: [MockService],
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
it('should combine with individual metadata on a story', () => {
|
|
115
|
+
const result = moduleMetadata({
|
|
116
|
+
imports: [MockModule],
|
|
117
|
+
})(() => ({
|
|
118
|
+
component: MockComponent,
|
|
119
|
+
moduleMetadata: {
|
|
120
|
+
imports: [MockModuleTwo],
|
|
121
|
+
providers: [MockService],
|
|
122
|
+
},
|
|
123
|
+
}),
|
|
124
|
+
// deepscan-disable-next-line
|
|
125
|
+
defaultContext);
|
|
126
|
+
expect(result).toEqual({
|
|
127
|
+
component: MockComponent,
|
|
128
|
+
moduleMetadata: {
|
|
129
|
+
declarations: [],
|
|
130
|
+
entryComponents: [],
|
|
131
|
+
imports: [MockModule, MockModuleTwo],
|
|
132
|
+
schemas: [],
|
|
133
|
+
providers: [MockService],
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
it('should return the original metadata if passed null', () => {
|
|
138
|
+
const result = moduleMetadata(null)(() => ({
|
|
139
|
+
component: MockComponent,
|
|
140
|
+
moduleMetadata: {
|
|
141
|
+
providers: [MockService],
|
|
142
|
+
},
|
|
143
|
+
}),
|
|
144
|
+
// deepscan-disable-next-line
|
|
145
|
+
defaultContext);
|
|
146
|
+
expect(result).toEqual({
|
|
147
|
+
component: MockComponent,
|
|
148
|
+
moduleMetadata: {
|
|
149
|
+
declarations: [],
|
|
150
|
+
entryComponents: [],
|
|
151
|
+
imports: [],
|
|
152
|
+
schemas: [],
|
|
153
|
+
providers: [MockService],
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
});
|