Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a Test for the Count-Reaservations Function #30

Open
wants to merge 2 commits into
base: add-new-reservation
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"presets": ["@babel/preset-env"],
"plugins": ["@babel/plugin-proposal-class-properties", "@babel/plugin-transform-modules-commonjs", "@babel/plugin-transform-runtime"]

"env": {
"test": {
"plugins": ["@babel/plugin-transform-modules-commonjs"]
}
}
}
10 changes: 10 additions & 0 deletions _test_/reservationsCounter.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import ReservationsCounter from '../src/module/reservationsCounter.js';

describe('Check reservations count', () => {
test('return number of items in array', () => {
const reservations = ['reservation1', 'reservation2', 'reservation3', 'reservation4'];

const countReservations = new ReservationsCounter(reservations);
expect(countReservations.getLength()).toEqual(4);
});
});
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"homepage": "https://github.com/topeogunleye/basic-setup#readme",
"devDependencies": {
"@babel/core": "^7.16.5",
"@babel/plugin-transform-modules-commonjs": "^7.19.6",
"@babel/preset-env": "^7.16.5",
"babel-eslint": "^10.1.0",
"babel-jest": "^27.4.5",
Expand All @@ -32,7 +33,7 @@
"favicons-webpack-plugin": "^5.0.2",
"hint": "^6.1.9",
"html-webpack-plugin": "^5.5.0",
"jest": "^27.4.5",
"jest": "^27.5.1",
"style-loader": "^3.3.1",
"stylelint": "^13.13.1",
"stylelint-config-standard": "^21.0.0",
Expand All @@ -48,4 +49,4 @@
"lodash": "^4.17.21",
"uuidv4": "^6.2.12"
}
}
}
8 changes: 4 additions & 4 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,10 @@ <h1 class="heading text-center">Bounty Food :)</h1>
</div>
</div>

<div class="reservations">
<h1 class="sub-heading text-center">Reservation (2)</h1>
<p>03-10-2022 - 11-05-2022 by Jimmy</p>
<p>03-10-2022 - 11-05-2022 by Jidula</p>
<div class="reservations-box">
<h1 class="sub-heading text-center">Reservation (<span class="counts"></span>)</h1>

<div class="reservations"></div>
</div>

<form class="reservation-form">
Expand Down
8 changes: 8 additions & 0 deletions src/module/reservation.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import ReservationsCounter from './reservationsCounter.js';

const reservationBtn = document.querySelector('.reservation-btn');
const modal = document.querySelector('.modal');

Expand All @@ -16,6 +18,12 @@ const updateReservationsList = async () => {
const items = await data.json();

reservations.innerHTML = '';
const counts = document.querySelector('.counts');

const countReservations = new ReservationsCounter(items);

counts.innerText = countReservations.getLength();

items.forEach((item) => {
const content = `
<p>${item.date_start} - ${item.date_end} by ${item.username}</p>
Expand Down
9 changes: 9 additions & 0 deletions src/module/reservationsCounter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default class ReservationsCounter {
constructor(reservations) {
this.reservations = reservations;
}

getLength() {
return this.reservations.length;
}
}
8 changes: 8 additions & 0 deletions src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -365,3 +365,11 @@ li.page-item.active {
background-color: #374151;
width: 30%;
}

.reservations p {
padding: 3px 3px;
}

.reservations p:nth-child(odd) {
background-color: rgb(241, 241, 241);
}