@strapi/plugin-documentation 4.12.0-beta.1 → 4.12.0-beta.4

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,625 +1,124 @@
1
1
  import React from 'react';
2
2
 
3
+ import { fixtures } from '@strapi/admin-test-utils';
3
4
  import { lightTheme, ThemeProvider } from '@strapi/design-system';
4
- import { render, screen, waitFor } from '@testing-library/react';
5
- import { createMemoryHistory } from 'history';
5
+ import { NotificationsProvider, RBACContext } from '@strapi/helper-plugin';
6
+ import { fireEvent, render as renderRTL, waitFor } from '@testing-library/react';
7
+ import userEvent from '@testing-library/user-event';
8
+ import { rest } from 'msw';
6
9
  import { IntlProvider } from 'react-intl';
7
10
  import { QueryClient, QueryClientProvider } from 'react-query';
8
- import { Router } from 'react-router-dom';
11
+ import { MemoryRouter } from 'react-router-dom';
9
12
 
13
+ import { server } from '../../../../../tests/server';
10
14
  import SettingsPage from '../index';
11
15
 
12
- import server from './server';
13
-
14
- jest.mock('@strapi/helper-plugin', () => ({
15
- ...jest.requireActual('@strapi/helper-plugin'),
16
- useNotification: jest.fn(),
17
- CheckPermissions: jest.fn(({ children }) => children),
18
- }));
19
-
20
- const client = new QueryClient({
21
- defaultOptions: {
22
- queries: {
23
- retry: false,
16
+ const render = ({ permissions } = { permissions: fixtures.permissions.allPermissions }) => ({
17
+ ...renderRTL(<SettingsPage />, {
18
+ wrapper({ children }) {
19
+ const client = new QueryClient({
20
+ defaultOptions: {
21
+ queries: {
22
+ retry: false,
23
+ },
24
+ },
25
+ });
26
+
27
+ // eslint-disable-next-line react-hooks/rules-of-hooks
28
+ const rbacContextValue = React.useMemo(
29
+ () => ({
30
+ allPermissions: permissions,
31
+ }),
32
+ []
33
+ );
34
+
35
+ return (
36
+ <MemoryRouter>
37
+ <ThemeProvider theme={lightTheme}>
38
+ <QueryClientProvider client={client}>
39
+ <IntlProvider locale="en" messages={{}} textComponent="span">
40
+ <NotificationsProvider>
41
+ <RBACContext.Provider value={rbacContextValue}>{children}</RBACContext.Provider>
42
+ </NotificationsProvider>
43
+ </IntlProvider>
44
+ </QueryClientProvider>
45
+ </ThemeProvider>
46
+ </MemoryRouter>
47
+ );
24
48
  },
25
- },
49
+ }),
50
+ user: userEvent.setup(),
26
51
  });
27
52
 
28
- const makeApp = (history) => (
29
- <Router history={history}>
30
- <ThemeProvider theme={lightTheme}>
31
- <QueryClientProvider client={client}>
32
- <IntlProvider locale="en" messages={{}} textComponent="span">
33
- <SettingsPage />
34
- </IntlProvider>
35
- </QueryClientProvider>
36
- </ThemeProvider>
37
- </Router>
38
- );
39
-
40
- describe('Plugin | Documentation | SettingsPage', () => {
41
- beforeAll(() => server.listen());
42
-
43
- beforeEach(() => jest.clearAllMocks());
44
-
45
- afterEach(() => server.resetHandlers());
46
-
47
- afterAll(() => server.close());
48
-
49
- it('renders and matches the snapshot', async () => {
50
- const history = createMemoryHistory();
51
- const App = makeApp(history);
52
- const {
53
- container: { firstChild },
54
- } = render(App);
55
-
56
- await waitFor(() => {
57
- expect(screen.getByText('Make the documentation endpoint private')).toBeInTheDocument();
58
- });
59
-
60
- expect(firstChild).toMatchInlineSnapshot(`
61
- .c6 {
62
- font-weight: 600;
63
- font-size: 2rem;
64
- line-height: 1.25;
65
- color: #32324d;
66
- }
67
-
68
- .c11 {
69
- font-size: 0.75rem;
70
- line-height: 1.33;
71
- font-weight: 600;
72
- color: #ffffff;
73
- }
74
-
75
- .c12 {
76
- font-size: 1rem;
77
- line-height: 1.5;
78
- color: #666687;
79
- }
80
-
81
- .c16 {
82
- font-weight: 500;
83
- font-size: 1rem;
84
- line-height: 1.25;
85
- color: #32324d;
86
- }
87
-
88
- .c21 {
89
- font-size: 0.75rem;
90
- line-height: 1.33;
91
- font-weight: 600;
92
- color: #32324d;
93
- }
94
-
95
- .c29 {
96
- font-size: 0.75rem;
97
- line-height: 1.33;
98
- font-weight: 600;
99
- color: #b72b1a;
100
- text-transform: uppercase;
101
- }
102
-
103
- .c31 {
104
- font-size: 0.75rem;
105
- line-height: 1.33;
106
- font-weight: 600;
107
- color: #666687;
108
- text-transform: uppercase;
109
- }
110
-
111
- .c33 {
112
- font-size: 0.75rem;
113
- line-height: 1.33;
114
- color: #666687;
115
- }
116
-
117
- .c1 {
118
- background: #f6f6f9;
119
- padding-top: 40px;
120
- padding-right: 56px;
121
- padding-bottom: 40px;
122
- padding-left: 56px;
123
- }
124
-
125
- .c3 {
126
- min-width: 0;
127
- }
128
-
129
- .c7 {
130
- background: #4945ff;
131
- padding: 8px;
132
- padding-right: 16px;
133
- padding-left: 16px;
134
- border-radius: 4px;
135
- border-color: #4945ff;
136
- border: 1px solid #4945ff;
137
- cursor: pointer;
138
- }
139
-
140
- .c13 {
141
- padding-right: 56px;
142
- padding-left: 56px;
143
- }
53
+ describe('SettingsPage', () => {
54
+ it('renders the setting page correctly', async () => {
55
+ const { getByRole, queryByText, getByText } = render();
144
56
 
145
- .c14 {
146
- background: #ffffff;
147
- padding-top: 24px;
148
- padding-right: 32px;
149
- padding-bottom: 24px;
150
- padding-left: 32px;
151
- border-radius: 4px;
152
- box-shadow: 0px 1px 4px rgba(33,33,52,0.1);
153
- }
57
+ expect(queryByText('Plugin settings are loading')).toBeInTheDocument();
154
58
 
155
- .c19 {
156
- max-width: 320px;
157
- }
59
+ await waitFor(() => expect(queryByText('Plugin settings are loading')).not.toBeInTheDocument());
158
60
 
159
- .c23 {
160
- background: #f6f6f9;
161
- padding: 4px;
162
- border-radius: 4px;
163
- border-style: solid;
164
- border-width: 1px;
165
- border-color: #dcdce4;
166
- position: relative;
167
- cursor: pointer;
168
- }
61
+ expect(getByRole('heading', { name: 'Documentation' })).toBeInTheDocument();
62
+ expect(getByText('Configure the documentation plugin')).toBeInTheDocument();
63
+ expect(getByRole('heading', { name: 'Settings' })).toBeInTheDocument();
169
64
 
170
- .c26 {
171
- background: #ffffff;
172
- padding-top: 8px;
173
- padding-right: 12px;
174
- padding-bottom: 8px;
175
- padding-left: 12px;
176
- border-radius: 4px;
177
- border-color: #dcdce4;
178
- border: 1px solid #dcdce4;
179
- -webkit-flex: 1 1 50%;
180
- -ms-flex: 1 1 50%;
181
- flex: 1 1 50%;
182
- }
65
+ expect(getByRole('button', { name: 'Save' })).toBeInTheDocument();
66
+ expect(getByRole('button', { name: 'Save' })).toHaveAttribute('aria-disabled', 'true');
183
67
 
184
- .c30 {
185
- background: transparent;
186
- padding-right: 12px;
187
- padding-left: 12px;
188
- border-radius: 4px;
189
- border-color: #f6f6f9;
190
- border: 1px solid #f6f6f9;
191
- -webkit-flex: 1 1 50%;
192
- -ms-flex: 1 1 50%;
193
- flex: 1 1 50%;
194
- }
195
-
196
- .c2 {
197
- -webkit-align-items: center;
198
- -webkit-box-align: center;
199
- -ms-flex-align: center;
200
- align-items: center;
201
- display: -webkit-box;
202
- display: -webkit-flex;
203
- display: -ms-flexbox;
204
- display: flex;
205
- -webkit-flex-direction: row;
206
- -ms-flex-direction: row;
207
- flex-direction: row;
208
- -webkit-box-pack: justify;
209
- -webkit-justify-content: space-between;
210
- -ms-flex-pack: justify;
211
- justify-content: space-between;
212
- }
213
-
214
- .c4 {
215
- -webkit-align-items: center;
216
- -webkit-box-align: center;
217
- -ms-flex-align: center;
218
- align-items: center;
219
- display: -webkit-box;
220
- display: -webkit-flex;
221
- display: -ms-flexbox;
222
- display: flex;
223
- -webkit-flex-direction: row;
224
- -ms-flex-direction: row;
225
- flex-direction: row;
226
- }
227
-
228
- .c8 {
229
- -webkit-align-items: center;
230
- -webkit-box-align: center;
231
- -ms-flex-align: center;
232
- align-items: center;
233
- display: -webkit-box;
234
- display: -webkit-flex;
235
- display: -ms-flexbox;
236
- display: flex;
237
- -webkit-flex-direction: row;
238
- -ms-flex-direction: row;
239
- flex-direction: row;
240
- gap: 8px;
241
- }
242
-
243
- .c15 {
244
- -webkit-align-items: stretch;
245
- -webkit-box-align: stretch;
246
- -ms-flex-align: stretch;
247
- align-items: stretch;
248
- display: -webkit-box;
249
- display: -webkit-flex;
250
- display: -ms-flexbox;
251
- display: flex;
252
- -webkit-flex-direction: column;
253
- -ms-flex-direction: column;
254
- flex-direction: column;
255
- gap: 16px;
256
- }
257
-
258
- .c20 {
259
- -webkit-align-items: stretch;
260
- -webkit-box-align: stretch;
261
- -ms-flex-align: stretch;
262
- align-items: stretch;
263
- display: -webkit-box;
264
- display: -webkit-flex;
265
- display: -ms-flexbox;
266
- display: flex;
267
- -webkit-flex-direction: column;
268
- -ms-flex-direction: column;
269
- flex-direction: column;
270
- gap: 4px;
271
- }
272
-
273
- .c24 {
274
- -webkit-align-items: center;
275
- -webkit-box-align: center;
276
- -ms-flex-align: center;
277
- align-items: center;
278
- display: -webkit-box;
279
- display: -webkit-flex;
280
- display: -ms-flexbox;
281
- display: flex;
282
- -webkit-flex-direction: row;
283
- -ms-flex-direction: row;
284
- flex-direction: row;
285
- -webkit-flex-wrap: wrap;
286
- -ms-flex-wrap: wrap;
287
- flex-wrap: wrap;
288
- }
289
-
290
- .c27 {
291
- -webkit-align-items: center;
292
- -webkit-box-align: center;
293
- -ms-flex-align: center;
294
- align-items: center;
295
- display: -webkit-box;
296
- display: -webkit-flex;
297
- display: -ms-flexbox;
298
- display: flex;
299
- -webkit-flex-direction: row;
300
- -ms-flex-direction: row;
301
- flex-direction: row;
302
- -webkit-box-pack: center;
303
- -webkit-justify-content: center;
304
- -ms-flex-pack: center;
305
- justify-content: center;
306
- }
307
-
308
- .c9 {
309
- position: relative;
310
- outline: none;
311
- }
312
-
313
- .c9 > svg {
314
- height: 12px;
315
- width: 12px;
316
- }
317
-
318
- .c9 > svg > g,
319
- .c9 > svg path {
320
- fill: #ffffff;
321
- }
322
-
323
- .c9[aria-disabled='true'] {
324
- pointer-events: none;
325
- }
326
-
327
- .c9:after {
328
- -webkit-transition-property: all;
329
- transition-property: all;
330
- -webkit-transition-duration: 0.2s;
331
- transition-duration: 0.2s;
332
- border-radius: 8px;
333
- content: '';
334
- position: absolute;
335
- top: -4px;
336
- bottom: -4px;
337
- left: -4px;
338
- right: -4px;
339
- border: 2px solid transparent;
340
- }
341
-
342
- .c9:focus-visible {
343
- outline: none;
344
- }
345
-
346
- .c9:focus-visible:after {
347
- border-radius: 8px;
348
- content: '';
349
- position: absolute;
350
- top: -5px;
351
- bottom: -5px;
352
- left: -5px;
353
- right: -5px;
354
- border: 2px solid #4945ff;
355
- }
356
-
357
- .c10 {
358
- height: 2rem;
359
- }
360
-
361
- .c10 svg {
362
- height: 0.75rem;
363
- width: auto;
364
- }
68
+ expect(getByRole('checkbox', { name: 'Restricted Access' })).toBeInTheDocument();
69
+ });
365
70
 
366
- .c10[aria-disabled='true'] {
367
- border: 1px solid #dcdce4;
368
- background: #eaeaef;
369
- }
71
+ it('should automatically render the password field if the server restricted access property is true', async () => {
72
+ server.use(
73
+ rest.get('*/getInfos', (req, res, ctx) => {
74
+ return res(
75
+ ctx.json({
76
+ documentationAccess: { restrictedAccess: true },
77
+ })
78
+ );
79
+ })
80
+ );
370
81
 
371
- .c10[aria-disabled='true'] .c5 {
372
- color: #666687;
373
- }
82
+ const { getByLabelText, queryByText } = render();
374
83
 
375
- .c10[aria-disabled='true'] svg > g,.c10[aria-disabled='true'] svg path {
376
- fill: #666687;
377
- }
84
+ expect(queryByText('Plugin settings are loading')).toBeInTheDocument();
378
85
 
379
- .c10[aria-disabled='true']:active {
380
- border: 1px solid #dcdce4;
381
- background: #eaeaef;
382
- }
86
+ await waitFor(() => expect(queryByText('Plugin settings are loading')).not.toBeInTheDocument());
383
87
 
384
- .c10[aria-disabled='true']:active .c5 {
385
- color: #666687;
386
- }
88
+ expect(getByLabelText('Password')).toBeInTheDocument();
387
89
 
388
- .c10[aria-disabled='true']:active svg > g,.c10[aria-disabled='true']:active svg path {
389
- fill: #666687;
390
- }
90
+ server.restoreHandlers();
91
+ });
391
92
 
392
- .c10:hover {
393
- border: 1px solid #7b79ff;
394
- background: #7b79ff;
395
- }
93
+ it('should render the password field when the Restricted Access checkbox is checked', async () => {
94
+ const { getByRole, getByLabelText, queryByText } = render();
396
95
 
397
- .c10:active {
398
- border: 1px solid #4945ff;
399
- background: #4945ff;
400
- }
96
+ expect(queryByText('Plugin settings are loading')).toBeInTheDocument();
401
97
 
402
- .c10 svg > g,
403
- .c10 svg path {
404
- fill: #ffffff;
405
- }
98
+ await waitFor(() => expect(queryByText('Plugin settings are loading')).not.toBeInTheDocument());
406
99
 
407
- .c22 {
408
- display: -webkit-box;
409
- display: -webkit-flex;
410
- display: -ms-flexbox;
411
- display: flex;
412
- -webkit-align-items: center;
413
- -webkit-box-align: center;
414
- -ms-flex-align: center;
415
- align-items: center;
416
- }
100
+ fireEvent.click(getByRole('checkbox', { name: 'Restricted Access' }));
417
101
 
418
- .c17 {
419
- display: grid;
420
- grid-template-columns: repeat(12,1fr);
421
- gap: 16px;
422
- }
102
+ expect(getByRole('button', { name: 'Save' })).toHaveAttribute('aria-disabled', 'false');
423
103
 
424
- .c18 {
425
- grid-column: span 6;
426
- max-width: 100%;
427
- }
104
+ expect(getByLabelText('Password')).toBeInTheDocument();
105
+ });
428
106
 
429
- .c0:focus-visible {
430
- outline: none;
431
- }
107
+ it('should allow me to type a password and save that settings change successfully', async () => {
108
+ const { getByRole, getByLabelText, queryByText, user, getByText } = render();
432
109
 
433
- .c25 {
434
- outline: none;
435
- box-shadow: 0;
436
- -webkit-transition-property: border-color,box-shadow,fill;
437
- transition-property: border-color,box-shadow,fill;
438
- -webkit-transition-duration: 0.2s;
439
- transition-duration: 0.2s;
440
- }
110
+ expect(queryByText('Plugin settings are loading')).toBeInTheDocument();
441
111
 
442
- .c25:focus-within {
443
- border: 1px solid #4945ff;
444
- box-shadow: #4945ff 0px 0px 0px 2px;
445
- }
112
+ await waitFor(() => expect(queryByText('Plugin settings are loading')).not.toBeInTheDocument());
446
113
 
447
- .c28 {
448
- padding-top: 6px;
449
- padding-bottom: 6px;
450
- }
114
+ fireEvent.click(getByRole('checkbox', { name: 'Restricted Access' }));
451
115
 
452
- .c32 {
453
- height: 100%;
454
- left: 0;
455
- opacity: 0;
456
- position: absolute;
457
- top: 0;
458
- z-index: 0;
459
- width: 100%;
460
- }
116
+ expect(getByRole('button', { name: 'Save' })).toHaveAttribute('aria-disabled', 'false');
461
117
 
462
- @media (max-width:68.75rem) {
463
- .c18 {
464
- grid-column: span 12;
465
- }
466
- }
118
+ await user.type(getByLabelText('Password'), 'password');
467
119
 
468
- @media (max-width:34.375rem) {
469
- .c18 {
470
- grid-column: span;
471
- }
472
- }
120
+ fireEvent.click(getByRole('button', { name: 'Save' }));
473
121
 
474
- <main
475
- aria-labelledby="main-content-title"
476
- class="c0"
477
- id="main-content"
478
- tabindex="-1"
479
- >
480
- <form
481
- action="#"
482
- novalidate=""
483
- >
484
- <div
485
- style="height: 0px;"
486
- >
487
- <div
488
- class="c1"
489
- data-strapi-header="true"
490
- >
491
- <div
492
- class="c2"
493
- >
494
- <div
495
- class="c3 c4"
496
- >
497
- <h1
498
- class="c5 c6"
499
- >
500
- Documentation
501
- </h1>
502
- </div>
503
- <button
504
- aria-disabled="true"
505
- class="c7 c8 c9 c10"
506
- disabled=""
507
- type="submit"
508
- >
509
- <div
510
- aria-hidden="true"
511
- class=""
512
- >
513
- <svg
514
- fill="none"
515
- height="1rem"
516
- viewBox="0 0 24 24"
517
- width="1rem"
518
- xmlns="http://www.w3.org/2000/svg"
519
- >
520
- <path
521
- d="M20.727 2.97a.2.2 0 0 1 .286 0l2.85 2.89a.2.2 0 0 1 0 .28L9.554 20.854a.2.2 0 0 1-.285 0l-9.13-9.243a.2.2 0 0 1 0-.281l2.85-2.892a.2.2 0 0 1 .284 0l6.14 6.209L20.726 2.97Z"
522
- fill="#212134"
523
- />
524
- </svg>
525
- </div>
526
- <span
527
- class="c5 c11"
528
- >
529
- Save
530
- </span>
531
- </button>
532
- </div>
533
- <p
534
- class="c5 c12"
535
- >
536
- Configure the documentation plugin
537
- </p>
538
- </div>
539
- </div>
540
- <div
541
- class="c13"
542
- >
543
- <div
544
- class="c14"
545
- >
546
- <div
547
- class="c15"
548
- >
549
- <h2
550
- class="c5 c16"
551
- >
552
- Settings
553
- </h2>
554
- <div
555
- class="c17"
556
- >
557
- <div
558
- class="c18"
559
- >
560
- <div
561
- class="c19"
562
- >
563
- <div
564
- class="c20"
565
- >
566
- <div
567
- class="c4"
568
- >
569
- <label
570
- class="c5 c21 c22"
571
- for=":r0:"
572
- >
573
- Restricted Access
574
- </label>
575
- </div>
576
- <div
577
- class="c23 c24 c25"
578
- wrap="wrap"
579
- >
580
- <div
581
- class="c26 c27 c28"
582
- >
583
- <span
584
- class="c5 c29"
585
- >
586
- Off
587
- </span>
588
- </div>
589
- <div
590
- class="c30 c27 c28"
591
- >
592
- <span
593
- class="c5 c31"
594
- >
595
- On
596
- </span>
597
- </div>
598
- <input
599
- aria-describedby=":r0:-hint :r0:-error"
600
- aria-disabled="false"
601
- aria-required="false"
602
- class="c32"
603
- id=":r0:"
604
- name="restrictedAccess"
605
- type="checkbox"
606
- />
607
- </div>
608
- <p
609
- class="c5 c33"
610
- id=":r0:-hint"
611
- >
612
- Make the documentation endpoint private
613
- </p>
614
- </div>
615
- </div>
616
- </div>
617
- </div>
618
- </div>
619
- </div>
620
- </div>
621
- </form>
622
- </main>
623
- `);
122
+ await waitFor(() => expect(getByText('Successfully updated settings')).toBeInTheDocument());
624
123
  });
625
124
  });