Skip to content

Commit

Permalink
Merge pull request #7 from usorfaitheloho/feature-1
Browse files Browse the repository at this point in the history
Testing To Do list -part 2
  • Loading branch information
usorfaitheloho committed Mar 3, 2022
2 parents 7fa2c2b + 76e423a commit 5ca3759
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 16 deletions.
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
modules/task_collection.js
dist/
test/
45 changes: 32 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ToDo-list App


![](https://img.shields.io/badge/Microverse-blueviolet)
This is a microverse project that allows users to update tasks from a list using javascript modules

Our goal here is to Build a book application with add and remove feature from scratch using JavaScripts... click [here] (https://usorfaitheloho.github.io/ToDo-list-app/dist) to see deployed live version
Expand Down Expand Up @@ -36,24 +36,43 @@ To get a local copy up and running follow these simple example steps.
- git clone https://github.com/usorfaitheloho/ToDo-list-app.git


## Getting packages and dependencies
To get all package modules required to build the project run:
```
cd To-Do-list-Application
npm install
npm run start
```
## Getting packages and debuging with Stylelint
```
npm install --save-dev stylelint@13.x stylelint-scss@3.x stylelint-config-standard@21.x stylelint-csstree-validator@1.x
```
##### For validation detection using Stylelint Run
```
npx stylelint "**/*.{css,scss}"
```
##### from parent source directory
## Getting packages and debuging with ESlint
```
npm install npm install --save-dev eslint@7.x eslint-config-airbnb-base@14.x eslint-plugin-import@2.x babel-eslint@10.x
```
##### For validation detection using Stylelint Run
```
npx eslint .
```
##### from parent source directory
## Getting packages and debuging with Webhint
```
npm init -y
npm install --save-dev hint@6.x
```
every package module required to build the project is listed in the package.json file. this is used as a reference to get all dependencies.
## Building
To build the project run:
##### For validation detection using Webhint Run
```
npm run-script build
npx hint .
```
after you run this sucessfully you'd locate the build from in the ```dist``` folder located from the parent directory of the project. two files are being built which are, ```core.js and index.html``
## Running
To run the program on a browser through a server run this command in your cli
## Unit Testing
You can find each unit test cases in the Test folder located in the parent source directory of the project. you can create your own custom unit test and test it by running
```
npm start
npx run test
```
This should open the page in your localhost on port 8080. then you'd be able to view the built page generated using webpack.
This should run all unit test found in the application.test.js from the Test folder.
## Authors
Expand Down
39 changes: 37 additions & 2 deletions modules/task_collection.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class TaskCollection {
constructor(isTest = false) {
constructor(isTest = false) {
this.addTask = document.querySelector('.add-task');
this.domList = document.querySelector('.todo-list');
this.todoList = [];
Expand Down Expand Up @@ -36,7 +36,35 @@ class TaskCollection {
this.updateDom();
}


editTaskList = (index, word) => {
if (index < this.todoList.length) {
this.todoList[index].description = word;
this.onSaveList();
}

return this.todoList[index].description;
}

checkTask = (index, status) => {
if (index < this.todoList.length) {
this.todoList[index].completed = !status;
this.onSaveList();
}

return this.todoList[index].completed;
}

clearAllChecked = () => {
const filteredTasks = this.todoList.filter((item) => {
const state = item.completed === false;
return state;
});
this.todoList = filteredTasks;
this.onSaveList();

return this.todoList === filteredTasks;
}

updateDom = () => {
const ref = this;
this.domList.innerHTML = '';
Expand Down Expand Up @@ -150,6 +178,13 @@ class TaskCollection {
}
});

desc.addEventListener('focusout', (event) => {
const refObj = event.currentTarget;
if (refObj.value.innerHTML !== refObj.ref.todoList[refObj.index].description) {
this.editTaskList(refObj.index, refObj.value.innerHTML);
}
});

desc.index = index;
desc.ref = ref;
desc.value = desc;
Expand Down
120 changes: 120 additions & 0 deletions test/task_collection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,123 @@ describe("Delete from list", () => {
expect(list).toHaveLength(2);
});
});

describe("Edit Task Description", () => {
test("Test case 11", () => {
const Test = new TaskCollection(true);
Test.addTaskToList("TaskTest_1 of Example 1");
Test.addTaskToList("TaskTest_1 of Example-2");
Test.deleteTask(0);
Test.addTaskToList("TaskTest_1 of Example-3");
Test.deleteTask(1);
expect(Test.onSaveList()).not.toBeUndefined();
const newDescription = "This particular value has changed";

expect(Test.editTaskList(0, newDescription)).toEqual(newDescription);
});

test("Test case 12", () => {
const Test = new TaskCollection(true);
expect(Test.onLoadList()).not.toBeUndefined();
Test.addTaskToList("TaskTest_1 of Example 1");
Test.addTaskToList("TaskTest_1 of Example-2");
Test.addTaskToList("TaskTest_1 of Example-3");
expect(Test.onSaveList()).not.toBeUndefined();
const newDescription = "This is a good edge test case";

expect(Test.editTaskList(2, newDescription)).toEqual(newDescription);
});

test("Test case 13", () => {
const Test = new TaskCollection(true);
Test.addTaskToList("TaskTest_1 of Example 1");
Test.addTaskToList("TaskTest_1 of Example-2");
Test.deleteTask(1);
Test.addTaskToList("TaskTest_1 of Example-3");
expect(Test.onSaveList()).not.toBeUndefined();
const newDescription = "UAT Test debug chips";

expect(Test.editTaskList(0, newDescription)).toEqual(newDescription);
});
});

describe("Update Task Completed Status", () => {
test("Test case 14", () => {
const Test = new TaskCollection(true);
Test.addTaskToList("TaskTest_1 of Example 1");
Test.addTaskToList("TaskTest_1 of Example-2");
Test.deleteTask(0);
Test.addTaskToList("TaskTest_1 of Example-3");
Test.deleteTask(1);
expect(Test.onSaveList()).not.toBeUndefined();

expect(Test.checkTask(0, true)).toBeFalsy();
});

test("Test case 15", () => {
const Test = new TaskCollection(true);
expect(Test.onLoadList()).not.toBeUndefined();
Test.addTaskToList("TaskTest_1 of Example 1");
Test.addTaskToList("TaskTest_1 of Example-2");
Test.addTaskToList("TaskTest_1 of Example-3");
expect(Test.onSaveList()).not.toBeUndefined();

expect(Test.checkTask(2, false)).toBeTruthy();
});

test("Test case 16", () => {
const Test = new TaskCollection(true);
Test.addTaskToList("TaskTest_1 of Example 1");
Test.addTaskToList("TaskTest_1 of Example-2");
Test.deleteTask(1);
Test.addTaskToList("TaskTest_1 of Example-3");
expect(Test.onSaveList()).not.toBeUndefined();

expect(Test.checkTask(0, true)).toBeFalsy();
});
});

describe("Clear All Completed Tasks", () => {
test("Test case 17", () => {
const Test = new TaskCollection(true);
Test.addTaskToList("TaskTest_1 of Example 1");
Test.addTaskToList("TaskTest_1 of Example-2");
Test.deleteTask(0);
Test.addTaskToList("TaskTest_1 of Example-3");
Test.deleteTask(1);
expect(Test.onSaveList()).not.toBeUndefined();

Test.checkTask(0, true);
expect(Test.clearAllChecked()).toBeTruthy();
});

test("Test case 18", () => {
const Test = new TaskCollection(true);
expect(Test.onLoadList()).not.toBeUndefined();
Test.addTaskToList("TaskTest_1 of Example 1");
Test.addTaskToList("TaskTest_1 of Example-2");
Test.addTaskToList("TaskTest_1 of Example-3");
expect(Test.onSaveList()).not.toBeUndefined();

Test.checkTask(2, true);
Test.checkTask(0, true);
expect(Test.clearAllChecked()).toBeTruthy();
});

test("Test case 29", () => {
const Test = new TaskCollection(true);
Test.addTaskToList("TaskTest_1 of Example 1");
Test.addTaskToList("TaskTest_1 of Example-2");
Test.addTaskToList("TaskTest_1 of Example-3");
Test.addTaskToList("TaskTest_1 of Example-4");
Test.addTaskToList("TaskTest_1 of Example-5");
Test.addTaskToList("TaskTest_1 of Example-6");
Test.addTaskToList("TaskTest_1 of Example-7");
Test.addTaskToList("TaskTest_1 of Example-8");
expect(Test.onSaveList()).not.toBeUndefined();
Test.checkTask(0, true);
Test.checkTask(1, true);
Test.checkTask(2, true);
expect(Test.clearAllChecked()).toBeTruthy();
});
});

0 comments on commit 5ca3759

Please sign in to comment.