Skip to content

Commit ce16582

Browse files
committed
fix: Changed the structure of the tests and added an empty line between methods in Overview.js
1 parent 5c00f9a commit ce16582

6 files changed

Lines changed: 167 additions & 159 deletions

File tree

frontend/lib/public/Model.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
} from '/js/src/index.js';
2525

2626
import Overview from './views/Overview/Overview.js';
27+
2728
/**
2829
* Root of model tree
2930
* Handle global events: keyboard, websocket and router location change

frontend/lib/public/components/Filters/index.js

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1717
*/
1818
import { h } from '/js/src/index.js';
19+
1920
const FILTERS_LIMITS = 5;
2021

2122
/**
@@ -25,32 +26,32 @@ const FILTERS_LIMITS = 5;
2526
* @return {vnode}
2627
*/
2728
const checkboxFilter = (model, tags) => {
28-
const checkboxes = Object.entries(tags).map(([tag, count], index) =>
29-
h('.form-check', [
30-
h('input.form-check-input', {
31-
onclick: e => {
32-
const isChecked = e.target.checked;
33-
!isChecked
34-
? model.overview.removeFilter(tag)
35-
: model.overview.addFilter(tag);
36-
},
37-
id: `filtersCheckbox${index + 1}`,
38-
type: 'checkbox',
39-
}),
40-
h('label.flex-row.items-center.form-check-label', {
41-
for: `filtersCheckbox${index + 1}`,
42-
}, tag, h('.f7.mh1.gray-darker', `(${count})`)),
43-
]));
29+
const checkboxes = Object.entries(tags).map(([tag, count], index) =>
30+
h('.form-check', [
31+
h('input.form-check-input', {
32+
onclick: e => {
33+
const isChecked = e.target.checked;
34+
!isChecked
35+
? model.overview.removeFilter(tag)
36+
: model.overview.addFilter(tag);
37+
},
38+
id: `filtersCheckbox${index + 1}`,
39+
type: 'checkbox',
40+
}),
41+
h('label.flex-row.items-center.form-check-label', {
42+
for: `filtersCheckbox${index + 1}`,
43+
}, tag, h('.f7.mh1.gray-darker', `(${count})`)),
44+
]));
4445

45-
return checkboxes.length > FILTERS_LIMITS
46-
? h('.form-group', [
47-
...checkboxes.slice(0, FILTERS_LIMITS),
48-
h('button.btn.btn-primary.mv1', {
49-
onclick: () => console.log('TODO'),
50-
}, 'Meer opties'),
51-
...checkboxes.slice(FILTERS_LIMITS),
52-
])
53-
: h('.form-group', checkboxes);
46+
return checkboxes.length > FILTERS_LIMITS
47+
? h('.form-group', [
48+
...checkboxes.slice(0, FILTERS_LIMITS),
49+
h('button.btn.btn-primary.mv1', {
50+
onclick: () => console.log('TODO'),
51+
}, 'Meer opties'),
52+
...checkboxes.slice(FILTERS_LIMITS),
53+
])
54+
: h('.form-group', checkboxes);
5455
};
5556

5657
/**
@@ -60,10 +61,10 @@ const checkboxFilter = (model, tags) => {
6061
* @return {vnode}
6162
*/
6263
const filters = (model, tags) =>
63-
h('.w-25.shadow-level1.p2', [
64-
h('.f3', 'Filters'),
65-
h('.f4', 'Tags'),
66-
checkboxFilter(model, tags),
67-
]);
64+
h('.w-25.shadow-level1.p2', [
65+
h('.f3', 'Filters'),
66+
h('.f4', 'Tags'),
67+
checkboxFilter(model, tags),
68+
]);
6869

6970
export default filters;

frontend/lib/public/views/Overview/Overview.js

Lines changed: 118 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -21,133 +21,134 @@ import { Observable } from '/js/src/index.js';
2121
* Model representing handlers for homePage.js
2222
*/
2323
export default class Overview extends Observable {
24-
/**
25-
* @param {Object} model
26-
*/
27-
constructor(model) {
28-
super();
29-
this.model = model;
30-
this.date = new Date().toDateString();
31-
this.filterCriteria = [];
32-
this.data = [
33-
{
34-
authorID: 'Batman',
35-
title: 'Run1',
36-
creationTime: this.date,
37-
tags: ['Tag1', 'Tag2'],
38-
},
39-
{
40-
authorID: 'Joker',
41-
title: 'Run2',
42-
creationTime: this.date,
43-
tags: ['Tag2'],
44-
},
45-
{
46-
authorID: 'Anonymous',
47-
title: 'Run5',
48-
creationTime: this.date,
49-
tags: ['Tag3'],
50-
},
51-
];
52-
this.filtered = [...this.data];
53-
this.headers = ['ID', 'Author ID', 'Title', 'Creation Time'];
54-
}
55-
/**
56-
* @returns {Array} headers
57-
*/
58-
getHeaders() {
59-
return this.headers;
60-
}
24+
/**
25+
* @param {Object} model
26+
*/
27+
constructor(model) {
28+
super();
29+
this.model = model;
30+
this.date = new Date().toDateString();
31+
this.filterCriteria = [];
32+
this.data = [
33+
{
34+
authorID: 'Batman',
35+
title: 'Run1',
36+
creationTime: this.date,
37+
tags: ['Tag1', 'Tag2'],
38+
},
39+
{
40+
authorID: 'Joker',
41+
title: 'Run2',
42+
creationTime: this.date,
43+
tags: ['Tag2'],
44+
},
45+
{
46+
authorID: 'Anonymous',
47+
title: 'Run5',
48+
creationTime: this.date,
49+
tags: ['Tag3'],
50+
},
51+
];
52+
this.filtered = [...this.data];
53+
this.headers = ['ID', 'Author ID', 'Title', 'Creation Time'];
54+
}
55+
/**
56+
* @returns {Array} headers
57+
*/
58+
getHeaders() {
59+
return this.headers;
60+
}
6161

62-
/**
63-
* @returns {Array} subentries
64-
*/
65-
getTableData() {
66-
const subentries = this.filtered.map(entry => {
67-
const filter = Object.keys(entry).map(subkey => {
68-
if (subkey !== 'tags') {
69-
return entry[subkey];
70-
}
71-
});
62+
/**
63+
* @returns {Array} subentries
64+
*/
65+
getTableData() {
66+
const subentries = this.filtered.map(entry => {
67+
const filter = Object.keys(entry).map(subkey => {
68+
if (subkey !== 'tags') {
69+
return entry[subkey];
70+
}
71+
});
7272

73-
return filter;
74-
});
73+
return filter;
74+
});
7575

76-
return subentries;
77-
}
76+
return subentries;
77+
}
7878

79-
/**
80-
* Add filter to the selection
81-
* @param {string} tag
82-
*/
83-
addFilter(tag) {
84-
this.filterCriteria = [...this.filterCriteria, tag];
85-
this.getFilteredData();
86-
}
87-
88-
/**
89-
* Remove filter from the selection
90-
* @param {string} condition
91-
*/
92-
removeFilter(condition) {
93-
this.filterCriteria = this.filterCriteria.filter(tag => tag !== condition);
94-
this.getFilteredData();
95-
}
79+
/**
80+
* Add filter to the selection
81+
* @param {string} tag
82+
*/
83+
addFilter(tag) {
84+
this.filterCriteria = [...this.filterCriteria, tag];
85+
this.getFilteredData();
86+
}
9687

97-
/**
98-
* Filter the data
99-
*/
100-
getFilteredData() {
101-
this.filterCriteria.length !== 0
102-
? this.filterByTags()
103-
: (this.filtered = [...this.data]);
88+
/**
89+
* Remove filter from the selection
90+
* @param {string} condition
91+
*/
92+
removeFilter(condition) {
93+
this.filterCriteria = this.filterCriteria.filter(tag => tag !== condition);
94+
this.getFilteredData();
95+
}
10496

105-
this.notify();
106-
}
107-
/**
108-
* Filter data by tags if applicable
97+
/**
98+
* Filter the data
10999
*/
110-
filterByTags() {
111-
this.filtered = this.data
112-
.map(entry => {
113-
let match = this.checkExistingTag(entry);
100+
getFilteredData() {
101+
this.filterCriteria.length !== 0
102+
? this.filterByTags()
103+
: (this.filtered = [...this.data]);
114104

115-
if (match) {
116-
return entry;
117-
}
105+
this.notify();
106+
}
118107

119-
return null;
120-
})
121-
.filter(entry => entry !== null);
122-
}
108+
/**
109+
* Filter data by tags if applicable
110+
*/
111+
filterByTags() {
112+
this.filtered = this.data
113+
.map(entry => {
114+
let match = this.checkExistingTag(entry);
123115

124-
/**
125-
* Check for an existing tag
126-
* @param {object} entry
127-
* @return {bool}
128-
*/
129-
checkExistingTag(entry) {
130-
const check = this.filterCriteria.map(tag => {
131-
const match = entry.tags.includes(tag);
132-
if (match) {
133-
return 'Match';
134-
}
135-
return 'No Match';
136-
});
116+
if (match) {
117+
return entry;
118+
}
137119

138-
return check.includes('Match');
139-
}
120+
return null;
121+
})
122+
.filter(entry => entry !== null);
123+
}
140124

141-
/**
142-
* Counts the tags with their total appearances
143-
* @return {object}
144-
*/
145-
getTagCounts() {
146-
return this.data.reduce((accumulator, currentValue) => {
147-
currentValue.tags.forEach(tag => {
148-
accumulator[tag] = (accumulator[tag] || 0) + 1;
149-
});
150-
return accumulator;
151-
}, {});
152-
}
125+
/**
126+
* Check for an existing tag
127+
* @param {object} entry
128+
* @return {bool}
129+
*/
130+
checkExistingTag(entry) {
131+
const check = this.filterCriteria.map(tag => {
132+
const match = entry.tags.includes(tag);
133+
if (match) {
134+
return 'Match';
135+
}
136+
return 'No Match';
137+
});
138+
139+
return check.includes('Match');
140+
}
141+
142+
/**
143+
* Counts the tags with their total appearances
144+
* @return {object}
145+
*/
146+
getTagCounts() {
147+
return this.data.reduce((accumulator, currentValue) => {
148+
currentValue.tags.forEach(tag => {
149+
accumulator[tag] = (accumulator[tag] || 0) + 1;
150+
});
151+
return accumulator;
152+
}, {});
153+
}
153154
}

frontend/lib/server.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,11 @@ const http = new HttpServer({
2323
port: 3000,
2424
});
2525

26+
http.address = () => http.getServer.address();
27+
http.listen = () => { };
28+
http.close = () => http.getServer.close();
29+
2630
http.addStaticPath(path.resolve(__dirname, 'public'));
31+
32+
module.exports = http;
33+

frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
"nodemon": "2.0.2",
1919
"puppeteer": "2.1.1"
2020
}
21-
}
21+
}

0 commit comments

Comments
 (0)