Skip to content

Commit

Permalink
Merge pull request #35 from rishi2019194/ui-branch-3
Browse files Browse the repository at this point in the history
add legend to graph, add javaScript assert tests for FE
  • Loading branch information
rishi2019194 authored Nov 25, 2023
2 parents fb84419 + 71a7aca commit c3272b1
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 0 deletions.
88 changes: 88 additions & 0 deletions static/js/tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
console.assert(() => {
addToLocalStorage("testKey", "testData");
return localStorage.getItem("testKey") === "testData";
}, "addToLocalStorage test failed");

// Test retrieveFromLocalStorage function
localStorage.setItem("testRetrieveKey", "testRetrieveData");
console.assert(() => {
return retrieveFromLocalStorage("testRetrieveKey") === "testRetrieveData";
}, "retrieveFromLocalStorage test failed");


console.assert(() => {
let ajaxCalled = false;
$.ajax = function(options) {
ajaxCalled = true;
options.success();
};

logout();

return ajaxCalled;
}, "logout test failed");

// Test history function
console.assert(() => {
let ajaxCalled = false;
$.ajax = function(options) {
ajaxCalled = true;
options.success('{"date":"2023-01-01","calories":2000,"burnout":300}');
};

history({ target: document.createElement('form') });

return $("#date").text() === "2023-01-01" && $("#calories").text() === "2000" && $("#burnout").text() === "300" && ajaxCalled;
}, "history test failed");

// Test sendRequest function
console.assert(() => {
let ajaxCalled = false;
$.ajax = function(options) {
ajaxCalled = true;
options.success('{}');
};

sendRequest({}, "testReceiver");

return ajaxCalled;
}, "sendRequest test failed");

// Test cancelRequest function
console.assert(() => {
let ajaxCalled = false;
$.ajax = function(options) {
ajaxCalled = true;
options.success('{}');
};

cancelRequest({}, "testReceiver");

return ajaxCalled;
}, "cancelRequest test failed");

// Test approveRequest function
console.assert(() => {
let ajaxCalled = false;
$.ajax = function(options) {
ajaxCalled = true;
options.success('{}');
};

approveRequest({}, "testReceiver");

return ajaxCalled;
}, "approveRequest test failed");

// Test dashboard function
console.assert(() => {
let ajaxCalled = false;
$.ajax = function(options) {
ajaxCalled = true;
options.success('{"enroll":5}');
};

dashboard({}, "[email protected]");

return $("#enroll").text() === "5" && ajaxCalled;
}, "dashboard test failed");
43 changes: 43 additions & 0 deletions static/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,42 @@
}


.legend {
display: flex;
align-items: center;
justify-content: space-around;
padding: 10px;
margin-left: 10rem;
flex-direction: column;
align-items: flex-start;
justify-content: space-around;

}

.legend div {
display: flex;
align-items: center;
}

.legend label {
margin-bottom: 0px;
}

.legend span {
display: inline-block;
width: 20px;
height: 20px;
margin-right: 5px;
}

#calories-burnt {
background-color: rgba(220,20,60,0.91);
}

#calories-consumed {
background-color: #84d320;
}

footer {
margin-top: auto;
}
Expand Down Expand Up @@ -57,6 +93,13 @@
width: 55%;
align-self: center;
box-shadow: 0px 0px 95px -30px rgba(0, 0, 0, 0.15);
margin-left: auto;
margin-right: auto;
}

.sign-in-div {
width: 55%;
margin: auto;
}

.content-section-container {
Expand Down
10 changes: 10 additions & 0 deletions templates/history.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ <h4>Great job with the progress</h4>
},
});
</script>
<div class="legend">
<div>
<span id="calories-burnt"></span>
<label>Calories Burnt</label>
</div>
<div>
<span id="calories-consumed"></span>
<label>Calories Consumed</label>
</div>
</div>
</div>


Expand Down
1 change: 1 addition & 0 deletions templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,6 @@ <h5 class="text-white mb-3">Newsletter</h5>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<script src="../static/js/script.js"></script>
<script src="../static/js/tests.js"></script>
</body>
</html>

0 comments on commit c3272b1

Please sign in to comment.