1+
2+ using Bunit ;
3+ using Bunit . TestDoubles ;
4+ using NUnit . Framework ;
5+ using FWO . Api . Client ;
6+ using FWO . Config . Api ;
7+ using FWO . Report ;
8+ using FWO . Ui . Shared ;
9+ using Microsoft . Extensions . DependencyInjection ;
10+ using AngleSharp . Dom ;
11+ using AngleSharp . Css . Dom ;
12+ using System . Text . RegularExpressions ;
13+ using FWO . Logging ;
14+
15+ namespace FWO . Test
16+ {
17+ [ FixtureLifeCycle ( LifeCycle . InstancePerTestCase ) ]
18+ public class UiRsbLinkTest : Bunit . TestContext
19+ {
20+ static readonly UserConfig userConfig = new SimulatedUserConfig
21+ {
22+ ModNamingConvention = "{\" networkAreaRequired\" :true,\" fixedPartLength\" :4,\" freePartLength\" :5,\" networkAreaPattern\" :\" NA\" ,\" appRolePattern\" :\" AR\" }"
23+ } ;
24+ static readonly ApiConnection apiConnection = new UiRsbTestApiConn ( ) ;
25+ static readonly ReportBase currentReport = SimulatedReport . DetailedReport ( ) ;
26+
27+ [ Test ]
28+ public void ObjShouldBeVisibleAfterNavigation ( )
29+ {
30+ // Arrange
31+ Services . AddSingleton ( userConfig ) ;
32+ Services . AddSingleton ( apiConnection ) ;
33+ Services . AddLocalization ( ) ;
34+
35+ var objToFind = currentReport . ReportData . ManagementData [ 0 ] . Objects [ 1 ] ;
36+ var simObjHtml = ReportDevicesBase . ConstructLink ( ObjCatString . NwObj , "" , 0 , objToFind . Id , objToFind . Name , OutputLocation . report , currentReport . ReportData . ManagementData [ 0 ] . Id , "" ) ;
37+ var hrefValue = Regex . Match ( simObjHtml , "href=\" ([^\" ]*)\" " ) . Groups [ 1 ] . Value ;
38+ var link = $ "https://localhost/{ hrefValue } ";
39+
40+ var navigationManager = Services . GetRequiredService < FakeNavigationManager > ( ) ;
41+ navigationManager . NavigateTo ( link ) ;
42+
43+ // Mock JS interop
44+ JSInterop . Setup < string > ( "getCurrentUrl" ) . SetResult ( link ) ;
45+ var scrollIntoRSBViewInvocation = JSInterop . Setup < bool > ( "scrollIntoRSBView" , _ => true ) . SetResult ( true ) ;
46+ var removeUrlFragmentInvocation = JSInterop . SetupVoid ( "removeUrlFragment" ) ;
47+
48+ // Act
49+ var cut = RenderComponent < RightSidebar > ( parameters => parameters
50+ . Add ( p => p . CurrentReport , currentReport )
51+ . Add ( p => p . SelectedRules , [ currentReport . ReportData . ManagementData [ 0 ] . Devices [ 0 ] . Rules ! [ 0 ] ] ) ) ;
52+
53+ // Assert
54+ Assert . That ( scrollIntoRSBViewInvocation . Invocations , Is . Not . Empty , "scrollIntoRSBView should have been called" ) ;
55+ var invocation = scrollIntoRSBViewInvocation . Invocations . First ( ) ;
56+ var parameter = invocation . Arguments [ 0 ] ;
57+ Assert . That ( parameter , Is . Not . Null , "scrollIntoRSBView was called with a null parameter" ) ;
58+ Assert . That ( parameter , Is . InstanceOf < string > ( ) , "scrollIntoRSBView was called with a non-string parameter" ) ;
59+ Assert . That ( ( string ) parameter ! , Is . Not . Empty , "scrollIntoRSBView was called with an empty string" ) ;
60+
61+ var element = cut . Find ( $ "#{ parameter } ") ;
62+ Assert . That ( element , Is . Not . Null , "Element with id {parameter} not found in right sidebar" ) ;
63+ Assert . That ( IsElementVisible ( element ) , Is . True , "Element is not visible (might be incorrect tab or uncollapsed)" ) ;
64+ }
65+
66+ private bool IsElementVisible ( IElement ? element )
67+ {
68+ while ( element != null )
69+ {
70+ var display = element . GetStyle ( ) . GetPropertyValue ( "display" ) ;
71+ if ( display == "none" )
72+ {
73+ Log . WriteError ( "Test UI RSB" , $ "Element { element . TagName } is not visible") ;
74+ return false ;
75+ }
76+ element = element . ParentElement ;
77+ }
78+ return true ;
79+ }
80+ }
81+ }
0 commit comments