1+ describe ( 'Names.js tests' , function ( ) {
2+
3+ it ( 'should have a idrinth variable in scope' , function ( ) {
4+ expect ( idrinth ) . toBeDefined ( ) ;
5+ } ) ;
6+
7+
8+ it ( 'should check default data is valid, and empty' , function ( ) {
9+ expect ( idrinth . names . users ) . toEqual ( { } ) ;
10+ expect ( idrinth . names . classes ) . toEqual ( { } ) ;
11+ expect ( idrinth . names . guilds ) . toEqual ( { } ) ;
12+ expect ( idrinth . names . counter ) . toEqual ( 0 ) ;
13+ } ) ;
14+
15+ describe ( "Names parse method" , function ( ) {
16+ //<span class="username chat_message_window_username ign dotdm_1484406507967"
17+ // username="arkamat" dotdxname="arkamat" oncontextmenu="return false;">K2 mat</span>
18+
19+ it ( "Should get attribute with name dotdxname" , function ( ) {
20+ var span = document . createElement ( "span" ) ;
21+ span . className = 'username chat_message_window_username ign' ;
22+ span . setAttribute ( "dotdxname" , "testcharacterDTX" ) ;
23+ span . innerHTML = "K2 TestCharacter" ;
24+
25+ expect ( idrinth . names . parse ( span ) ) . toEqual ( "testcharacterDTX" ) ;
26+ } ) ;
27+
28+ it ( "Should get attribute with name username" , function ( ) {
29+
30+ var span = document . createElement ( "span" ) ;
31+ span . className = 'username' ;
32+ span . setAttribute ( "username" , "testcharacterUSN" ) ;
33+ span . innerHTML = "K2 TestCharacter" ;
34+
35+ expect ( idrinth . names . parse ( span ) ) . toEqual ( "testcharacterUSN" ) ;
36+ } ) ;
37+
38+ it ( "Should get default attribute" , function ( ) {
39+ var span = document . createElement ( "span" ) ;
40+ span . innerHTML = "K2 TestCharacter" ;
41+
42+ expect ( idrinth . names . parse ( span ) ) . toEqual ( "K2 TestCharacter" ) ;
43+ } ) ;
44+
45+ } ) ;
46+
47+ describe ( "Names run method" , function ( ) {
48+
49+ beforeAll ( function ( ) {
50+
51+ var SPANUsername = { } ;
52+ document . getElementsByClassName = jasmine . createSpy ( 'HTML Class Elements' ) . andCallFake ( function ( className ) {
53+ if ( ! SPANUsername [ className ] ) {
54+ SPANUsername [ className ] = document . createElement ( 'span' ) ;
55+ }
56+ return SPANUsername [ className ] ;
57+ } ) ;
58+ } ) ;
59+
60+ it ( "Should run for new names and add them" , function ( ) {
61+
62+ var testUser = {
63+ kongregate : { name : 'test' } ,
64+ world : { name : 'test' }
65+ } ;
66+
67+ idrinth . names . counter = 300 ;
68+ idrinth . names . names [ 'testUser' ] = testUser ;
69+
70+ idrinth . names . run ( ) ;
71+
72+ expect ( idrinth . names . users ) . toEqual ( 2 ) ;
73+ expect ( idrinth . names . counter ) . toEqual ( 121312 ) ;
74+ } ) ;
75+
76+ it ( "Should get attribute with name dotdxname" , function ( ) {
77+
78+ idrinth . names . run ( ) ;
79+
80+ expect ( idrinth . names . users ) . toEqual ( 2 ) ;
81+ expect ( idrinth . names . counter ) . toEqual ( 300 ) ;
82+ } ) ;
83+
84+ } ) ;
85+
86+ describe ( "Names start method for kongregate" , function ( ) {
87+
88+ it ( "Should start names for kongregate" , function ( ) {
89+ // idrinth.ui.tooltip
90+ // idrinth.ui.base
91+ // idrinth.ui.updateClassesList
92+ // idrinth.settings.get
93+ // idrinth.ui.setTooltipTimeout
94+ // idrinth.ui.getElementPositioning
95+
96+ spyOn ( idrinth . core . multibind , 'add' ) ;
97+ spyOn ( idrinth . core . timeouts , 'add' ) ;
98+
99+ idrinth . names . run ( ) ;
100+
101+ expect ( idrinth . core . multibind . add ) . toHaveBeenCalled ( ) ;
102+ expect ( idrinth . core . multibind . add ) . toHaveBeenCalledTimes ( 1 ) ;
103+
104+ expect ( idrinth . core . timeouts . add ) . toHaveBeenCalled ( ) ;
105+ expect ( idrinth . core . timeouts . add ) . toHaveBeenCalledTimes ( 1 ) ;
106+ } ) ;
107+
108+ } ) ;
109+ } ) ;
0 commit comments