- commit
- fc4ac1a7137b4dcdce486a76250b80955bfb5279
- parent
- 3ea2fe78e486363d2f7086fda6191d2aaec7cf1c
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2020-10-17 06:09
rm name
Diffstat
| M | static/src/template.js | 9 | ++------- |
| M | static/src/voterunner.js | 12 | +++--------- |
| M | static/test/test.js | 80 | ++++++++++++------------------------------------------------ |
3 files changed, 21 insertions, 80 deletions
diff --git a/static/src/template.js b/static/src/template.js
@@ -25,10 +25,6 @@ var getDelegationChain = function(nodes, node) {
25 25 return node.delegationChain;
26 26 };
27 27
28 -1 var getName = function(node) {
29 -1 return node.name || 'anonymous';
30 -1 };
31 -1
32 28 var tplFollowers = function(state, id) {
33 29 return state.nodes
34 30 .filter(n => n.delegate === id)
@@ -64,14 +60,14 @@ var tplNode = function(state, node) {
64 60 }, node.expanded ? '\u25BC' : '\u25B6'),
65 61 h('button', {
66 62 className: 'node__delegate bar__item bar__item--button bar__item--right',
67 -1 title: 'delegate to ' + getName(node),
-1 63 title: 'delegate to ' + node.id,
68 64 disabled: (
69 65 node.id === state.id ||
70 66 getDelegationChain(state.nodes, node).includes(state.id)
71 67 ),
72 68 }, '\u2795'),
73 69 h('div', {className: 'node__votes bar__item bar__item--right'}, '' + getVotes(state.nodes, node)),
74 -1 h('div', {className: 'node__name bar__item' + (!node.expanded && node.comment ? '' : ' bar__item--grow')}, getName(node)),
-1 70 h('div', {className: 'node__name bar__item' + (!node.expanded && node.comment ? '' : ' bar__item--grow')}, node.id),
75 71 !node.expanded && node.comment && h('div', {className: 'node__preview bar__item bar__item--grow'}, node.comment.substr(0, 100)),
76 72 ]),
77 73 node.expanded && h('div', {className: 'node__comment'}, node.comment || ''),
@@ -92,6 +88,5 @@ var template = function(state) {
92 88
93 89 module.exports = {
94 90 getVotes: getVotes,
95 -1 getName: getName,
96 91 template: template,
97 92 };
diff --git a/static/src/voterunner.js b/static/src/voterunner.js
@@ -47,7 +47,6 @@ document.addEventListener('DOMContentLoaded', function() {
47 47
48 48 var user = state.nodes.find(n => n.id === state.id);
49 49 if (user) {
50 -1 document.querySelector('.user__name input').value = user.name;
51 50 document.querySelector('.user__comment textarea').value = user.comment;
52 51 ensureVisible(user);
53 52 }
@@ -56,8 +55,7 @@ document.addEventListener('DOMContentLoaded', function() {
56 55 document.querySelector('.user__votes').textContent = template.getVotes(state.nodes, user || {});
57 56
58 57 if (user && user.delegate) {
59 -1 var delegatee = getNode(user.delegate);
60 -1 document.querySelector('.user__delegation').textContent = 'delegated to: ' + template.getName(delegatee);
-1 58 document.querySelector('.user__delegation').textContent = 'delegated to: ' + user.delegate;
61 59 } else {
62 60 document.querySelector('.user__delegation').textContent = '(no delegation)';
63 61 }
@@ -84,13 +82,13 @@ document.addEventListener('DOMContentLoaded', function() {
84 82 utils.on(document, 'click', '.user__rm', function() {
85 83 if (confirm('Do you really want to delete this opinion?')) {
86 84 socket.emit('rmNode');
87 -1 document.querySelector('.user__name input').value = '';
88 85 document.querySelector('.user__comment textarea').value = '';
89 86 }
90 87 });
91 88
92 89 utils.on(document, 'change', '.user__name input', function() {
93 -1 socket.emit('setNodeName', this.value);
-1 90 state.id = this.value;
-1 91 update(state);
94 92 });
95 93
96 94 utils.on(document, 'click', '.user__undelegate', function() {
@@ -117,10 +115,6 @@ document.addEventListener('DOMContentLoaded', function() {
117 115 invalidateVotes();
118 116 update(state);
119 117 });
120 -1 socket.on('setNodeName', function(id, name) {
121 -1 getNode(id).name = name;
122 -1 update(state);
123 -1 });
124 118 socket.on('setNodeComment', function(id, comment) {
125 119 getNode(id).comment = comment;
126 120 update(state);
diff --git a/static/test/test.js b/static/test/test.js
@@ -7,11 +7,21 @@ var trigger = function(target, type) {
7 7 target.dispatchEvent(new Event(type, {bubbles: true}));
8 8 };
9 9
-1 10 var setUpUser = function(browser, id) {
-1 11 var d = browser.contentDocument;
-1 12 var userName = d.querySelector('.user__name input');
-1 13 userName.value = id;
-1 14 trigger(userName, 'input');
-1 15 };
-1 16
10 17 var setUp = function(url, fn) {
11 18 var iframe = document.createElement('iframe');
12 -1 iframe.onload = function() {fn(iframe)};
13 19 iframe.url = url;
14 20 iframe.src = url;
-1 21 iframe.onload = function() {
-1 22 setUpUser(this, ID);
-1 23 fn(iframe);
-1 24 };
15 25
16 26 iframe.tearDown = function(done) {
17 27 var self = this;
@@ -23,7 +33,10 @@ var setUp = function(url, fn) {
23 33
24 34 iframe.reload = function(fn) {
25 35 this.onload = function() {
26 -1 this.onload = fn;
-1 36 this.onload = function() {
-1 37 setUpUser(this, ID);
-1 38 setTimeout(fn, TIMEOUT);
-1 39 };
27 40 this.src = this.url;
28 41 };
29 42 this.src = '';
@@ -56,59 +69,6 @@ describe('load', function() {
56 69 });
57 70 });
58 71
59 -1 describe('setName', function() {
60 -1 var test = 'setName';
61 -1 var name = 'testName';
62 -1 var browser;
63 -1 var d, userName, node, nodeName;
64 -1
65 -1 before(function(done) {
66 -1 setUp('/test' + test + '/' + ID, function(b) {
67 -1 browser = b;
68 -1 d = browser.contentDocument;
69 -1
70 -1 userName = d.querySelector('.user__name input');
71 -1 userName.value = name;
72 -1 trigger(userName, 'change');
73 -1
74 -1 setTimeout(done, TIMEOUT);
75 -1 });
76 -1 });
77 -1
78 -1 after(function(done) {
79 -1 browser.tearDown(done);
80 -1 });
81 -1
82 -1 it('should set user name', function() {
83 -1 expect(userName.value).to.equal(name);
84 -1 });
85 -1
86 -1 it('node sould exist', function() {
87 -1 node = d.getElementById('node-' + ID);
88 -1 expect(node).to.exist;
89 -1 });
90 -1
91 -1 it('should set node name', function() {
92 -1 node = d.getElementById('node-' + ID);
93 -1 nodeName = node.querySelector('.node__name').textContent;
94 -1 expect(nodeName).to.equal(name);
95 -1 });
96 -1
97 -1 it('should be permanent', function(done) {
98 -1 browser.reload(function() {
99 -1 d = browser.contentDocument;
100 -1 userName = d.querySelector('.user__name input').value;
101 -1 expect(userName).to.equal(name);
102 -1
103 -1 node = d.getElementById('node-' + ID);
104 -1 nodeName = node.querySelector('.node__name').textContent;
105 -1 expect(nodeName).to.equal(name);
106 -1
107 -1 done();
108 -1 });
109 -1 });
110 -1 });
111 -1
112 72 describe('setComment', function() {
113 73 var test = 'setComment';
114 74 var comment = 'testComment';
@@ -177,7 +137,7 @@ describe('removeDelegate', function() {
177 137 describe('remove', function() {
178 138 var test = 'remove';
179 139 var browser;
180 -1 var d, userName, userComment, userRemove;
-1 140 var d, userComment, userRemove;
181 141
182 142 before(function(done) {
183 143 setUp('/test' + test + '/' + ID, function(b) {
@@ -186,9 +146,6 @@ describe('remove', function() {
186 146 browser.contentWindow.confirm = () => true;
187 147
188 148 // create something to delete
189 -1 userName = d.querySelector('.user__name input');
190 -1 userName.value = 'testName';
191 -1 trigger(userName, 'change');
192 149 userComment = d.querySelector('.user__comment textarea');
193 150 userComment.value = 'testComment';
194 151 trigger(userComment, 'input');
@@ -209,11 +166,6 @@ describe('remove', function() {
209 166 expect(node).to.not.exist;
210 167 });
211 168
212 -1 it('should clear user name', function() {
213 -1 userName = d.querySelector('.user__name input').value;
214 -1 expect(userName).to.equal('');
215 -1 });
216 -1
217 169 it('should clear user comment', function() {
218 170 userComment = d.querySelector('.user__comment textarea').value;
219 171 expect(userComment).to.equal('');