@@ -1946,6 +1946,7 @@ describe('export-button.business', () => {
19461946
19471947 // Act
19481948 const result = placeAllTablesWithoutOverlap ( tables ) ;
1949+
19491950
19501951 // Assert
19511952 result . forEach ( ( table , index ) => {
@@ -1962,6 +1963,122 @@ describe('export-button.business', () => {
19621963 }
19631964 } ) ;
19641965 } ) ;
1966+
1967+ it ( 'Wide tables shouldnt be on the left border overlapping other tables after relocating. ' , ( ) => {
1968+ // Arrange
1969+ const tables : TableVm [ ] = [
1970+ {
1971+ id : '1' ,
1972+ fields : [
1973+ { id : '1' , PK : true , name : 'campo1' , type : 'string' , children : [ ] , isCollapsed : false , isArray : false } ,
1974+ { id : '2' , PK : true , name : 'campo2' , type : 'string' , children : [ ] , isCollapsed : false , isArray : false } ,
1975+ { id : '3' , PK : true , name : 'campo3' , type : 'string' , children : [ ] , isCollapsed : false , isArray : false } ,
1976+ { id : '4' , PK : true , name : 'campo4' , type : 'string' , children : [ ] , isCollapsed : false , isArray : false } ,
1977+ { id : '5' , PK : true , name : 'campo5' , type : 'string' , children : [ ] , isCollapsed : false , isArray : false } ,
1978+ { id : '6' , PK : true , name : 'campo6' , type : 'string' , children : [ ] , isCollapsed : false , isArray : false } ,
1979+ { id : '7' , PK : true , name : 'campo7' , type : 'string' , children : [ ] , isCollapsed : false , isArray : false } ,
1980+ ] ,
1981+ tableName : 'table1' ,
1982+ x : 100 ,
1983+ y : 300
1984+ } ,
1985+ {
1986+ id : '2' ,
1987+ fields : [
1988+ { id : '1' , PK : true , name : 'campo1' , type : 'string' , children : [ ] , isCollapsed : false , isArray : false } ,
1989+ { id : '2' , PK : true , name : 'campo2' , type : 'string' , children : [ ] , isCollapsed : false , isArray : false } ,
1990+ { id : '3' , PK : true , name : 'campo3' , type : 'string' , children : [ ] , isCollapsed : false , isArray : false } ,
1991+ { id : '4' , PK : true , name : 'campo4' , type : 'string' , children : [ ] , isCollapsed : false , isArray : false } ,
1992+ { id : '5' , PK : true , name : 'campo5' , type : 'string' , children : [ ] , isCollapsed : false , isArray : false } ,
1993+ { id : '6' , PK : true , name : 'campo6' , type : 'string' , children : [ ] , isCollapsed : false , isArray : false } ,
1994+ { id : '7' , PK : true , name : 'campo7' , type : 'string' , children : [ ] , isCollapsed : false , isArray : false } ,
1995+ { id : '8' , PK : true , name : 'campo8' , type : 'string' , children : [ ] , isCollapsed : false , isArray : false } ,
1996+ { id : '9' , PK : true , name : 'campo9' , type : 'string' , children : [ ] , isCollapsed : false , isArray : false } ,
1997+ { id : '10' , PK : true , name : 'campo10' , type : 'string' , children : [ ] , isCollapsed : false , isArray : false } ,
1998+ { id : '11' , PK : true , name : 'campo11' , type : 'string' , children : [ ] , isCollapsed : false , isArray : false } ,
1999+ { id : '12' , PK : true , name : 'campo12' , type : 'string' , children : [ ] , isCollapsed : false , isArray : false } ,
2000+ { id : '13' , PK : true , name : 'campo13' , type : 'string' , children : [ ] , isCollapsed : false , isArray : false } ,
2001+ { id : '14' , PK : true , name : 'campo14' , type : 'string' , children : [ ] , isCollapsed : false , isArray : false } ,
2002+ { id : '15' , PK : true , name : 'campo15' , type : 'string' , children : [ ] , isCollapsed : false , isArray : false } ,
2003+ { id : '16' , PK : true , name : 'campo16' , type : 'string' , children : [ ] , isCollapsed : false , isArray : false } ,
2004+ { id : '17' , PK : true , name : 'campo17' , type : 'string' , children : [ ] , isCollapsed : false , isArray : false } ,
2005+ { id : '18' , PK : true , name : 'campo18' , type : 'string' , children : [ ] , isCollapsed : false , isArray : false } ,
2006+ { id : '19' , PK : true , name : 'campo19' , type : 'string' , children : [ ] , isCollapsed : false , isArray : false } ,
2007+ { id : '20' , PK : true , name : 'campo20' , type : 'string' , children : [ ] , isCollapsed : false , isArray : false } ,
2008+ { id : '21' , PK : true , name : 'campo21' , type : 'string' , children : [ ] , isCollapsed : false , isArray : false } ,
2009+ { id : '22' , PK : true , name : 'campo22' , type : 'string' , children : [ ] , isCollapsed : false , isArray : false } ,
2010+ ] ,
2011+ tableName : 'table2' ,
2012+ x : 450 ,
2013+ y : 100 ,
2014+ width : 780
2015+ } ,
2016+ {
2017+ id : '3' ,
2018+ fields : [ ] ,
2019+ tableName : 'table3' ,
2020+ x : 1200 ,
2021+ y : 700
2022+ } ,
2023+ {
2024+ id : '4' ,
2025+ fields : [ ] ,
2026+ tableName : 'table4' ,
2027+ x : 1500 ,
2028+ y : 100
2029+ } ,
2030+ {
2031+ id : '5' ,
2032+ fields : [ ] ,
2033+ tableName : 'table5' ,
2034+ x : 300 ,
2035+ y : 100 ,
2036+ } ,
2037+ {
2038+ id : '6' ,
2039+ fields : [ ] ,
2040+ tableName : 'table6' ,
2041+ x : 100 ,
2042+ y : 150 ,
2043+ } ,
2044+ {
2045+ id : '7' ,
2046+ fields : [ ] ,
2047+ tableName : 'table7' ,
2048+ x : 150 ,
2049+ y : 150 ,
2050+ } ,
2051+ ] ;
2052+
2053+ // Act
2054+ const result = placeAllTablesWithoutOverlap ( tables ) ;
2055+
2056+
2057+ // Assert
2058+ result . forEach ( ( table , index ) => {
2059+ const tableWidth = table . width ?? TABLE_CONST . DEFAULT_TABLE_WIDTH ;
2060+ const tableHeight = calculateTableHeight ( table . fields ) ;
2061+ for ( let i = 0 ; i < result . length ; i ++ ) {
2062+ if ( i !== index ) {
2063+ const iWidth = result [ i ] . width ?? TABLE_CONST . DEFAULT_TABLE_WIDTH ;
2064+ const iHeight = calculateTableHeight ( result [ i ] . fields ) ;
2065+
2066+ const isOverlapping = ! (
2067+ table . x >= result [ i ] . x + iWidth ||
2068+ table . x + tableWidth <= result [ i ] . x ||
2069+ table . y >= result [ i ] . y + iHeight ||
2070+ table . y + tableHeight <= result [ i ] . y
2071+ ) ;
2072+
2073+ const hasBadPosition = ( isOverlapping ) &&
2074+ ( table . x <= TABLE_CONST . TABLE_SHIFT_DISTANCE ) &&
2075+ ( tableWidth > TABLE_CONST . DEFAULT_TABLE_WIDTH ) ;
2076+
2077+ expect ( hasBadPosition ) . toBe ( false ) ;
2078+ }
2079+ }
2080+ } ) ;
2081+ } ) ;
19652082 } ) ;
19662083} ) ;
19672084
@@ -1981,6 +2098,27 @@ describe('getPropertyJsonSchema', () => {
19812098 //Assert
19822099 expect ( result ) . toBe ( '"fieldName": { bsonType: "string" }' ) ;
19832100 } ) ;
2101+ } ) ;
2102+
2103+
2104+
2105+ describe ( 'getPropertyJsonSchema' , ( ) => {
2106+ it ( 'should generate json schema for non-array field' , ( ) => {
2107+ //Arrange
2108+ const field : FieldVm = {
2109+ id : '1' ,
2110+ PK : false ,
2111+ name : 'fieldName' ,
2112+ type : 'string' ,
2113+ } ;
2114+
2115+ //Act
2116+ const result = getPropertyJsonSchema ( field ) ;
2117+
2118+ //Assert
2119+ expect ( result ) . toBe ( '"fieldName": { bsonType: "string" }' ) ;
2120+ } ) ;
2121+
19842122
19852123 it ( 'should generate json schema for array field' , ( ) => {
19862124 //Arrange
0 commit comments