@@ -1068,30 +1068,31 @@ describe("renderBrick for control nodes", () => {
10681068 expect ( output1 ) . toEqual ( {
10691069 blockingList : [ ] ,
10701070 node : expect . objectContaining ( {
1071- tag : RenderTag . BRICK ,
10721071 return : renderRoot ,
1073- type : "div" ,
1074- properties : {
1075- textContent : "a" ,
1076- title : "0/2" ,
1077- } ,
1078- slotId : undefined ,
1079- sibling : expect . objectContaining ( {
1072+ tag : RenderTag . ABSTRACT ,
1073+ child : expect . objectContaining ( {
10801074 tag : RenderTag . BRICK ,
1081- return : renderRoot ,
10821075 type : "div" ,
10831076 properties : {
1084- textContent : "b " ,
1085- title : "1 /2" ,
1077+ textContent : "a " ,
1078+ title : "0 /2" ,
10861079 } ,
10871080 slotId : undefined ,
1081+ sibling : expect . objectContaining ( {
1082+ tag : RenderTag . BRICK ,
1083+ type : "div" ,
1084+ properties : {
1085+ textContent : "b" ,
1086+ title : "1/2" ,
1087+ } ,
1088+ slotId : undefined ,
1089+ } ) ,
10881090 } ) ,
10891091 } ) ,
10901092 } ) ;
10911093 expect ( output2 ) . toEqual ( {
10921094 node : {
1093- tag : RenderTag . PLACEHOLDER ,
1094- tracking : false ,
1095+ tag : RenderTag . ABSTRACT ,
10951096 return : {
10961097 tag : RenderTag . ROOT ,
10971098 } ,
@@ -1623,31 +1624,36 @@ describe("renderBrick for control nodes", () => {
16231624 expect ( output1 ) . toEqual ( {
16241625 blockingList : [ ] ,
16251626 node : expect . objectContaining ( {
1626- tag : RenderTag . BRICK ,
1627+ tag : RenderTag . ABSTRACT ,
16271628 return : renderRoot ,
1628- type : "div" ,
1629- properties : {
1630- textContent : "Good" ,
1631- } ,
1632- slotId : undefined ,
1629+ child : expect . objectContaining ( {
1630+ tag : RenderTag . BRICK ,
1631+ type : "div" ,
1632+ properties : {
1633+ textContent : "Good" ,
1634+ } ,
1635+ slotId : undefined ,
1636+ } ) ,
16331637 } ) ,
16341638 } ) ;
16351639 expect ( output2 ) . toEqual ( {
16361640 blockingList : [ ] ,
16371641 node : expect . objectContaining ( {
1638- tag : RenderTag . BRICK ,
1642+ tag : RenderTag . ABSTRACT ,
16391643 return : renderRoot ,
1640- type : "div" ,
1641- properties : {
1642- textContent : "Bad" ,
1643- } ,
1644- slotId : undefined ,
1644+ child : expect . objectContaining ( {
1645+ tag : RenderTag . BRICK ,
1646+ type : "div" ,
1647+ properties : {
1648+ textContent : "Bad" ,
1649+ } ,
1650+ slotId : undefined ,
1651+ } ) ,
16451652 } ) ,
16461653 } ) ;
16471654 expect ( output3 ) . toEqual ( {
16481655 node : {
1649- tag : RenderTag . PLACEHOLDER ,
1650- tracking : false ,
1656+ tag : RenderTag . ABSTRACT ,
16511657 return : {
16521658 tag : RenderTag . ROOT ,
16531659 } ,
@@ -1691,28 +1697,34 @@ describe("renderBrick for control nodes", () => {
16911697 } ,
16921698 } ,
16931699 {
1694- iid : "if-a" ,
16951700 brick : ":if" ,
1696- dataSource : "<%= CTX.quality === 'bad' %>" ,
1701+ dataSource : true ,
16971702 children : [
16981703 {
1699- brick : "h2" ,
1700- properties : {
1701- textContent : "Warning" ,
1702- } ,
1704+ iid : "if-a" ,
1705+ brick : ":if" ,
1706+ dataSource : "<%= CTX.quality === 'bad' %>" ,
1707+ children : [
1708+ {
1709+ brick : "h2" ,
1710+ properties : {
1711+ textContent : "Warning" ,
1712+ } ,
1713+ } ,
1714+ ] ,
17031715 } ,
1704- ] ,
1705- } ,
1706- {
1707- iid : "if:b" ,
1708- brick : ":if" ,
1709- dataSource : "<%= CTX.quality === 'bad' %>" ,
1710- children : [
17111716 {
1712- brick : "p" ,
1713- properties : {
1714- textContent : "Not good" ,
1715- } ,
1717+ iid : "if:b" ,
1718+ brick : ":if" ,
1719+ dataSource : "<%= CTX.quality === 'bad' %>" ,
1720+ children : [
1721+ {
1722+ brick : "p" ,
1723+ properties : {
1724+ textContent : "Not good" ,
1725+ } ,
1726+ } ,
1727+ ] ,
17161728 } ,
17171729 ] ,
17181730 } ,
@@ -1751,6 +1763,90 @@ describe("renderBrick for control nodes", () => {
17511763 rendererContext . dispose ( ) ;
17521764 } ) ;
17531765
1766+ test ( "nested if" , async ( ) => {
1767+ const container = document . createElement ( "div" ) ;
1768+ const portal = document . createElement ( "div" ) ;
1769+ const renderRoot = {
1770+ tag : RenderTag . ROOT ,
1771+ container,
1772+ createPortal : portal ,
1773+ } as RenderRoot ;
1774+ const ctxStore = new DataStore ( "CTX" ) ;
1775+ const runtimeContext = {
1776+ ctxStore,
1777+ tplStateStoreMap : new Map ( ) ,
1778+ formStateStoreMap : new Map ( ) ,
1779+ pendingPermissionsPreCheck : [ ] as undefined [ ] ,
1780+ } as RuntimeContext ;
1781+ ctxStore . define (
1782+ [
1783+ {
1784+ name : "quality" ,
1785+ value : "good" ,
1786+ } ,
1787+ ] ,
1788+ runtimeContext
1789+ ) ;
1790+ const rendererContext = new RendererContext ( "page" ) ;
1791+ const output = await renderBricks (
1792+ renderRoot ,
1793+ [
1794+ {
1795+ brick : ":if" ,
1796+ dataSource : "<%= CTX.quality !== 'bad' %>" ,
1797+ children : [
1798+ {
1799+ iid : "if-a" ,
1800+ brick : ":if" ,
1801+ dataSource : "<%= CTX.quality === 'better' %>" ,
1802+ children : [
1803+ {
1804+ brick : "h2" ,
1805+ properties : {
1806+ textContent : "Better" ,
1807+ } ,
1808+ } ,
1809+ ] ,
1810+ } ,
1811+ {
1812+ brick : ":if" ,
1813+ dataSource : true ,
1814+ children : [
1815+ {
1816+ brick : "p" ,
1817+ properties : {
1818+ textContent : "Cool" ,
1819+ } ,
1820+ } ,
1821+ ] ,
1822+ } ,
1823+ ] ,
1824+ } ,
1825+ ] ,
1826+ runtimeContext ,
1827+ rendererContext ,
1828+ [ ] ,
1829+ { }
1830+ ) ;
1831+ renderRoot . child = output . node ;
1832+ await Promise . all ( [ ...output . blockingList , ctxStore . waitForAll ( ) ] ) ;
1833+ mountTree ( renderRoot ) ;
1834+ rendererContext . dispatchOnMount ( ) ;
1835+ rendererContext . initializeScrollIntoView ( ) ;
1836+
1837+ expect ( container . innerHTML ) . toBe ( "<p>Cool</p>" ) ;
1838+
1839+ ctxStore . updateValue ( "quality" , "better" , "replace" ) ;
1840+ await new Promise ( ( resolve ) => setTimeout ( resolve , 0 ) ) ;
1841+
1842+ expect ( container . innerHTML ) . toBe ( "<h2>Better</h2><p>Cool</p>" ) ;
1843+
1844+ unmountTree ( container ) ;
1845+ unmountTree ( portal ) ;
1846+ rendererContext . dispatchOnUnmount ( ) ;
1847+ rendererContext . dispose ( ) ;
1848+ } ) ;
1849+
17541850 test ( "re-render dynamic nodes with portal bricks from useBrick" , async ( ) => {
17551851 const container = document . createElement ( "div" ) ;
17561852 const portal = document . createElement ( "div" ) ;
@@ -1933,13 +2029,16 @@ describe("renderBrick for control nodes", () => {
19332029 expect ( output ) . toEqual ( {
19342030 blockingList : [ ] ,
19352031 node : expect . objectContaining ( {
1936- tag : RenderTag . BRICK ,
2032+ tag : RenderTag . ABSTRACT ,
19372033 return : renderRoot ,
1938- type : "div" ,
1939- properties : {
1940- textContent : "B" ,
1941- } ,
1942- slotId : undefined ,
2034+ child : expect . objectContaining ( {
2035+ tag : RenderTag . BRICK ,
2036+ type : "div" ,
2037+ properties : {
2038+ textContent : "B" ,
2039+ } ,
2040+ slotId : undefined ,
2041+ } ) ,
19432042 } ) ,
19442043 } ) ;
19452044 } ) ;
0 commit comments