Bri Prebilic Cole

GUI -- Started writing the ToolbarService with its unit tests -- WIP

Change-Id: I3adb60cdf9b516e3a325a85f1b0487710ef22178
...@@ -26,4 +26,5 @@ ...@@ -26,4 +26,5 @@
26 - Web Socket Service 26 - Web Socket Service
27 27
28 - Widget 28 - Widget
29 - - Table Service 29 + - Table Styling Directives
30 + - Toolbar Service
......
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +/*
18 + ONOS GUI -- Widget -- Toolbar Service
19 + */
20 +(function () {
21 + 'use strict';
22 +
23 + var $log;
24 +
25 + // rids will hold all the ids used with makeRadio so that you can create
26 + // more radio buttons not in order
27 + // TODO: implement this --^
28 + var rids = {},
29 + ridCtr = 0;
30 +
31 + // toggle state is used in createToolbar (not needed in makeToggle) (??)
32 + var toggle = false;
33 +
34 + function makeButton(id, gid, cb) {
35 + return {
36 + t: 'btn',
37 + id: id,
38 + gid: gid,
39 + cb: cb
40 + };
41 + }
42 +
43 + function makeToggle(id, gid, cb) {
44 + return {
45 + t: 'tog',
46 + id: id,
47 + gid: gid,
48 + cb: cb
49 + };
50 + }
51 +
52 + function makeRadio(id, cb) {
53 + return {
54 + t: 'rad',
55 + id: id + '-' + ridCtr,
56 + cb: cb
57 + };
58 + }
59 +
60 + function separator() {
61 + return {
62 + t: 'sep'
63 + };
64 + }
65 +
66 + function createToolbar() {
67 +
68 + }
69 +
70 + angular.module('onosWidget')
71 + .factory('ToolbarService', ['$log', function (_$log_) {
72 + $log = _$log_;
73 +
74 + return {
75 + makeButton: makeButton,
76 + makeToggle: makeToggle,
77 + makeRadio: makeRadio,
78 + separator: separator,
79 + createToolbar: createToolbar
80 + };
81 + }]);
82 +
83 +}());
...\ No newline at end of file ...\ No newline at end of file
...@@ -58,6 +58,7 @@ ...@@ -58,6 +58,7 @@
58 58
59 <script src="fw/widget/widget.js"></script> 59 <script src="fw/widget/widget.js"></script>
60 <script src="fw/widget/table.js"></script> 60 <script src="fw/widget/table.js"></script>
61 + <script src="fw/widget/toolbar.js"></script>
61 62
62 <script src="fw/layer/layer.js"></script> 63 <script src="fw/layer/layer.js"></script>
63 <script src="fw/layer/panel.js"></script> 64 <script src="fw/layer/panel.js"></script>
......
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +/*
18 + ONOS GUI -- Widget -- Toolbar Service - Unit Tests
19 + */
20 +describe('factory: fw/widget/toolbar.js', function () {
21 + var $log, fs, tbs;
22 +
23 + beforeEach(module('onosWidget', 'onosUtil'));
24 +
25 + beforeEach(inject(function (_$log_, FnService, ToolbarService) {
26 + $log = _$log_;
27 + fs = FnService;
28 + tbs = ToolbarService;
29 + }));
30 +
31 + it('should define ToolbarService', function () {
32 + expect(tbs).toBeDefined();
33 + });
34 +
35 + it('should define api functions', function () {
36 + expect(fs.areFunctions(tbs, [
37 + 'makeButton', 'makeToggle', 'makeRadio', 'separator', 'createToolbar'
38 + ])).toBeTruthy();
39 + });
40 +
41 + it("should verify makeButton's returned object", function () {
42 + var button = tbs.makeButton('foo', 'glyph-bar', function () {});
43 +
44 + expect(button.t).toBe('btn');
45 + expect(button.id).toBe('foo');
46 + expect(button.gid).toBe('glyph-bar');
47 + expect(fs.isF(button.cb)).toBeTruthy();
48 + });
49 +
50 + it("should verify makeToggle's returned object", function () {
51 + var toggle = tbs.makeToggle('foo', 'glyph-bar', function () {});
52 +
53 + expect(toggle.t).toBe('tog');
54 + expect(toggle.id).toBe('foo');
55 + expect(toggle.gid).toBe('glyph-bar');
56 + expect(fs.isF(toggle.cb)).toBeTruthy();
57 + });
58 +
59 + it("should verify makeRadio's returned object", function () {
60 + // TODO: finish this
61 +
62 + //var rFoo1 = tbs.makeRadio('foo', function () {});
63 + //var rFoo2 = tbs.makeRadio('foo', function () {});
64 + //var rFoo3 = tbs.makeRadio('foo', function () {});
65 + //var rBar1 = tbs.makeRadio('bar', function () {});
66 + //
67 + //expect(radio1.t).toBe('rad');
68 + //expect(radio1.id).toBe('foo');
69 + //expect(fs.isF(radio1.cb)).toBeTruthy();
70 + });
71 +
72 + it("should verify separator's returned object", function () {
73 + var separator = tbs.separator();
74 + expect(separator.t).toBe('sep');
75 + });
76 +
77 +});