@@ -230,6 +230,12 @@ function attachDivWithID(id) {
230
230
document . body . appendChild ( div ) ;
231
231
}
232
232
233
+ function detachDivWithID ( id ) {
234
+ const el = document . getElementById ( id ) ;
235
+ if ( ! el ) return ;
236
+ document . body . removeChild ( el ) ;
237
+ }
238
+
233
239
describe ( 'NavigatorCard' , ( ) => {
234
240
beforeEach ( ( ) => {
235
241
document . body . innerHTML = '' ;
@@ -1108,11 +1114,11 @@ describe('NavigatorCard', () => {
1108
1114
// item is not scrolled to
1109
1115
expect ( DynamicScrollerStub . methods . scrollToItem ) . toHaveBeenCalledTimes ( 0 ) ;
1110
1116
const filter = wrapper . find ( FilterInput ) ;
1117
+ // the filter is on the grandchild of the current activeUID
1111
1118
filter . vm . $emit ( 'input' , root0Child1GrandChild0 . title ) ;
1112
1119
await flushPromises ( ) ;
1113
- // assert list is scrolled to the top
1114
- expect ( DynamicScrollerStub . methods . scrollToItem ) . toHaveBeenCalledTimes ( 1 ) ;
1115
- expect ( DynamicScrollerStub . methods . scrollToItem ) . toHaveBeenCalledWith ( 0 ) ;
1120
+ // assert list is not scrolled, if item is in viewport or current activeUID is rendered
1121
+ expect ( DynamicScrollerStub . methods . scrollToItem ) . toHaveBeenCalledTimes ( 0 ) ;
1116
1122
// assert only the parens of the match are visible
1117
1123
const all = wrapper . findAll ( NavigatorCardItem ) ;
1118
1124
expect ( all ) . toHaveLength ( 3 ) ;
@@ -1145,8 +1151,7 @@ describe('NavigatorCard', () => {
1145
1151
// make sure we match at both the top item as well as one of its children
1146
1152
filter . vm . $emit ( 'input' , 'Second' ) ;
1147
1153
await flushPromises ( ) ;
1148
- expect ( DynamicScrollerStub . methods . scrollToItem ) . toHaveBeenCalledTimes ( 1 ) ;
1149
- expect ( DynamicScrollerStub . methods . scrollToItem ) . toHaveBeenCalledWith ( 0 ) ;
1154
+ expect ( DynamicScrollerStub . methods . scrollToItem ) . toHaveBeenCalledTimes ( 0 ) ;
1150
1155
// assert only the parens of the match are visible
1151
1156
const all = wrapper . findAll ( NavigatorCardItem ) ;
1152
1157
expect ( all ) . toHaveLength ( 2 ) ;
@@ -1161,8 +1166,7 @@ describe('NavigatorCard', () => {
1161
1166
await flushPromises ( ) ;
1162
1167
filter . vm . $emit ( 'input' , root0 . title ) ;
1163
1168
await flushPromises ( ) ;
1164
- expect ( DynamicScrollerStub . methods . scrollToItem ) . toHaveBeenCalledTimes ( 1 ) ;
1165
- expect ( DynamicScrollerStub . methods . scrollToItem ) . toHaveBeenCalledWith ( 0 ) ;
1169
+ expect ( DynamicScrollerStub . methods . scrollToItem ) . toHaveBeenCalledTimes ( 0 ) ;
1166
1170
// assert only the parens of the match are visible
1167
1171
let all = wrapper . findAll ( NavigatorCardItem ) ;
1168
1172
expect ( all ) . toHaveLength ( 1 ) ;
@@ -1201,6 +1205,8 @@ describe('NavigatorCard', () => {
1201
1205
await flushPromises ( ) ;
1202
1206
const filter = wrapper . find ( FilterInput ) ;
1203
1207
filter . vm . $emit ( 'update:selectedTags' , [ FILTER_TAGS_TO_LABELS . articles ] ) ;
1208
+ // this item is not an article
1209
+ detachDivWithID ( root0Child0 . uid ) ;
1204
1210
await flushPromises ( ) ;
1205
1211
expect ( DynamicScrollerStub . methods . scrollToItem ) . toHaveBeenCalledTimes ( 1 ) ;
1206
1212
expect ( DynamicScrollerStub . methods . scrollToItem ) . toHaveBeenLastCalledWith ( 0 ) ;
@@ -1219,6 +1225,7 @@ describe('NavigatorCard', () => {
1219
1225
const filter = wrapper . find ( FilterInput ) ;
1220
1226
await flushPromises ( ) ;
1221
1227
filter . vm . $emit ( 'update:selectedTags' , [ FILTER_TAGS_TO_LABELS . tutorials ] ) ;
1228
+ detachDivWithID ( root0Child0 . uid ) ;
1222
1229
await flushPromises ( ) ;
1223
1230
expect ( DynamicScrollerStub . methods . scrollToItem ) . toHaveBeenCalledTimes ( 1 ) ;
1224
1231
expect ( DynamicScrollerStub . methods . scrollToItem ) . toHaveBeenCalledWith ( 0 ) ;
@@ -1234,6 +1241,7 @@ describe('NavigatorCard', () => {
1234
1241
const filter = wrapper . find ( FilterInput ) ;
1235
1242
await flushPromises ( ) ;
1236
1243
filter . vm . $emit ( 'update:selectedTags' , [ FILTER_TAGS_TO_LABELS . articles ] ) ;
1244
+ detachDivWithID ( root0Child0 . uid ) ;
1237
1245
await flushPromises ( ) ;
1238
1246
expect ( DynamicScrollerStub . methods . scrollToItem ) . toHaveBeenCalledTimes ( 1 ) ;
1239
1247
expect ( DynamicScrollerStub . methods . scrollToItem ) . toHaveBeenCalledWith ( 0 ) ;
@@ -1251,6 +1259,8 @@ describe('NavigatorCard', () => {
1251
1259
expect ( all . at ( 0 ) . props ( 'item' ) ) . toEqual ( root0 ) ;
1252
1260
expect ( all . at ( 1 ) . props ( 'item' ) ) . toEqual ( root0Child1 ) ;
1253
1261
expect ( all . at ( 2 ) . props ( 'item' ) ) . toEqual ( root0Child1GrandChild0 ) ;
1262
+ expect ( DynamicScrollerStub . methods . scrollToItem ) . toHaveBeenCalledTimes ( 2 ) ;
1263
+ expect ( DynamicScrollerStub . methods . scrollToItem ) . toHaveBeenLastCalledWith ( 0 ) ;
1254
1264
} ) ;
1255
1265
1256
1266
it ( 'allows opening an item, that has a filter match' , async ( ) => {
@@ -2201,7 +2211,7 @@ describe('NavigatorCard', () => {
2201
2211
} ) ;
2202
2212
2203
2213
describe ( 'scroll to item' , ( ) => {
2204
- it ( 'resets the scroll position, if initiating a filter ' , async ( ) => {
2214
+ it ( 'resets the scroll position, if filtering, current page is NOT in the results ' , async ( ) => {
2205
2215
attachDivWithID ( root0Child0 . uid ) ;
2206
2216
// simulate item is above the scrollarea
2207
2217
getChildPositionInScroller . mockReturnValueOnce ( 1 ) ;
@@ -2210,10 +2220,14 @@ describe('NavigatorCard', () => {
2210
2220
expect ( DynamicScrollerStub . methods . scrollToItem ) . toHaveBeenCalledTimes ( 1 ) ;
2211
2221
expect ( DynamicScrollerStub . methods . scrollToItem ) . toHaveBeenLastCalledWith ( 1 ) ;
2212
2222
// initiate a filter
2213
- wrapper . find ( FilterInput ) . vm . $emit ( 'input' , root0Child1 . title ) ;
2223
+ wrapper . find ( FilterInput ) . vm . $emit ( 'input' , root1 . title ) ;
2224
+ // we have to manually remove it from the DOM, as we are mocking lots of stuff
2225
+ detachDivWithID ( root0Child0 . uid ) ;
2214
2226
await wrapper . vm . $nextTick ( ) ;
2215
2227
// assert filter is applied
2216
- expect ( wrapper . findAll ( NavigatorCardItem ) ) . toHaveLength ( 2 ) ;
2228
+ const items = wrapper . findAll ( NavigatorCardItem ) ;
2229
+ expect ( items ) . toHaveLength ( 1 ) ;
2230
+ expect ( items . at ( 0 ) . props ( 'item' ) ) . toEqual ( root1 ) ;
2217
2231
// assert scroller has been reset
2218
2232
expect ( DynamicScrollerStub . methods . scrollToItem ) . toHaveBeenCalledTimes ( 2 ) ;
2219
2233
expect ( DynamicScrollerStub . methods . scrollToItem ) . toHaveBeenLastCalledWith ( 0 ) ;
0 commit comments