Skip to content

Commit 5a89f0f

Browse files
committed
Added tests for node helpers
1 parent 4b91758 commit 5a89f0f

File tree

2 files changed

+146
-6
lines changed

2 files changed

+146
-6
lines changed

src/EmptyFlow.SciterAPI.UnitTest/SciterAPIHostIntegrationTests.cs

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,6 +1320,146 @@ public void SciterAPIHost_Completed_GlobalPredefinedVariables () {
13201320
Assert.True ( falseValue );
13211321
}
13221322

1323+
[Fact, Trait ( "Category", "Integration" )]
1324+
public void SciterAPIHost_Completed_NodeNextSibling () {
1325+
//Arrange
1326+
var host = new SciterAPIHost ( "" );
1327+
1328+
host.CreateMainWindow ();
1329+
host.LoadHtml (
1330+
"""
1331+
<html>
1332+
<body>
1333+
<div>Sibling 1</div><div id="middlesibling">Sibling 2</div><div>Sibling 3</div>
1334+
</body>
1335+
</html>
1336+
"""
1337+
);
1338+
var html = "";
1339+
host.AddWindowEventHandler (
1340+
new DocumentReadyHandler (
1341+
() => {
1342+
var spanElement = host.MakeCssSelector ( "#middlesibling" ).First ();
1343+
var nextSibling = host.NodeNextSibling ( spanElement );
1344+
html = host.GetElementHtml ( nextSibling, false );
1345+
host.CloseWindow ( host.MainWindow );
1346+
},
1347+
host
1348+
)
1349+
);
1350+
1351+
//Act
1352+
host.Process ();
1353+
1354+
//Assert
1355+
Assert.Equal ( "Sibling 3", html );
1356+
}
1357+
1358+
[Fact, Trait ( "Category", "Integration" )]
1359+
public void SciterAPIHost_Completed_NodePreviousSibling () {
1360+
//Arrange
1361+
var host = new SciterAPIHost ( "" );
1362+
1363+
host.CreateMainWindow ();
1364+
host.LoadHtml (
1365+
"""
1366+
<html>
1367+
<body>
1368+
<div>Sibling 1</div><div id="middlesibling">Sibling 2</div><div>Sibling 3</div>
1369+
</body>
1370+
</html>
1371+
"""
1372+
);
1373+
var html = "";
1374+
host.AddWindowEventHandler (
1375+
new DocumentReadyHandler (
1376+
() => {
1377+
var spanElement = host.MakeCssSelector ( "#middlesibling" ).First ();
1378+
var nextSibling = host.NodePreviousSibling ( spanElement );
1379+
html = host.GetElementHtml ( nextSibling, false );
1380+
host.CloseWindow ( host.MainWindow );
1381+
},
1382+
host
1383+
)
1384+
);
1385+
1386+
//Act
1387+
host.Process ();
1388+
1389+
//Assert
1390+
Assert.Equal ( "Sibling 1", html );
1391+
}
1392+
1393+
[Fact, Trait ( "Category", "Integration" )]
1394+
public void SciterAPIHost_Completed_NodeFirstChild () {
1395+
//Arrange
1396+
var host = new SciterAPIHost ( "" );
1397+
1398+
host.CreateMainWindow ();
1399+
host.LoadHtml (
1400+
"""
1401+
<html>
1402+
<body>
1403+
<div id="container"><div>Sibling 1</div><div>Sibling 2</div><div>Sibling 3</div></div>
1404+
</body>
1405+
</html>
1406+
"""
1407+
);
1408+
var html = "";
1409+
host.AddWindowEventHandler (
1410+
new DocumentReadyHandler (
1411+
() => {
1412+
var spanElement = host.MakeCssSelector ( "#container" ).First ();
1413+
var firstChild = host.NodeFirstChild ( spanElement );
1414+
html = host.GetElementText ( firstChild );
1415+
host.CloseWindow ( host.MainWindow );
1416+
},
1417+
host
1418+
)
1419+
);
1420+
1421+
//Act
1422+
host.Process ();
1423+
1424+
//Assert
1425+
Assert.Equal ( "Sibling 1", html );
1426+
}
1427+
1428+
[Fact, Trait ( "Category", "Integration" )]
1429+
public void SciterAPIHost_Completed_NodeLastChild () {
1430+
//Arrange
1431+
var host = new SciterAPIHost ( "" );
1432+
1433+
host.CreateMainWindow ();
1434+
host.LoadHtml (
1435+
"""
1436+
<html>
1437+
<body>
1438+
<div id="container"><div>Sibling 1</div><div>Sibling 2</div><div>Sibling 3</div></div>
1439+
</body>
1440+
</html>
1441+
"""
1442+
);
1443+
var html = "";
1444+
host.AddWindowEventHandler (
1445+
new DocumentReadyHandler (
1446+
() => {
1447+
var spanElement = host.MakeCssSelector ( "#container" ).First ();
1448+
var lastChild = host.NodeLastChild ( spanElement );
1449+
html = host.GetElementText ( lastChild );
1450+
host.CloseWindow ( host.MainWindow );
1451+
},
1452+
host
1453+
)
1454+
);
1455+
1456+
//Act
1457+
host.Process ();
1458+
1459+
//Assert
1460+
Assert.Equal ( "Sibling 3", html );
1461+
}
1462+
13231463
}
13241464

13251465
public class DocumentReadyHandler : SciterEventHandler {

src/EmptyFlow.SciterAPI/Client/HostNodeAPI.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public nint NodeNextSibling ( nint node ) {
3131
/// <param name="node">Node/Element.</param>
3232
/// <returns>Previous sibling node/element or zero.</returns>
3333
public nint NodePreviousSibling ( nint node ) {
34-
var domResult = m_basicApi.SciterNodePrevSibling ( node, out var nextNode );
35-
if ( domResult == DomResult.SCDOM_OK ) return nextNode;
34+
var domResult = m_basicApi.SciterNodePrevSibling ( node, out var previousNode );
35+
if ( domResult == DomResult.SCDOM_OK ) return previousNode;
3636

3737
return nint.Zero;
3838
}
@@ -43,8 +43,8 @@ public nint NodePreviousSibling ( nint node ) {
4343
/// <param name="node">Node/Element.</param>
4444
/// <returns>Next sibling node/element or zero.</returns>
4545
public nint NodeFirstChild ( nint node ) {
46-
var domResult = m_basicApi.SciterNodeFirstChild ( node, out var nextNode );
47-
if ( domResult == DomResult.SCDOM_OK ) return nextNode;
46+
var domResult = m_basicApi.SciterNodeFirstChild ( node, out var firstChild );
47+
if ( domResult == DomResult.SCDOM_OK ) return firstChild;
4848

4949
return nint.Zero;
5050
}
@@ -55,8 +55,8 @@ public nint NodeFirstChild ( nint node ) {
5555
/// <param name="node">Node/Element.</param>
5656
/// <returns>Previous sibling node/element or zero.</returns>
5757
public nint NodeLastChild ( nint node ) {
58-
var domResult = m_basicApi.SciterNodeLastChild ( node, out var nextNode );
59-
if ( domResult == DomResult.SCDOM_OK ) return nextNode;
58+
var domResult = m_basicApi.SciterNodeLastChild ( node, out var lastChild );
59+
if ( domResult == DomResult.SCDOM_OK ) return lastChild;
6060

6161
return nint.Zero;
6262
}

0 commit comments

Comments
 (0)