|
1 | 1 | import React from 'react';
|
2 |
| -import { act, render, screen } from '@testing-library/react'; |
| 2 | +import { act, render, screen, waitFor } from '@testing-library/react'; |
3 | 3 | import userEvent from '@testing-library/user-event';
|
4 | 4 |
|
5 | 5 | import FormTemplate from '../../../../../__mocks__/mock-form-template';
|
@@ -468,6 +468,59 @@ describe('condition test', () => {
|
468 | 468 | expect(() => screen.getByLabelText('field-2')).toThrow();
|
469 | 469 | });
|
470 | 470 |
|
| 471 | + it('should handle nested complex coniditions', async () => { |
| 472 | + const schema = { |
| 473 | + fields: [ |
| 474 | + { |
| 475 | + component: 'text-field', |
| 476 | + name: 'info.name.last', |
| 477 | + label: 'last name', |
| 478 | + }, |
| 479 | + { |
| 480 | + component: 'text-field', |
| 481 | + name: 'info.name.father', |
| 482 | + label: 'Father name', |
| 483 | + }, |
| 484 | + { |
| 485 | + component: 'text-field', |
| 486 | + name: 'info.name.equipment', |
| 487 | + label: 'Equipment name', |
| 488 | + }, |
| 489 | + { |
| 490 | + component: 'text-field', |
| 491 | + name: 'info.occupation', |
| 492 | + label: 'occupation', |
| 493 | + condition: { |
| 494 | + sequence: [ |
| 495 | + { |
| 496 | + and: [ |
| 497 | + { |
| 498 | + or: [ |
| 499 | + { when: 'info.name.father', is: 'Charles' }, |
| 500 | + { when: 'info.name.equipment', is: 'Gun' }, |
| 501 | + ], |
| 502 | + }, |
| 503 | + { when: 'info.name.last', is: 'Bond' }, |
| 504 | + ], |
| 505 | + then: { |
| 506 | + set: { 'info.occupation': 'SPY' }, |
| 507 | + }, |
| 508 | + else: { visible: true }, |
| 509 | + }, |
| 510 | + ], |
| 511 | + }, |
| 512 | + }, |
| 513 | + ], |
| 514 | + }; |
| 515 | + |
| 516 | + render(<FormRenderer {...initialProps} schema={schema} />); |
| 517 | + |
| 518 | + userEvent.type(screen.getByLabelText('info.name.last'), 'Bond'); |
| 519 | + userEvent.type(screen.getByLabelText('info.name.equipment'), 'Gun'); |
| 520 | + |
| 521 | + await waitFor(() => expect(screen.getByLabelText('info.occupation')).toHaveValue('SPY')); |
| 522 | + }); |
| 523 | + |
471 | 524 | describe('reducer', () => {
|
472 | 525 | it('returns default', () => {
|
473 | 526 | const initialState = {
|
|
0 commit comments