@@ -9,7 +9,6 @@ import EventDispatcherInterface, {
9
9
import { AppEvents } from "@src/Types" ;
10
10
import FeatureService from "@src/Feature/FeatureService" ;
11
11
import { ResolverInterface } from "@src/Resolver/Interfaces" ;
12
- import { DelayerInterface } from "@src/Components/Delayer/Delayer" ;
13
12
import LoggerInterface from "@src/Components/Debug/LoggerInterface" ;
14
13
import { FunctionReplacerFactory } from "@config/inversify.factory.types" ;
15
14
import FunctionReplacer from "../../../../src/Utils/FunctionReplacer" ;
@@ -21,10 +20,11 @@ let callback: Callback<AppEvents[keyof AppEvents]>;
21
20
let dispatcher : MockProxy < EventDispatcherInterface < any > > ;
22
21
let refs : [ any ?, any ?] ;
23
22
let featureService : MockProxy < FeatureService > ;
24
- let delayer : MockProxy < DelayerInterface > ;
25
23
let sort : ExplorerSort ;
26
24
let view : MockProxy < TFileExplorerView > ;
27
- let replacerFactory : jest . Mock < ReturnType < FunctionReplacerFactory < TFileExplorerItem , "sort" , ExplorerSort > > > ;
25
+ let replacerFactory : jest . Mock <
26
+ ReturnType < FunctionReplacerFactory < TFileExplorerView , "getSortedFolderItems" , ExplorerSort > >
27
+ > ;
28
28
29
29
beforeEach ( ( ) => {
30
30
refs = [ ] ;
@@ -38,12 +38,11 @@ beforeEach(() => {
38
38
} ) ;
39
39
featureService = mock < FeatureService > ( ) ;
40
40
featureService . createResolver . mockReturnValue ( mock < ResolverInterface > ( ) ) ;
41
- delayer = mock < DelayerInterface > ( ) ;
42
41
view = mock < TFileExplorerView > ( ) ;
43
42
replacerFactory = jest . fn ( ) ;
44
43
// @ts -ignore
45
44
view . requestSort = jest . fn ( ) ;
46
- sort = new ExplorerSort ( mock < LoggerInterface > ( ) , facade , dispatcher , featureService , delayer , replacerFactory ) ;
45
+ sort = new ExplorerSort ( mock < LoggerInterface > ( ) , facade , dispatcher , featureService , replacerFactory ) ;
47
46
} ) ;
48
47
49
48
describe ( "ExplorerSort" , ( ) => {
@@ -58,43 +57,25 @@ describe("ExplorerSort", () => {
58
57
facade . getViewsOfType . mockReturnValue ( [ view ] ) ;
59
58
} ) ;
60
59
61
- test ( "should add listener after enabled" , ( ) => {
62
- sort . start ( ) ;
63
- expect ( sort . isStarted ( ) ) . toBeTruthy ( ) ;
64
- expect ( dispatcher . addListener ) . toHaveBeenCalledWith ( { name : "manager:update" , cb : expect . anything ( ) } ) ;
65
- expect ( dispatcher . addListener ) . toHaveBeenCalledWith ( { name : "manager:refresh" , cb : expect . anything ( ) } ) ;
66
- expect ( dispatcher . addListener ) . toHaveBeenCalledTimes ( 2 ) ;
67
- } ) ;
68
- //
69
- test ( "should delay replace because these is not item" , ( ) => {
70
- let fn : Function ;
71
- //copy delayed function to call it manually
72
- delayer . delay . mockImplementation ( f => {
73
- fn = f ;
74
- return 0 ;
75
- } ) ;
76
- //enable sort to trigger internal "tryToReplaceOriginalSort"
77
- sort . start ( ) ;
78
- expect ( delayer . delay ) . toHaveBeenCalledTimes ( 1 ) ;
79
- //Call delayed function
80
- fn ( ) ;
81
- expect ( delayer . delay ) . toHaveBeenCalledTimes ( 2 ) ;
82
- expect ( replacerFactory ) . not . toBeCalled ( ) ;
83
- } ) ;
84
-
85
60
describe ( "with explorer item" , ( ) => {
86
- let replacer : FunctionReplacer < TFileExplorerItem , "sort " , ExplorerSort > ;
61
+ let replacer : FunctionReplacer < TFileExplorerView , "getSortedFolderItems " , ExplorerSort > ;
87
62
let item : TFileExplorerItem ;
88
63
beforeEach ( ( ) => {
89
64
item = mock < TFileExplorerItem > ( ) ;
90
65
item . file = new TFolder ( ) ;
91
- replacer = mock < FunctionReplacer < TFileExplorerItem , "sort " , ExplorerSort > > ( ) ;
66
+ replacer = mock < FunctionReplacer < TFileExplorerView , "getSortedFolderItems " , ExplorerSort > > ( ) ;
92
67
replacerFactory . mockImplementationOnce ( ( ) => replacer ) ;
93
68
} ) ;
69
+
70
+ afterEach ( ( ) => {
71
+ expect ( dispatcher . addListener ) . toHaveBeenCalledWith ( { name : "manager:update" , cb : expect . anything ( ) } ) ;
72
+ expect ( dispatcher . addListener ) . toHaveBeenCalledWith ( { name : "manager:refresh" , cb : expect . anything ( ) } ) ;
73
+ expect ( dispatcher . addListener ) . toHaveBeenCalledTimes ( 2 ) ;
74
+ } ) ;
75
+
94
76
test ( "Should create function replacer without delay, because there is folder item" , ( ) => {
95
77
view . fileItems [ "mock" ] = item ;
96
78
sort . start ( ) ;
97
- expect ( delayer . delay ) . not . toHaveBeenCalled ( ) ;
98
79
expect ( replacerFactory ) . toBeCalled ( ) ;
99
80
expect ( replacer . enable ) . toBeCalled ( ) ;
100
81
} ) ;
0 commit comments