Skip to content

Commit 1a00ec5

Browse files
authored
Merge pull request #66 from oslabs-beta/drew/codebase-cleaning
Drew/codebase cleaning
2 parents b5dceb6 + e2fb17f commit 1a00ec5

18 files changed

+184
-267
lines changed

__tests__/ContainersTab.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {describe, beforeEach, expect, test, jest} from '@jest/globals';
44
import '@testing-library/jest-dom';
55
import ToggleDisplay from '../src/components/display/ToggleDisplay';
66
import { fireEvent, render, screen } from '@testing-library/react';
7-
// import { Chart } from 'react-chartjs-2';
87

98
const props = {
109
runningList: [

__tests__/MetricsTab.test.js

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -25,79 +25,7 @@ const props = {
2525
// });
2626
// });
2727

28-
/*
2928

30-
// function shallowSetup() {
31-
32-
33-
// const props = {
34-
// runningList: [{ BlockIO: "1B/2B", ID: "6f49565a501c", CPUPerc: "20.00%", MemPerc: "0.00%", MemUsage: "5B/6B", Name: "checkpoint_nginx_1", NetIO: "3B/4B", PIDs: "0" }, { BlockIO: "3B/4B", ID: "6f49565a501c", CPUPerc: "30.00%", MemPerc: "20.00%", MemUsage: "5B/6B", Name: "checkpoint_nginx_2", NetIO: "5B/6B", PIDs: "0" }]
35-
// }
36-
// const enzymeWrapper = shallow(<Metrics {...props} />);
37-
38-
39-
// return {
40-
// props,
41-
// enzymeWrapper
42-
// };
43-
// }
44-
45-
// describe('Shallow rendered Metrics for chart', () => {
46-
// // Setup wrapper and assign props.
47-
48-
// const { enzymeWrapper, props } = shallowSetup();
49-
50-
// it('Should render <div> tag in Metrics', () => {
51-
// expect(enzymeWrapper.type()).toEqual('div');
52-
// })
53-
54-
// it('Should render Pie chart data properly', () => {
55-
56-
// // enzymeWrapper.find(selector) : Find every node in the render tree that matches the provided selector.
57-
// expect(enzymeWrapper.find('p.legend-text')).toHaveLength(4);
58-
// enzymeWrapper.find('p.legend-text').forEach((element) => {
59-
60-
// let value = element.text().split(' ')
61-
// let percentage = parseInt(value[1].substr(0, value[1].length-4));
62-
// expect(percentage).toBeGreaterThanOrEqual(0);
63-
// });
64-
65-
// });
66-
67-
// it('should have valid number of Net I/O and Block I/O of <p>', () => {
68-
// expect(enzymeWrapper.find('p.chart-number')).toHaveLength(2);
69-
// })
70-
71-
// it('should render Net I/O data properly', () => {
72-
73-
// enzymeWrapper.find('p.chart-number').forEach((element, i) => {
74-
// if(i === 0){
75-
// let value = element.text().split('/')
76-
// let IOFront = parseInt(value[0].substr(0, value[0].length-2));
77-
// let IOBack = parseInt(value[1].substr(0, value[1].length-2));
78-
79-
// expect(IOFront).toBeGreaterThanOrEqual(0);
80-
// expect(IOBack).toBeGreaterThanOrEqual(0);
81-
// }
82-
// });
83-
// });
84-
85-
// it('should render Block I/O data properly', () => {
86-
87-
// enzymeWrapper.find('p.chart-number').forEach((element, i) => {
88-
// if(i === 1){
89-
// let value = element.text().split('/')
90-
// let IOFront = parseInt(value[0].substr(0, value[0].length-1));
91-
// let IOBack = parseInt(value[1].substr(0, value[1].length-1));
92-
93-
// expect(IOFront).toBeGreaterThanOrEqual(0);
94-
// expect(IOBack).toBeGreaterThanOrEqual(0);
95-
// }
96-
// });
97-
// });
98-
// });
99-
100-
*/
10129

10230
//* Dummy Test
10331
describe('dummy test', () => {

__tests__/ProcessLogHelper.test.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -83,22 +83,3 @@ describe('buildOptionsObj', () => {
8383
});
8484
});
8585

86-
// //We edited the makeArrayOfObjects function and now this fails, not sure why as there still is a key of logMsg and timeStamp
87-
// test('each object in returned array has timeStamp and logMsg properties', () => {
88-
// const processLog =
89-
// 'this_is_the_first_timestampZ this is the first log message\nthere is no second time stamp but there is a second log message';
90-
// const result = makeArrayOfObjects(processLog);
91-
92-
// let output = false;
93-
94-
// if (
95-
// result.every(
96-
// (element) =>
97-
// element.timeStamp && element.logMsg && element.containerName
98-
// )
99-
// ) {
100-
// output = true;
101-
// }
102-
103-
// expect(output).toEqual(true);
104-
// });

__tests__/VolumeTab.test.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
/** Docketeer 7.0
2-
* These tests do not work as enzyme is highly depricated and does not communicate with React 18
3-
*/
41

52
import React from 'react';
63
import { describe, expect, test, jest } from '@jest/globals';

server/app.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ app.use('/db', dbRouter);
3838
app.use('/logout', logoutRouter);
3939

4040
app.use('/', (req, res) => {
41+
/*
42+
Reads the current URL (explains why electron crashes)
43+
const url = new URL(`${req.protocol}://${req.get('host')}${req.originalUrl}`);
44+
console.log('current url',url);
45+
*/
46+
// for development purposes, so we don't have to reopen electron everytime
4147
return res.status(404).redirect('/');
4248
});
4349

server/controllers/settingsController.js

Lines changed: 57 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ const settingsController = {};
1010
settingsController.addContainer = async (req, res, next) => {
1111
const queryString = `INSERT INTO containers(id, name) VALUES ($1, $2) ON CONFLICT (id) DO NOTHING`;
1212
const parameters = [req.body.container, req.body.name];
13-
await db.query2(queryString, parameters)
13+
await db
14+
.query2(queryString, parameters)
1415
.then((data) => {
1516
return next();
1617
})
@@ -25,121 +26,141 @@ settingsController.addContainerSettings = async (req, res, next) => {
2526
FROM notification_settings
2627
WHERE metric_name = $2`;
2728
const parameters = [req.body.container, req.body.metric];
28-
await db.query2(queryString, parameters)
29+
await db
30+
.query2(queryString, parameters)
2931
.then((data) => {
30-
return next();
31-
})
32-
.catch((err) => {
33-
return next(err);
34-
})
32+
return next();
33+
})
34+
.catch((err) => {
35+
return next(err);
36+
});
3537
};
3638

3739
settingsController.deleteContainerSettings = async (req, res, next) => {
3840
const queryString = `DELETE FROM container_settings
3941
WHERE container_id = $1 and notification_settings_id = (SELECT id FROM notification_settings where metric_name = $2)`;
4042
const parameters = [req.body.container, req.body.metric];
41-
await db.query2(queryString, parameters)
43+
await db
44+
.query2(queryString, parameters)
4245
.then((data) => {
4346
return next();
44-
})
47+
})
4548
.catch((err) => {
4649
return next(err);
47-
})
50+
});
4851
};
4952

5053
settingsController.notificationSettings = async (req, res, next) => {
5154
const queryString = `SELECT cs.container_id, metric_name, triggering_value
5255
FROM container_settings cs
5356
INNER JOIN notification_settings ns ON cs.notification_settings_id = ns.id`;
54-
await db.query2(queryString)
57+
await db
58+
.query2(queryString)
5559
.then((data) => {
5660
const tempMemory = [];
5761
const tempCPU = [];
5862
const tempStopped = [];
5963
data.rows.forEach((container, i) => {
6064
if (container.metric_name === 'memory') {
6165
tempMemory.push(container.container_id);
62-
}
63-
else if (container.metric_name === 'cpu') {
66+
} else if (container.metric_name === 'cpu') {
6467
tempCPU.push(container.container_id);
65-
}
66-
else if (container.metric_name === 'stopped') {
68+
} else if (container.metric_name === 'stopped') {
6769
tempStopped.push(container.container_id);
6870
}
6971
});
7072
res.locals.memory = tempMemory;
7173
res.locals.cpu = tempCPU;
7274
res.locals.stopped = tempStopped;
7375
return next();
74-
})
76+
})
7577
.catch((err) => {
7678
console.log('getNotificationSettings: ', err);
7779
return next(err);
78-
})
80+
});
7981
};
8082

8183
settingsController.addPhoneNumber = async (req, res, next) => {
8284
const queryString = `INSERT INTO users (username, phone_number, notification_frequency, monitoring_frequency)
8385
VALUES ($1, $2, $3, $4)
8486
ON CONFLICT ON CONSTRAINT unique_username
8587
DO UPDATE SET phone_number = $2`;
86-
const parameters = [req.body.admin, req.body.number, req.body.digits[0], req.body.digits[1]];
87-
await db.query2(queryString, parameters)
88+
const parameters = [
89+
req.body.admin,
90+
req.body.number,
91+
req.body.digits[0],
92+
req.body.digits[1],
93+
];
94+
await db
95+
.query2(queryString, parameters)
8896
.then((data) => {
8997
return next();
90-
})
98+
})
9199
.catch((err) => {
92100
console.log('addPhoneNumber: ', err);
93101
return next(err);
94-
})
102+
});
95103
};
96104

97105
settingsController.notificationFrequency = async (req, res, next) => {
98106
const queryString = `INSERT INTO users (username, phone_number, notification_frequency, monitoring_frequency)
99107
VALUES ($1, $2, $3, $4)
100108
ON CONFLICT ON CONSTRAINT unique_username
101-
DO UPDATE SET notification_frequency = $3`
102-
const parameters = [req.body.user, req.body.phoneNumber, req.body.notification, req.body.monitoring];
103-
await db.query2(queryString, parameters)
109+
DO UPDATE SET notification_frequency = $3`;
110+
const parameters = [
111+
req.body.user,
112+
req.body.phoneNumber,
113+
req.body.notification,
114+
req.body.monitoring,
115+
];
116+
await db
117+
.query2(queryString, parameters)
104118
.then((data) => {
105119
return next();
106-
})
120+
})
107121
.catch((err) => {
108122
console.log('notificationFrequency: ', err);
109123
return next(err);
110-
})
124+
});
111125
};
112126

113127
settingsController.monitoringFrequency = async (req, res, next) => {
114128
const queryString = `INSERT INTO users (username, phone_number, notification_frequency, monitoring_frequency)
115129
VALUES ($1, $2, $3, $4)
116130
ON CONFLICT ON CONSTRAINT unique_username
117-
DO UPDATE SET monitoring_frequency = $4`
118-
const parameters = [req.body.user, req.body.phoneNumber, req.body.notification, req.body.monitoring];
119-
await db.query2(queryString, parameters)
131+
DO UPDATE SET monitoring_frequency = $4`;
132+
const parameters = [
133+
req.body.user,
134+
req.body.phoneNumber,
135+
req.body.notification,
136+
req.body.monitoring,
137+
];
138+
await db
139+
.query2(queryString, parameters)
120140
.then((data) => {
121141
return next();
122-
})
142+
})
123143
.catch((err) => {
124144
console.log('monitoringFrequency: ', err);
125145
return next(err);
126-
})
146+
});
127147
};
128148

129149
settingsController.addGitLinks = async (req, res, next) => {
130150
const queryString = `INSERT INTO containers (id, name, github_url)
131151
VALUES ($1, $2, $3)
132152
ON CONFLICT ON CONSTRAINT unique_id
133-
DO UPDATE SET github_url = $3`
153+
DO UPDATE SET github_url = $3`;
134154
const parameters = [req.body.id, req.body.name, req.body.url];
135-
await db.query2(queryString, parameters)
155+
await db
156+
.query2(queryString, parameters)
136157
.then((data) => {
137158
return next();
138-
})
159+
})
139160
.catch((err) => {
140161
console.log('addGitLinks: ', err);
141162
return next(err);
142-
})
163+
});
143164
};
144165

145-
module.exports = settingsController;
166+
module.exports = settingsController;

src/components/Login.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@
120120
<br/>
121121
<Button
122122
variant= 'contained'
123-
// color='grey'
124123
size='small'
125124
onClick={()=> navigate('/userSignup')}
126125
sx={{

src/components/SignUp.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ const SignUp = () => {
9191
<IconButton
9292
aria-label="toggle password visibility"
9393
onClick={handleClickShowPassword}
94-
// onMouseDown={handleMouseDownPassword}
9594
edge="end"
9695
>
9796
{values.showPassword ? <VisibilityOff /> : <Visibility />}

src/components/css/styles.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ ul {
101101
max-height: 800px;
102102
display: flex;
103103
flex-wrap: wrap;
104+
overflow-y: auto;
104105
}
105106

106107
.viewsAndButton {

src/components/helper/commands.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,12 @@ export const refreshRunning = (refreshRunningContainers) => {
8686
console.log(`refreshRunning stderr: ${stderr}`);
8787
return;
8888
}
89-
// console.log(stdout);
89+
9090
const dockerOutput = `[${stdout
9191
.trim()
9292
.slice(0, -1)
9393
.replaceAll(' ', '')}]`;
9494
const convertedValue = JSON.parse(dockerOutput);
95-
// console.log(convertedValue);
9695
refreshRunningContainers(convertedValue);
9796
}
9897
);
@@ -140,7 +139,6 @@ export const refreshImages = (callback) => {
140139
return;
141140
}
142141
const value = parseContainerFormat.convert(stdout);
143-
// console.log('stdout in refreshImages: ', stdout);
144142
const objArray = ['reps', 'tag', 'imgid', 'size'];
145143
const resultImages = [];
146144

@@ -239,7 +237,6 @@ export const runStopped = (
239237
export const runIm = (container, runningList, callback_1, callback_2) => {
240238
// props.runIm(ele['imgid'], props.runningList, helper.addRunning, props.addRunningContainers)
241239
const { imgid, reps, tag } = container;
242-
console.log(container);
243240
window.nodeMethod.runExec(`docker run --name ${reps}-${tag} ${reps}:${tag}`, (error, stdout, stderr) => {
244241
if (error) {
245242
alert(`${error.message}`);
@@ -311,11 +308,9 @@ export const handlePruneClick = (e) => {
311308
export const pullImage = (repo) => {
312309
window.nodeMethod.runExec(`docker pull ${repo}`, (error: child_process.ExecException | null, stdout: string, stderr: string) => {
313310
if (error) {
314-
console.log('error occurred in pulling image');
315311
alert(
316312
`Image repo '${repo}' seems to not exist, or may be a private repo.`
317313
);
318-
// alert(`${error.message}`);
319314
return;
320315
}
321316
if (stderr) {

0 commit comments

Comments
 (0)