@@ -10,6 +10,7 @@ import React from 'react';
1010
1111import ReactDOM from 'react-dom' ;
1212import expect from 'expect' ;
13+ import TestUtils from "react-dom/test-utils" ;
1314import AttributesEditor from '../AttributesEditor.jsx' ;
1415const constraints = {
1516 attributes : {
@@ -51,6 +52,54 @@ describe('Attributes Editor component', () => {
5152 expect ( rows ) . toExist ( ) ;
5253 expect ( rows . length ) . toBe ( 3 ) ;
5354 } ) ;
55+ it ( 'render attributes on setOption' , ( done ) => {
56+ TestUtils . act ( ( ) => {
57+ ReactDOM . render ( < AttributesEditor
58+ setOption = { ( value ) => {
59+ try {
60+ expect ( value . key ) . toBe ( 'attributes' ) ;
61+ expect ( value . value ) . toEqual ( { "attribute" : [ { "name" : "the_geom" , "access" : "READONLY" } , { "access" : "READONLY" , "name" : "cat" } ] } ) ;
62+ } catch ( e ) {
63+ done ( e ) ;
64+ }
65+ done ( ) ;
66+ } }
67+ attributes = { attributes } active
68+ constraints = { constraints }
69+ /> , document . getElementById ( "container" ) ) ;
70+ } ) ;
71+ const container = document . getElementById ( 'container' ) ;
72+ const rows = container . querySelectorAll ( '.row' ) ;
73+ expect ( rows ) . toBeTruthy ( ) ;
74+ } ) ;
75+ it ( 'render attributes on change value' , ( done ) => {
76+ TestUtils . act ( ( ) => {
77+ ReactDOM . render ( < AttributesEditor
78+ setOption = { ( value ) => {
79+ try {
80+ const isModified = value . value ?. attribute ?. some ( attr => attr . access === 'READWRITE' ) ;
81+ if ( isModified ) {
82+ expect ( value . key ) . toBe ( 'attributes' ) ;
83+ expect ( value . value ) . toEqual ( { "attribute" : [ { "name" : "cat" , "access" : "READWRITE" } ] } ) ;
84+ }
85+ } catch ( e ) {
86+ done ( e ) ;
87+ }
88+ done ( ) ;
89+ } }
90+ attributes = { attributes } active
91+ constraints = { constraints }
92+ /> , document . getElementById ( "container" ) ) ;
93+ } ) ;
94+ const container = document . getElementById ( 'container' ) ;
95+ const rows = container . querySelectorAll ( '.row' ) ;
96+ expect ( rows ) . toBeTruthy ( ) ;
97+ const rule = document . querySelectorAll ( '.Select-control' ) [ 1 ] ;
98+ expect ( rule ) . toBeTruthy ( ) ;
99+ TestUtils . Simulate . mouseDown ( rule , { button : 0 } ) ;
100+ TestUtils . Simulate . keyDown ( rule , { keyCode : 40 , key : 'ArrowDown' } ) ;
101+ TestUtils . Simulate . keyDown ( rule , { key : 'Enter' , keyCode : 13 } ) ;
102+ } ) ;
54103 it ( 'render attributes with highlighted DD' , ( ) => {
55104 ReactDOM . render ( < AttributesEditor editedAttributes = { [ "cat" ] } attributes = { attributes } active constraints = { constraints } /> , document . getElementById ( "container" ) ) ;
56105 const container = document . getElementById ( 'container' ) ;
0 commit comments