-
Notifications
You must be signed in to change notification settings - Fork 358
/
dialog_field_refresh_service_spec.js
71 lines (58 loc) · 1.73 KB
/
dialog_field_refresh_service_spec.js
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
describe('dialogFieldRefreshService', function() {
var testDialogFieldRefreshService, API;
beforeEach(module('ManageIQ'));
beforeEach(inject(function(dialogFieldRefreshService, _API_, DialogData) {
testDialogFieldRefreshService = dialogFieldRefreshService;
API = _API_;
var responseResult = {
result: {
'the field': 'the results'
}
};
spyOn(API, 'post').and.callFake(function() {
return {then: function(response) { response(responseResult); }};
});
DialogData.data = {
fields: {},
};
}));
describe('#refreshField', function() {
var data = 'the data';
var field = 'the field';
var url = 'url';
var idList = {
dialogId: '123',
resourceActionId: '321',
targetId: '456',
targetType: 'service_template',
};
var refreshPromise;
var resolvedValue;
beforeEach(function(done) {
refreshPromise = testDialogFieldRefreshService.refreshField(data, field, url, idList);
refreshPromise.then(function(value) {
resolvedValue = value;
done();
});
});
it('returns a promise', function() {
expect(refreshPromise instanceof Promise).toBe(true);
});
it('uses a post on the API', function() {
var requestData = {
action: 'refresh_dialog_fields',
resource: {
dialog_fields: 'the data',
fields: 'the field',
resource_action_id: '321',
target_id: '456',
target_type: 'service_template',
}
};
expect(API.post).toHaveBeenCalledWith('url123', JSON.stringify(requestData));
});
it('resolves the promise with the results', function() {
expect(resolvedValue).toEqual('the results');
});
});
});