forked from onivim/oni2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfigurationTest.re
75 lines (68 loc) · 1.88 KB
/
ConfigurationTest.re
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
69
70
71
72
73
74
75
open Oni_Core;
open TestFramework;
open Exthost;
let model1 =
Configuration.Model.create(
~keys=["foo.bar"],
`Assoc([("foo", `Assoc([("bar", `String("value1"))]))]),
);
let configuration1 = Configuration.create(~user=model1, ());
module TestConfigurationEvent = {
type t = {
eventType: string,
result: string,
};
let decode = {
Json.Decode.(
obj(({field, _}) => {
{
eventType: field.required("eventType", string),
result: field.required("result", string),
}
})
);
};
};
let waitForConfigurationEvent = (~name, f, context) => {
context
|> Test.waitForMessage(
~name,
fun
| Msg.MessageService(ShowMessage({message, _})) => {
message
|> Yojson.Safe.from_string
|> Json.Decode.decode_value(TestConfigurationEvent.decode)
|> Result.map(f)
|> Result.value(~default=false);
}
| _ => false,
);
};
describe("ConfigurationTest", ({test, _}) => {
test("sets configuration value", _ => {
Test.startWithExtensions(["oni-configuration"])
|> Test.waitForExtensionActivation("oni-configuration")
|> Test.withClient(
Exthost.Request.Configuration.acceptConfigurationChanged(
~configuration=configuration1,
~changed=model1,
),
)
|> waitForConfigurationEvent(
~name="Configuration change event", ({eventType, _}) => {
String.equal(eventType, "config.changed")
})
|> Test.withClient(
Exthost.Request.Commands.executeContributedCommand(
~arguments=[`String("foo.bar")],
~command="config.show",
),
)
|> waitForConfigurationEvent(
~name="Value should be 'value1'", ({result, _}) => {
String.equal(result, "value1")
})
|> Test.terminate
|> Test.waitForProcessClosed
})
});