@servicetitan/docs-anvil-uikit-contrib 33.0.0 → 35.0.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.
@@ -82,7 +82,7 @@ Sometimes it can be redundant to show equal notifications to the user, in that c
82
82
 
83
83
  #### Multiline Message
84
84
 
85
- Notification message supports the newline control character, so if you need to show something list like just add `\r\n` between rows.
85
+ Notification message supports the newline control character, so if you need to show something list like just add `\n` between rows.
86
86
 
87
87
  <CodeDemo
88
88
  example={MultilineMessageExample}
@@ -2,10 +2,25 @@
2
2
  title: API
3
3
  ---
4
4
 
5
+ import Tabs from '@theme/Tabs';
6
+ import TabItem from '@theme/TabItem';
7
+
5
8
  ## MockApiCalls
6
9
 
7
10
  When it isn't practical to [mock the API service classes](/docs/frontend/testing/miscellaneous/migrating-from-autogenerated-mocks), use `MockApiCalls` to configure responses for API endpoints.
8
11
 
12
+ ### Examples
13
+
14
+ <Tabs
15
+ defaultValue="jest"
16
+ values={[
17
+ { label: 'Jest (default)', value: 'jest' },
18
+ { label: 'Vitest', value: 'vitest' },
19
+ { label: 'Storybook', value: 'storybook' },
20
+ ]}
21
+ >
22
+ <TabItem value="jest">
23
+
9
24
  ```ts
10
25
  describe('[admin] AppRoutes', () => {
11
26
  // Create helper to mock API calls
@@ -24,11 +39,80 @@ describe('[admin] AppRoutes', () => {
24
39
  });
25
40
  ```
26
41
 
42
+ </TabItem>
43
+ <TabItem value="vitest">
44
+
45
+ For Vitest tests, import from the `/vitest` entry point:
46
+
47
+ ```ts
48
+ import { MockApiCalls } from '@servicetitan/testing-library/vitest';
49
+ import { describe, it, expect, beforeEach } from 'vitest';
50
+
51
+ describe('[admin] AppRoutes', () => {
52
+ // Create helper to mock API calls
53
+ const apiResponses = new MockApiCalls();
54
+
55
+ beforeEach(() => {
56
+ apiResponses.reset();
57
+ // Configure /Admin/isGoEnvironment to return false
58
+ apiResponses.add(/Admin\/isGoEnvironment/, { body: () => false });
59
+ });
60
+
61
+ it('should handle unauthorized users', () => {
62
+ // Configure /Admin/GetClientData to return 401 Unauthorized
63
+ apiResponses.add(/Admin\/GetClientData/, { status: 401 });
64
+ // ... test logic
65
+ });
66
+ });
67
+ ```
68
+
69
+ </TabItem>
70
+ <TabItem value="storybook">
71
+
72
+ For use in Storybook stories or other contexts without Jest or Vitest, import from the `/mock-api-calls` entry point:
73
+
74
+ ```ts
75
+ import { MockApiCalls } from '@servicetitan/testing-library/mock-api-calls';
76
+ import type { Meta, StoryObj } from '@storybook/react';
77
+
78
+ const meta: Meta<typeof MyComponent> = {
79
+ component: MyComponent,
80
+ beforeEach: () => {
81
+ const mockApi = new MockApiCalls();
82
+ mockApi.reset();
83
+ mockApi.add('/api/users', {
84
+ body: () => [
85
+ { id: 1, name: 'John Doe' },
86
+ { id: 2, name: 'Jane Smith' },
87
+ ],
88
+ });
89
+
90
+ return () => {
91
+ mockApi.reset();
92
+ };
93
+ },
94
+ };
95
+
96
+ export default meta;
97
+ type Story = StoryObj<typeof MyComponent>;
98
+
99
+ export const Default: Story = {
100
+ render: () => <MyComponent />,
101
+ };
102
+ ```
103
+
104
+ :::caution
105
+ When using the `/mock-api-calls` entry point, jQuery mocking has limited functionality since no spy function is provided.
106
+ :::
107
+
108
+ </TabItem>
109
+ </Tabs>
110
+
27
111
  It exposes the following methods:
28
112
 
29
- - [add](#add): Configure an API response
30
- - [replace](#replace): Replace a previously configured response
31
- - [reset](#reset): Remove all previously configured responses
113
+ - [add](#add): Configure an API response
114
+ - [replace](#replace): Replace a previously configured response
115
+ - [reset](#reset): Remove all previously configured responses
32
116
 
33
117
  ### add
34
118
 
@@ -44,9 +128,9 @@ add(
44
128
  )
45
129
  ```
46
130
 
47
- - `path`: regular expression to match against GET request URLs, or string value that must equal GET request URL. If a URL matches more than one path, the first one wins.
48
- - `body`: function that returns the API response. If omitted, or if it returns `undefined`, the mock returns an empty object (`{}`).
49
- - `status`: HTTP status code for API response. Defaults to 200.
131
+ - `path`: regular expression to match against GET request URLs, or string value that must equal GET request URL. If a URL matches more than one path, the first one wins.
132
+ - `body`: function that returns the API response. If omitted, or if it returns `undefined`, the mock returns an empty object (`{}`).
133
+ - `status`: HTTP status code for API response. Defaults to 200.
50
134
 
51
135
  ```ts
52
136
  // Configure GET /desktop/version.json to return test clientVersion
@@ -80,8 +164,8 @@ replace(
80
164
  )
81
165
  ```
82
166
 
83
- - `path`: the exact regular expression to replace or exact string value to replace.
84
- - `response`: see [add](#add)
167
+ - `path`: the exact regular expression to replace or exact string value to replace.
168
+ - `response`: see [add](#add)
85
169
 
86
170
  The `path` must exactly match a previously configured API response. Otherwise, the function does nothing.
87
171
 
@@ -116,9 +200,9 @@ mockComponent(
116
200
  )
117
201
  ```
118
202
 
119
- - `renderChildren`: Set to `true` to render both the component and it's children Defaults to `false`.
120
- - `renderProps`: Set to `true` to render the component's props. Defaults to `true`.
121
- - `forwardRef`: Set to `true` when mocking a component that is wrapped within `React.forwardRef`. Defaults to `false`.
203
+ - `renderChildren`: Set to `true` to render both the component and it's children Defaults to `false`.
204
+ - `renderProps`: Set to `true` to render the component's props. Defaults to `true`.
205
+ - `forwardRef`: Set to `true` when mocking a component that is wrapped within `React.forwardRef`. Defaults to `false`.
122
206
 
123
207
  ```ts
124
208
  // Replace <BillingNewAdmin> component with placeholder
@@ -147,8 +231,8 @@ When called with a string, it sets `location.pathname`.
147
231
 
148
232
  Use the object signature to change either or both `location.origin` and `location.pathname`.
149
233
 
150
- - `origin`: new `location.origin`. Defaults to preserving previous value.
151
- - `pathname`: new `location.pathname`. Defaults to preserving previous value.
234
+ - `origin`: new `location.origin`. Defaults to preserving previous value.
235
+ - `pathname`: new `location.pathname`. Defaults to preserving previous value.
152
236
 
153
237
  To mock `window.location` without changing the value, pass an empty object.
154
238
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@servicetitan/docs-anvil-uikit-contrib",
3
- "version": "33.0.0",
3
+ "version": "35.0.0",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,5 +16,5 @@
16
16
  "cli": {
17
17
  "webpack": false
18
18
  },
19
- "gitHead": "73576ba8cbadb851c04aacc9c2fd295be3678d29"
19
+ "gitHead": "2d0ca381a54385f88a17412ea7382bc31da86696"
20
20
  }