1
+
2
+ import { Framework } from "$lib/controller/framework" ;
3
+ import { BlacklistEntry } from "$lib/model/tables/blacklist/Blacklist" ;
4
+ import { jest } from "@jest/globals" ;
5
+ import { ServerMock } from "./__setup__/serverMock" ;
6
+ import { AliasSuggestionsEntry } from "$lib/model/tables/suggestions/AliasSuggestions" ;
7
+ import type { Alias } from "$lib/model/tables/official/OfficialAliases" ;
8
+ import { matchers } from "./__setup__/matcher" ;
9
+ import render from "./__setup__/pageRenderer" ;
10
+ import { clickOnButtonForRows , clickOnButtonForSomeRows , getAllInputs , getAllRows , setValueOfInput } from "./__setup__/helpers" ;
11
+ import { BUTTON , INPUT } from "./__setup__/constants" ;
12
+ import { fireEvent } from "@testing-library/svelte" ;
13
+
14
+ class OpenFramework extends Framework {
15
+ public constructor ( ) {
16
+ super ( ) ;
17
+ }
18
+ }
19
+
20
+ expect . extend ( matchers ) ;
21
+
22
+ describe ( "Testing interactions of settings as user" , ( ) => {
23
+
24
+ const entries = [
25
+ new AliasSuggestionsEntry ( "Infobau" , "50.34" , "-" , 503400000 , 10 , 0 , "tester" ) ,
26
+ new AliasSuggestionsEntry ( "Mathebau" , "20.30" , "-" , 203000000 , 8 , 1 , "tester2" ) ,
27
+ new AliasSuggestionsEntry ( "Seminarraum" , "50.34" , "-108" , 503499108 , 11 , 3 , "tester3" ) ,
28
+ new AliasSuggestionsEntry ( "HSaF" , "50.36" , "-" , 503600000 , 1 , 2 , "tester4" ) ,
29
+ new AliasSuggestionsEntry ( "Hörsaal am Fasanen" , "50.36" , "-" , 503600000 , 0 , 7 , "tester3" )
30
+ ] ;
31
+
32
+ const originalWarn = console . warn . bind ( console . warn )
33
+ let page : HTMLElement ;
34
+
35
+ let framework : OpenFramework ;
36
+ let serverMock : ServerMock ;
37
+ let fetchBackend : ( body : string ) => Promise < any > ;
38
+
39
+ beforeAll ( ( ) => {
40
+ serverMock = new ServerMock ( [ ] , [ ] , [ ] ) ;
41
+ fetchBackend = serverMock . getFetchBackendMock ( ) ;
42
+ framework = new OpenFramework ( ) ;
43
+ Framework [ 'instance' ] = framework ;
44
+ framework [ 'backend' ] [ 'fetchBackend' ] = fetchBackend ;
45
+
46
+ console . warn = ( msg ) => ! msg . toString ( ) . includes ( 'prop' ) && originalWarn ( msg ) ;
47
+ } ) ;
48
+
49
+ afterAll ( ( ) => {
50
+ console . warn = originalWarn
51
+ } ) ;
52
+
53
+ describe ( "setting value" , ( ) => {
54
+
55
+ beforeEach ( async ( ) => {
56
+ serverMock . setBlacklist ( [ ] ) ;
57
+ serverMock . setOfficial ( [ ] ) ;
58
+ serverMock . setSuggestions ( [ ...entries ] ) ;
59
+ page = await render . settings ( ) ;
60
+ await setValueOfInput ( page , INPUT . SETTINGS . MIN_POSITIVE_SUGGESTION , 0 ) ;
61
+ await setValueOfInput ( page , INPUT . SETTINGS . MIN_NEGATIVE_SUGGESTION , 0 ) ;
62
+ } ) ;
63
+
64
+ test . each ( [
65
+ [ 0 , [ 0 , 1 , 2 , 3 , 4 ] , [ ] ] ,
66
+ [ - 1 , [ 0 , 1 , 2 , 3 , 4 ] , [ ] ] ,
67
+ [ 1 , [ 0 , 1 , 2 , 3 ] , [ 4 ] ] ,
68
+ [ 10 , [ 0 , 2 ] , [ 1 , 3 , 4 ] ] ,
69
+ [ 42 , [ ] , [ 0 , 1 , 2 , 3 , 4 ] ]
70
+ ] ) ( `upvotes` , async ( value : number , shown : number [ ] , notShown : number [ ] ) => {
71
+ page = await render . suggestion ( ) ;
72
+ expect ( page ) . toHaveAllRows ( entries ) ;
73
+
74
+ page = await render . settings ( ) ;
75
+ await setValueOfInput ( page , INPUT . SETTINGS . MIN_POSITIVE_SUGGESTION , value ) ;
76
+
77
+ page = await render . suggestion ( ) ;
78
+ if ( shown . length > 0 ) {
79
+ expect ( page ) . toHaveSomeRows ( shown , entries ) ;
80
+ }
81
+ if ( notShown . length > 0 ) {
82
+ expect ( page ) . not . toHaveSomeRows ( notShown , entries ) ;
83
+ }
84
+ expect ( serverMock . getSuggestions ( ) ) . toEqual ( entries ) ;
85
+ } ) ;
86
+
87
+ test . each ( [
88
+ [ 0 , [ 0 , 1 , 2 , 3 , 4 ] , [ ] ] ,
89
+ [ - 1 , [ 0 , 1 , 2 , 3 , 4 ] , [ ] ] ,
90
+ [ 1 , [ 1 , 2 , 3 , 4 ] , [ 0 ] ] ,
91
+ [ 5 , [ 4 ] , [ 0 , 1 , 2 , 3 ] ] ,
92
+ [ 42 , [ ] , [ 0 , 1 , 2 , 3 , 4 ] ]
93
+ ] ) ( `downvotes` , async ( value : number , shown : number [ ] , notShown : number [ ] ) => {
94
+ page = await render . suggestion ( ) ;
95
+ expect ( page ) . toHaveAllRows ( entries ) ;
96
+
97
+ page = await render . settings ( ) ;
98
+ await setValueOfInput ( page , INPUT . SETTINGS . MIN_NEGATIVE_SUGGESTION , value ) ;
99
+
100
+ page = await render . suggestion ( ) ;
101
+ if ( shown . length > 0 ) {
102
+ expect ( page ) . toHaveSomeRows ( shown , entries ) ;
103
+ }
104
+ if ( notShown . length > 0 ) {
105
+ expect ( page ) . not . toHaveSomeRows ( notShown , entries ) ;
106
+ }
107
+ expect ( serverMock . getSuggestions ( ) ) . toEqual ( entries ) ;
108
+ } ) ;
109
+
110
+ test . each ( [
111
+ [ 1 , - 1 , [ 0 , 1 , 2 , 3 ] , [ 4 ] ] ,
112
+ [ 4 , 3 , [ 2 ] , [ 0 , 1 , 3 , 4 ] ] ,
113
+ [ 1 , 1 , [ 1 , 2 , 3 ] , [ 0 , 4 ] ] ,
114
+ [ - 5 , - 8 , [ 0 , 1 , 2 , 3 , 4 ] , [ ] ] ,
115
+ [ 42 , 69 , [ ] , [ 0 , 1 , 2 , 3 , 4 ] ]
116
+ ] ) ( `both` , async ( upvotes : number , downvotes : number , shown : number [ ] , notShown : number [ ] ) => {
117
+ page = await render . suggestion ( ) ;
118
+ expect ( page ) . toHaveAllRows ( entries ) ;
119
+
120
+ page = await render . settings ( ) ;
121
+ await setValueOfInput ( page , INPUT . SETTINGS . MIN_POSITIVE_SUGGESTION , upvotes ) ;
122
+ await setValueOfInput ( page , INPUT . SETTINGS . MIN_NEGATIVE_SUGGESTION , downvotes ) ;
123
+
124
+ page = await render . suggestion ( ) ;
125
+ if ( shown . length > 0 ) {
126
+ expect ( page ) . toHaveSomeRows ( shown , entries ) ;
127
+ }
128
+ if ( notShown . length > 0 ) {
129
+ expect ( page ) . not . toHaveSomeRows ( notShown , entries ) ;
130
+ }
131
+ expect ( serverMock . getSuggestions ( ) ) . toEqual ( entries ) ;
132
+ } ) ;
133
+ } ) ;
134
+ } ) ;
0 commit comments