1- import 'jest-enzyme ' ;
1+ import '@testing-library/ jest-dom ' ;
22
33import { RootNode } from '@stoplight/json-schema-tree' ;
4- import { Icon } from '@stoplight/mosaic' ;
5- import { mount } from 'enzyme' ;
4+ import { render } from '@testing-library/react' ;
65import { JSONSchema4 } from 'json-schema' ;
76import * as React from 'react' ;
7+ import { beforeEach , describe , expect , it } from 'vitest' ;
88
99import { SchemaRow } from '../SchemaRow' ;
1010import { buildTree , findNodeWithPath } from '../shared/__tests__/utils' ;
11- import { Properties } from '../shared/Properties' ;
1211
1312describe ( 'SchemaRow component' , ( ) => {
1413 describe ( 'resolving error' , ( ) => {
@@ -28,13 +27,12 @@ describe('SchemaRow component', () => {
2827 tree = buildTree ( schema ) ;
2928 } ) ;
3029
31- it ( 'given no custom resolver, should render a generic error message' , ( ) => {
32- const wrapper = mount ( < SchemaRow schemaNode = { tree . children [ 0 ] ! } nestingLevel = { 0 } /> ) ;
33- expect ( wrapper . find ( Icon ) . at ( 1 ) ) . toHaveProp ( 'aria-label' , `Could not resolve '#/properties/foo'` ) ;
34- wrapper . unmount ( ) ;
30+ it ( 'given no custom resolver, should render a generic error message' , async ( ) => {
31+ const wrapper = render ( < SchemaRow schemaNode = { tree . children [ 0 ] ! } nestingLevel = { 0 } /> ) ;
32+ expect ( await wrapper . findByLabelText ( `Could not resolve '#/properties/foo'` ) ) . toBeInTheDocument ( ) ;
3533 } ) ;
3634
37- it ( 'given a custom resolver, should render a message thrown by it' , ( ) => {
35+ it ( 'given a custom resolver, should render a message thrown by it' , async ( ) => {
3836 const message = "I don't know how to resolve it. Sorry" ;
3937
4038 tree = buildTree ( schema , {
@@ -43,77 +41,71 @@ describe('SchemaRow component', () => {
4341 } ,
4442 } ) ;
4543
46- const wrapper = mount ( < SchemaRow schemaNode = { tree . children [ 0 ] ! } nestingLevel = { 0 } /> ) ;
47- expect ( wrapper . find ( Icon ) . at ( 1 ) ) . toHaveProp ( 'aria-label' , message ) ;
48- wrapper . unmount ( ) ;
44+ const wrapper = render ( < SchemaRow schemaNode = { tree . children [ 0 ] ! } nestingLevel = { 0 } /> ) ;
45+ expect ( await wrapper . findByLabelText ( message ) ) . toBeInTheDocument ( ) ;
4946 } ) ;
5047 } ) ;
5148
5249 describe ( 'resolving permission error' , ( ) => {
5350 let tree : RootNode ;
5451 let schema : JSONSchema4 ;
5552
56- it ( 'given an object schema is marked as internal, a permission denied error message should be shown' , ( ) => {
53+ it ( 'given an object schema is marked as internal, a permission denied error message should be shown' , async ( ) => {
5754 schema = {
5855 type : 'object' ,
5956 'x-sl-internally-excluded' : true ,
6057 'x-sl-error-message' : 'You do not have permission to view this reference' ,
6158 } ;
6259 tree = buildTree ( schema ) ;
63- const wrapper = mount ( < SchemaRow schemaNode = { tree . children [ 0 ] ! } nestingLevel = { 0 } /> ) ;
64- expect ( wrapper . find ( Icon ) . at ( 0 ) ) . toHaveProp ( 'aria-label' , `You do not have permission to view this reference` ) ;
65- wrapper . unmount ( ) ;
60+ const wrapper = render ( < SchemaRow schemaNode = { tree . children [ 0 ] ! } nestingLevel = { 0 } /> ) ;
61+ expect ( await wrapper . findByLabelText ( `You do not have permission to view this reference` ) ) . toBeInTheDocument ( ) ;
6662 } ) ;
6763
68- it ( 'given a number schema is marked as internal, a permission denied error messsage should be shown' , ( ) => {
64+ it ( 'given a number schema is marked as internal, a permission denied error messsage should be shown' , async ( ) => {
6965 schema = {
7066 type : 'number' ,
7167 'x-sl-internally-excluded' : true ,
7268 'x-sl-error-message' : 'You do not have permission to view this reference' ,
7369 } ;
7470 tree = buildTree ( schema ) ;
75- const wrapper = mount ( < SchemaRow schemaNode = { tree . children [ 0 ] ! } nestingLevel = { 0 } /> ) ;
76- expect ( wrapper . find ( Icon ) . at ( 0 ) ) . toHaveProp ( 'aria-label' , `You do not have permission to view this reference` ) ;
77- wrapper . unmount ( ) ;
71+ const wrapper = render ( < SchemaRow schemaNode = { tree . children [ 0 ] ! } nestingLevel = { 0 } /> ) ;
72+ expect ( await wrapper . findByLabelText ( `You do not have permission to view this reference` ) ) . toBeInTheDocument ( ) ;
7873 } ) ;
7974
80- it ( 'given an integer schema is marked as internal, a permission denied error messsage should be shown' , ( ) => {
75+ it ( 'given an integer schema is marked as internal, a permission denied error messsage should be shown' , async ( ) => {
8176 schema = {
8277 type : 'integer' ,
8378 'x-sl-internally-excluded' : true ,
8479 'x-sl-error-message' : 'You do not have permission to view this reference' ,
8580 } ;
8681 tree = buildTree ( schema ) ;
87- const wrapper = mount ( < SchemaRow schemaNode = { tree . children [ 0 ] ! } nestingLevel = { 0 } /> ) ;
88- expect ( wrapper . find ( Icon ) . at ( 0 ) ) . toHaveProp ( 'aria-label' , `You do not have permission to view this reference` ) ;
89- wrapper . unmount ( ) ;
82+ const wrapper = render ( < SchemaRow schemaNode = { tree . children [ 0 ] ! } nestingLevel = { 0 } /> ) ;
83+ expect ( await wrapper . findByLabelText ( `You do not have permission to view this reference` ) ) . toBeInTheDocument ( ) ;
9084 } ) ;
9185
92- it ( 'given a string schema is marked as internal, a permission denied error messsage should be shown' , ( ) => {
86+ it ( 'given a string schema is marked as internal, a permission denied error messsage should be shown' , async ( ) => {
9387 schema = {
9488 type : 'string' ,
9589 'x-sl-internally-excluded' : true ,
9690 'x-sl-error-message' : 'You do not have permission to view this reference' ,
9791 } ;
9892 tree = buildTree ( schema ) ;
99- const wrapper = mount ( < SchemaRow schemaNode = { tree . children [ 0 ] ! } nestingLevel = { 0 } /> ) ;
100- expect ( wrapper . find ( Icon ) . at ( 0 ) ) . toHaveProp ( 'aria-label' , `You do not have permission to view this reference` ) ;
101- wrapper . unmount ( ) ;
93+ const wrapper = render ( < SchemaRow schemaNode = { tree . children [ 0 ] ! } nestingLevel = { 0 } /> ) ;
94+ expect ( await wrapper . findByLabelText ( `You do not have permission to view this reference` ) ) . toBeInTheDocument ( ) ;
10295 } ) ;
10396
104- it ( 'given a boolean schema is marked as internal, a permission denied error messsage should be shown' , ( ) => {
97+ it ( 'given a boolean schema is marked as internal, a permission denied error messsage should be shown' , async ( ) => {
10598 schema = {
10699 type : 'boolean' ,
107100 'x-sl-internally-excluded' : true ,
108101 'x-sl-error-message' : 'You do not have permission to view this reference' ,
109102 } ;
110103 tree = buildTree ( schema ) ;
111- const wrapper = mount ( < SchemaRow schemaNode = { tree . children [ 0 ] ! } nestingLevel = { 0 } /> ) ;
112- expect ( wrapper . find ( Icon ) . at ( 0 ) ) . toHaveProp ( 'aria-label' , `You do not have permission to view this reference` ) ;
113- wrapper . unmount ( ) ;
104+ const wrapper = render ( < SchemaRow schemaNode = { tree . children [ 0 ] ! } nestingLevel = { 0 } /> ) ;
105+ expect ( await wrapper . findByLabelText ( `You do not have permission to view this reference` ) ) . toBeInTheDocument ( ) ;
114106 } ) ;
115107
116- it ( 'given an array schema is marked as internal, a permission denied error messsage should be shown' , ( ) => {
108+ it ( 'given an array schema is marked as internal, a permission denied error messsage should be shown' , async ( ) => {
117109 schema = {
118110 title : 'test' ,
119111 type : 'array' ,
@@ -124,9 +116,8 @@ describe('SchemaRow component', () => {
124116 } ,
125117 } ;
126118 tree = buildTree ( schema ) ;
127- const wrapper = mount ( < SchemaRow schemaNode = { tree . children [ 0 ] ! } nestingLevel = { 0 } /> ) ;
128- expect ( wrapper . find ( Icon ) . at ( 0 ) ) . toHaveProp ( 'aria-label' , `You do not have permission to view this reference` ) ;
129- wrapper . unmount ( ) ;
119+ const wrapper = render ( < SchemaRow schemaNode = { tree . children [ 0 ] ! } nestingLevel = { 0 } /> ) ;
120+ expect ( await wrapper . findByLabelText ( `You do not have permission to view this reference` ) ) . toBeInTheDocument ( ) ;
130121 } ) ;
131122 } ) ;
132123
@@ -140,9 +131,13 @@ describe('SchemaRow component', () => {
140131 if ( ! schemaNode ) {
141132 throw Error ( 'Node not found, invalid configuration' ) ;
142133 }
143- const wrapper = mount ( < SchemaRow schemaNode = { schemaNode } nestingLevel = { 0 } /> ) ;
144- expect ( wrapper . find ( Properties ) ) . toHaveProp ( 'required' , value ) ;
145- wrapper . unmount ( ) ;
134+ const wrapper = render ( < SchemaRow schemaNode = { schemaNode } nestingLevel = { 0 } /> ) ;
135+ const requiredEl = wrapper . queryByTestId ( 'property-required' ) ;
136+ if ( value ) {
137+ expect ( requiredEl ) . toBeInTheDocument ( ) ;
138+ } else {
139+ expect ( requiredEl ) . not . toBeInTheDocument ( ) ;
140+ }
146141 }
147142
148143 beforeEach ( ( ) => {
@@ -276,17 +271,16 @@ describe('SchemaRow component', () => {
276271 } ;
277272 } ) ;
278273
279- it ( 'should render correct type name for binary type' , ( ) => {
274+ it ( 'should render correct type name for binary type' , async ( ) => {
280275 const tree = buildTree ( schema ) ;
281276
282277 const schemaNode = findNodeWithPath ( tree , [ 'properties' , 'profile_photo' ] ) ;
283278 if ( ! schemaNode ) {
284279 throw Error ( 'Node not found, invalid configuration' ) ;
285280 }
286- const wrapper = mount ( < SchemaRow schemaNode = { schemaNode } nestingLevel = { 0 } /> ) ;
287- const spanWrapper = wrapper . find ( { 'data-test' : 'property-type' } ) ;
288- expect ( spanWrapper . at ( 0 ) . text ( ) ) . toContain ( 'string<binary>' ) ;
289- wrapper . unmount ( ) ;
281+ const wrapper = render ( < SchemaRow schemaNode = { schemaNode } nestingLevel = { 0 } /> ) ;
282+ const spanWrapper = await wrapper . findByTestId ( 'property-type' ) ;
283+ expect ( spanWrapper ) . toHaveTextContent ( 'string<binary>' ) ;
290284 } ) ;
291285 } ) ;
292286} ) ;
0 commit comments