|  | 
|  | 1 | +import 'jest-enzyme'; | 
|  | 2 | + | 
|  | 3 | +import { RootNode } from '@stoplight/json-schema-tree'; | 
|  | 4 | +import { Icon } from '@stoplight/mosaic'; | 
|  | 5 | +import { mount } from 'enzyme'; | 
|  | 6 | +import { JSONSchema4 } from 'json-schema'; | 
|  | 7 | +import * as React from 'react'; | 
|  | 8 | + | 
|  | 9 | +import { TopLevelSchemaRow } from '../SchemaRow/TopLevelSchemaRow'; | 
|  | 10 | +import { buildTree } from '../shared/__tests__/utils'; | 
|  | 11 | + | 
|  | 12 | +describe('resolving permission error', () => { | 
|  | 13 | +  let tree: RootNode; | 
|  | 14 | +  let schema: JSONSchema4; | 
|  | 15 | + | 
|  | 16 | +  it('given an object schema has a mixture of properties with and without x-sl-error-message, a permission denied error messsage should be shown on properties with x-sl-error-message', () => { | 
|  | 17 | +    schema = { | 
|  | 18 | +      title: 'User', | 
|  | 19 | +      type: 'object', | 
|  | 20 | +      description: '', | 
|  | 21 | +      properties: { | 
|  | 22 | +        id: { | 
|  | 23 | +          type: 'integer', | 
|  | 24 | +          description: 'Unique identifier for the given user.', | 
|  | 25 | +        }, | 
|  | 26 | +        firstName: { | 
|  | 27 | +          type: 'string', | 
|  | 28 | +        }, | 
|  | 29 | +        mailingAddress: { | 
|  | 30 | +          type: 'object', | 
|  | 31 | +          'x-sl-error-message': 'You do not have permission to view this reference', | 
|  | 32 | +          'x-sl-internally-excluded': true, | 
|  | 33 | +        }, | 
|  | 34 | +        billingAddresses: { | 
|  | 35 | +          type: 'array', | 
|  | 36 | +          'x-sl-error-message': 'You do not have permission to view this reference', | 
|  | 37 | +          'x-sl-internally-excluded': true, | 
|  | 38 | +        }, | 
|  | 39 | +      }, | 
|  | 40 | +    }; | 
|  | 41 | + | 
|  | 42 | +    tree = buildTree(schema); | 
|  | 43 | +    const wrapper = mount(<TopLevelSchemaRow schemaNode={tree.children[0]!} />); | 
|  | 44 | +    expect(wrapper.find(Icon).at(0)).toHaveProp('title', `You do not have permission to view this reference`); | 
|  | 45 | +    expect(wrapper.find(Icon).at(1)).toHaveProp('title', `You do not have permission to view this reference`); | 
|  | 46 | +    expect(wrapper.find(Icon).at(2)).not.toHaveProp('title', `You do not have permission to view this reference`); | 
|  | 47 | +    expect(wrapper.find(Icon).at(3)).not.toHaveProp('title', `You do not have permission to view this reference`); | 
|  | 48 | +    wrapper.unmount(); | 
|  | 49 | +  }); | 
|  | 50 | + | 
|  | 51 | +  it('given an object schema with all properties containing x-sl-error-message, a permission denied error messsage should be shown for each', () => { | 
|  | 52 | +    schema = { | 
|  | 53 | +      title: 'User', | 
|  | 54 | +      type: 'object', | 
|  | 55 | +      description: '', | 
|  | 56 | +      properties: { | 
|  | 57 | +        mailingAddress: { | 
|  | 58 | +          type: 'object', | 
|  | 59 | +          'x-sl-error-message': 'You do not have permission to view this reference', | 
|  | 60 | +          'x-sl-internally-excluded': true, | 
|  | 61 | +        }, | 
|  | 62 | +        testAddress: { | 
|  | 63 | +          type: 'string', | 
|  | 64 | +          'x-sl-error-message': 'You do not have permission to view this reference', | 
|  | 65 | +          'x-sl-internally-excluded': true, | 
|  | 66 | +        }, | 
|  | 67 | +        billingAddresses: { | 
|  | 68 | +          type: 'array', | 
|  | 69 | +          'x-sl-error-message': 'You do not have permission to view this reference', | 
|  | 70 | +          'x-sl-internally-excluded': true, | 
|  | 71 | +        }, | 
|  | 72 | +      }, | 
|  | 73 | +    }; | 
|  | 74 | + | 
|  | 75 | +    tree = buildTree(schema); | 
|  | 76 | +    const wrapper = mount(<TopLevelSchemaRow schemaNode={tree.children[0]!} />); | 
|  | 77 | +    expect(wrapper.find(Icon).at(0)).toHaveProp('title', `You do not have permission to view this reference`); | 
|  | 78 | +    expect(wrapper.find(Icon).at(1)).toHaveProp('title', `You do not have permission to view this reference`); | 
|  | 79 | +    expect(wrapper.find(Icon).at(2)).toHaveProp('title', `You do not have permission to view this reference`); | 
|  | 80 | +    wrapper.unmount(); | 
|  | 81 | +  }); | 
|  | 82 | + | 
|  | 83 | +  it('given an object schema where the toplevel contains x-sl-error-message, a permission denied error messsage should be shown', () => { | 
|  | 84 | +    schema = { | 
|  | 85 | +      type: 'object', | 
|  | 86 | +      'x-sl-error-message': 'You do not have permission to view this reference', | 
|  | 87 | +      'x-sl-internally-excluded': true, | 
|  | 88 | +    }; | 
|  | 89 | +    tree = buildTree(schema); | 
|  | 90 | +    const wrapper = mount(<TopLevelSchemaRow schemaNode={tree.children[0]!} />); | 
|  | 91 | +    expect(wrapper.find(Icon).at(0)).toHaveProp('title', `You do not have permission to view this reference`); | 
|  | 92 | +    wrapper.unmount(); | 
|  | 93 | +  }); | 
|  | 94 | + | 
|  | 95 | +  it('given an object schema has properties without ax-sl-error-message, a permission denied error messsage should not be shown', () => { | 
|  | 96 | +    schema = { | 
|  | 97 | +      title: 'User', | 
|  | 98 | +      type: 'object', | 
|  | 99 | +      description: '', | 
|  | 100 | +      properties: { | 
|  | 101 | +        id: { | 
|  | 102 | +          type: 'integer', | 
|  | 103 | +          description: 'Unique identifier for the given user.', | 
|  | 104 | +        }, | 
|  | 105 | +        firstName: { | 
|  | 106 | +          type: 'string', | 
|  | 107 | +        }, | 
|  | 108 | +        otherName: { | 
|  | 109 | +          type: 'array', | 
|  | 110 | +          items: { | 
|  | 111 | +            title: 'Address', | 
|  | 112 | +            type: 'object', | 
|  | 113 | +            description: '', | 
|  | 114 | +            properties: { | 
|  | 115 | +              id: { | 
|  | 116 | +                type: 'integer', | 
|  | 117 | +                description: 'Unique identifier for the given user.', | 
|  | 118 | +              }, | 
|  | 119 | +              location: { | 
|  | 120 | +                type: 'string', | 
|  | 121 | +              }, | 
|  | 122 | +            }, | 
|  | 123 | +          }, | 
|  | 124 | +        }, | 
|  | 125 | +      }, | 
|  | 126 | +    }; | 
|  | 127 | + | 
|  | 128 | +    tree = buildTree(schema); | 
|  | 129 | +    const wrapper = mount(<TopLevelSchemaRow schemaNode={tree.children[0]!} />); | 
|  | 130 | +    expect(wrapper.find(Icon).at(1)).not.toHaveProp('title', `You do not have permission to view this reference`); | 
|  | 131 | +    expect(wrapper.find(Icon).at(2)).not.toHaveProp('title', `You do not have permission to view this reference`); | 
|  | 132 | +    expect(wrapper.find(Icon).at(3)).not.toHaveProp('title', `You do not have permission to view this reference`); | 
|  | 133 | +    wrapper.unmount(); | 
|  | 134 | +  }); | 
|  | 135 | +}); | 
0 commit comments