Skip to content

Commit

Permalink
Merge pull request #6 from ahangarha/test-part-2
Browse files Browse the repository at this point in the history
Test part 2
  • Loading branch information
ahangarha committed Feb 23, 2022
2 parents 5f826f0 + 1073ae6 commit c44889c
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/modules/todoList.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,13 @@ export default class TodoList {
li.classList.add('active');
});

description.addEventListener('focusout', () => {
description.addEventListener('focusout', (event) => {
description.readOnly = true;
const newDescription = event.target.value;
const index = Number(event.target.parentElement.id.match(/\d+$/));
this.todos[index].description = newDescription;
li.classList.remove('active');
this.refreshTodosOnPage();
});

const actionIcon = document.createElement('div');
Expand Down
59 changes: 59 additions & 0 deletions src/modules/todoList.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,62 @@ describe('Test - Part 1', () => {
expect(wrapper.innerHTML).toBe('');
});
});

describe('Test Part 2', () => {
test('test edit Task', () => {
// Arrange
document.body.innerHTML = '<ul id="todo-list"></ul>';
const wrapper = document.getElementById('todo-list');
const todoList = new TodoList(wrapper);
todoList.addNewItem('New todo');
const input = document.querySelector('#todo-0 input');

// Act
input.focus();
input.value = 'edited';
input.blur();

// Assert
expect(todoList.todos[0].description).toBe('edited');
});

test('test completed task', () => {
// Arrange
document.body.innerHTML = '<ul id="todo-list"></ul>';
const wrapper = document.getElementById('todo-list');
const todoList = new TodoList(wrapper);
const todoElement = document.querySelector('#todo-0');
const button = document.querySelector('#todo-0 .completionIcon');

// Act
button.click();

// Assert
expect(todoElement.classList).toContain('completed');
expect(todoList.todos[0].completed).toBe(true);
});

test('remove all completed todos', () => {
// Arrange
document.body.innerHTML = `<ul id="todo-list"></ul>
<button type="button" id="clear-all">Clear all</button>`;
const wrapper = document.getElementById('todo-list');
const todoList = new TodoList(wrapper);

todoList.addNewItem('todo 1');
todoList.addNewItem('todo to remain');

const button1 = document.querySelector('#todo-1 .completionIcon');
const clearAllBtn = document.getElementById('clear-all');

// Act
button1.click();
clearAllBtn.click();
todoList.removeAllCompleted();

// Assert
expect(wrapper.children.length).toBe(1);
expect(todoList.todos.length).toBe(1);
expect(todoList.todos[0].description).toBe('todo to remain');
});
});

0 comments on commit c44889c

Please sign in to comment.