-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathtestModule.ts
More file actions
68 lines (57 loc) · 1.93 KB
/
testModule.ts
File metadata and controls
68 lines (57 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import {Settings} from "../scripts/settings";
import {Clipper} from "../scripts/clipperUI/frontEndGlobals";
import {Localization} from "../scripts/localization/localization";
export abstract class TestModule {
protected abstract module(): string;
protected abstract tests(): void;
public runTests(): void {
let beforeEach = this.beforeEach.bind(this);
let resetFrontEndStorage = this.resetFrontEndStorage.bind(this);
let afterEach = this.afterEach.bind(this);
// We call the implemented beforeEach/afterEach after the common functionality
// as it's a higher priority, and we don't want to override it
QUnit.module(this.module(), {
beforeEach: () => {
resetFrontEndStorage();
beforeEach();
},
afterEach: () => {
// Unfortunately, we have some code that makes use of static, which
// means that we might end up polluting other test modules if we don't
// reset things. We declare these here so the developer doesn't have
// to remember to do this in their modules.
Settings.setSettingsJsonForTesting(undefined);
Localization.setLocalizedStrings(undefined);
afterEach();
}
});
this.tests();
}
// Overridable
protected beforeEach() { }
protected afterEach() { }
private resetFrontEndStorage() {
let mockStorageRef = {};
let mockStorageCacheRef = {};
Clipper.getStoredValue = (key: string, callback: (value: string) => void, cacheValue?: boolean) => {
if (cacheValue) {
mockStorageCacheRef[key] = mockStorageRef[key];
}
callback(mockStorageRef[key]);
};
Clipper.storeValue = (key: string, value: string) => {
if (key in mockStorageCacheRef) {
mockStorageCacheRef[key] = value;
}
mockStorageRef[key] = value;
};
Clipper.preCacheStoredValues = (storageKeys: string[]) => {
for (let key of storageKeys) {
Clipper.getStoredValue(key, () => { }, true);
}
};
Clipper.getCachedValue = (key: string) => {
return mockStorageCacheRef[key];
};
}
}