You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the `PCF` component is a Virtual component you must build a template to place in the `stories\{ComponentName}.render.ts` that uses `ComponentFrameworkMockGeneratorReact<IInputs, IOutputs>` to render the component as follows:
3
+
4
+
```ts
5
+
// necessary imports
6
+
7
+
8
+
exportinterfaceStoryArgsextendsPCFStoryArgs {
9
+
// story field definition based on component
10
+
}
11
+
12
+
exportconst renderGenerator = () => {
13
+
let container:HTMLDivElement|null;
14
+
let mockGenerator:ComponentFrameworkMockGeneratorReact<IInputs, IOutputs>;
// for each parameter of type input or bound we use the typed method to update the value from Storybook like follows `mockGenerator.context._parameters.{Parameter}._SetValue(args.{Parameter});`
If the `PCF` component is a standard component you must build a template to place in the `stories\{ComponentName}.render.ts` that uses `ComponentFrameworkMockGenerator<IInputs, IOutputs>` to render the component as follows:
3
+
4
+
```ts
5
+
// necessary imports
6
+
7
+
8
+
exportinterfaceStoryArgsextendsPCFStoryArgs {
9
+
// story field definition based on component
10
+
}
11
+
12
+
exportconst renderGenerator = () => {
13
+
let container:HTMLDivElement|null;
14
+
let mockGenerator:ComponentFrameworkMockGenerator<IInputs, IOutputs>;
// for each parameter of type input or bound we use the typed method to update the value from Storybook like follows `mockGenerator.context._parameters.{Parameter}._SetValue(args.{Parameter});`
@@ -27,7 +27,7 @@ There are three main classes in this library that can be used to create a mock c
27
27
2.`ComponentFrameworkMockGeneratorReact`: This class generates a mock context for a virtual `PCF` component that uses `React` based on the provided configuration.
28
28
3.`ComponentFrameworkMockOrchestrator`: This class orchestrates the generation of mock contexts for multiple components, allowing you to manage and execute tests across different components in a unified manner.
29
29
30
-
To use these classes, you can follow the examples provided in the [API Reference](#api-reference) section below. Each class has its own set of methods and properties that allow you to customize the mock context according to your testing needs.
30
+
To use these classes, you can follow the examples provided in the [API Reference](@shko.online/ComponentFramework-Mock.API#api-reference) section below. Each class has its own set of methods and properties that allow you to customize the mock context according to your testing needs.
31
31
32
32
## Story Setup
33
33
@@ -43,9 +43,9 @@ make sure to run `npm install` after modifying the workspaces to ensure the new
43
43
44
44
make sure to run `npm run refreshTypes` after modifying the workspaces to ensure the new component types are properly refreshed.
45
45
46
-
Always read the `ControlManifest.Input.xml` file of the component to understand the expected inputs, outputs, and resources as this will help you set up the mock context correctly. From this file you can determine the `IInputs` and `IOutputs` types, as well as any `resx` or `css` that need to be loaded for the component.
46
+
Always read the `ControlManifest.Input.xml` file of the component to understand the expected inputs, outputs, and resources as this will help you set up the mock context correctly. From this file you can determine the `IInputs` and `IOutputs` types, as well as any `resx` or `css` that need to be loaded for the component. From `ControlManifest.Input.xml` you can also determine if the component uses `React` (defined by `control-type="virtual"`) or not which will help you decide which mock generator class to use. You should always tell the user which mock generator class you decided to use based on the `control-type` defined in the `ControlManifest.Input.xml` file.
47
47
48
-
check if the Storybook component brige file is set up. If not, create a new file in the `Storybook/Stories/Components` folder named `{ComponentName}.ts` and add the following code:
48
+
check if the Storybook component bridge file is set up. If not, create a new file in the `Storybook/Stories/Components` folder named `{ComponentName}.ts` and add the following code:
49
49
50
50
if a `resx` file is used by the component, make sure to load it using the `getFromResource` function exported from the component bridge file as shown below:
51
51
@@ -64,51 +64,4 @@ export type { IInputs, IOutputs } from "Relative Path to ManifestTypes";
64
64
65
65
```
66
66
67
-
<aname="api-reference"></a>
68
-
## API Reference
69
-
### Classes
70
-
71
-
72
-
73
-
<aname="componentframeworkmock"></a>
74
-
#### `ComponentFrameworkMock<IInputs, IOutputs>`
75
-
exported from `@shko.online/componentframework-mock/ComponentFrameworkMock`
76
-
77
-
**Properties:**
78
-
79
-
| Name | Type | Description |
80
-
|------|------|-------------|
81
-
|`db`|`MetadataDB`| - |
82
-
|`context`|`ContextMock<IInputs>`| - |
83
-
84
-
**Methods:**
85
-
86
-
| Method | Returns | Description |
87
-
|--------|---------|-------------|
88
-
|`ExecuteInit()`|`void`| - |
89
-
|`ExecuteUpdateView()`|`void`| - |
90
-
91
-
92
-
---
93
-
94
-
<aname="componentframeworkmockorchestrator"></a>
95
-
#### `ComponentFrameworkMockOrchestrator`
96
-
exported from `@shko.online/componentframework-mock/ComponentFrameworkMockOrchestrator`
if the component is a standard component use the `ComponentFrameworkMockGenerator` class to create a render function for the story as shown in the [Standard Component Story Render Template](@shko.online/StandardComponentStoryRenderTemplate) instructions file. If the component is a virtual `React` component use the `ComponentFrameworkMockGeneratorReact` class to create a render function for the story as shown in the [React Component Story Render Template](@shko.online/ReactComponentStoryRenderTemplate) instructions file.
0 commit comments