diff --git a/src/App.test.js b/src/App.test.js index dc768d7..dcde286 100644 --- a/src/App.test.js +++ b/src/App.test.js @@ -1,14 +1,18 @@ import { render, screen } from '@testing-library/react'; import App from './App'; -test('renders add task button', () => { - // Mock console.info method - console.info = jest.fn(); +describe('App', () => { - render(); - const addButton = screen.getByText(/Add Task/i); - expect(addButton).toBeInTheDocument(); + test('renders add task button', () => { + // Mock console.info method + console.info = jest.fn(); + + render(); + const addButton = screen.getByText(/Add Task/i); + expect(addButton).toBeInTheDocument(); + + // Verify that console.info was called + expect(console.info).toHaveBeenCalled(); + }); - // Verify that console.info was called - expect(console.info).toHaveBeenCalled(); }); diff --git a/src/core/logicUtils.test.js b/src/core/logicUtils.test.js index 59d9e09..b3cae57 100644 --- a/src/core/logicUtils.test.js +++ b/src/core/logicUtils.test.js @@ -1,66 +1,70 @@ import { objectsAreEqual, objectArraysAreEqual } from './logicUtils'; -test('objectsAreEqual returns true for equal objects', () => { - const obj1 = { name: 'John', age: 30 }; - const obj2 = { name: 'John', age: 30 }; - expect(objectsAreEqual(obj1, obj2)).toBe(true); -}); +describe('logicUtils', () => { -test('objectsAreEqual returns false for objects with different properties', () => { - const obj1 = { name: 'John', age: 30 }; - const obj2 = { name: 'John', age: 30, city: 'New York' }; - expect(objectsAreEqual(obj1, obj2)).toBe(false); -}); + test('objectsAreEqual returns true for equal objects', () => { + const obj1 = { name: 'John', age: 30 }; + const obj2 = { name: 'John', age: 30 }; + expect(objectsAreEqual(obj1, obj2)).toBe(true); + }); -test('objectsAreEqual returns false for objects with different property values', () => { - const obj1 = { name: 'John', age: 30 }; - const obj2 = { name: 'John', age: 40 }; - expect(objectsAreEqual(obj1, obj2)).toBe(false); -}); + test('objectsAreEqual returns false for objects with different properties', () => { + const obj1 = { name: 'John', age: 30 }; + const obj2 = { name: 'John', age: 30, city: 'New York' }; + expect(objectsAreEqual(obj1, obj2)).toBe(false); + }); -test('objectsAreEqual returns false for objects with different number of properties', () => { - const obj1 = { name: 'John', age: 30 }; - const obj2 = { name: 'John' }; - expect(objectsAreEqual(obj1, obj2)).toBe(false); -}); + test('objectsAreEqual returns false for objects with different property values', () => { + const obj1 = { name: 'John', age: 30 }; + const obj2 = { name: 'John', age: 40 }; + expect(objectsAreEqual(obj1, obj2)).toBe(false); + }); -test('objectArraysAreEqual returns true for equal arrays of objects', () => { - const arr1 = [ - { id: 1, name: 'John', age: 30 }, - { id: 2, name: 'Jane', age: 25 }, - { id: 3, name: 'Bob', age: 40 } - ]; - const arr2 = [ - { id: 1, name: 'John', age: 30 }, - { id: 2, name: 'Jane', age: 25 }, - { id: 3, name: 'Bob', age: 40 } - ]; - expect(objectArraysAreEqual(arr1, arr2)).toBe(true); -}); + test('objectsAreEqual returns false for objects with different number of properties', () => { + const obj1 = { name: 'John', age: 30 }; + const obj2 = { name: 'John' }; + expect(objectsAreEqual(obj1, obj2)).toBe(false); + }); -test('objectArraysAreEqual returns false for arrays with different lengths', () => { - const arr1 = [ - { id: 1, name: 'John', age: 30 }, - { id: 2, name: 'Jane', age: 25 }, - { id: 3, name: 'Bob', age: 40 } - ]; - const arr2 = [ - { id: 1, name: 'John', age: 30 }, - { id: 2, name: 'Jane', age: 25 } - ]; - expect(objectArraysAreEqual(arr1, arr2)).toBe(false); -}); + test('objectArraysAreEqual returns true for equal arrays of objects', () => { + const arr1 = [ + { id: 1, name: 'John', age: 30 }, + { id: 2, name: 'Jane', age: 25 }, + { id: 3, name: 'Bob', age: 40 } + ]; + const arr2 = [ + { id: 1, name: 'John', age: 30 }, + { id: 2, name: 'Jane', age: 25 }, + { id: 3, name: 'Bob', age: 40 } + ]; + expect(objectArraysAreEqual(arr1, arr2)).toBe(true); + }); -test('objectArraysAreEqual returns false for arrays with different objects', () => { - const arr1 = [ - { id: 1, name: 'John', age: 30 }, - { id: 2, name: 'Jane', age: 25 }, - { id: 3, name: 'Bob', age: 40 } - ]; - const arr2 = [ - { id: 1, name: 'John', age: 30 }, - { id: 2, name: 'Jane', age: 35 }, - { id: 3, name: 'Bob', age: 40 } - ]; - expect(objectArraysAreEqual(arr1, arr2)).toBe(false); -}); \ No newline at end of file + test('objectArraysAreEqual returns false for arrays with different lengths', () => { + const arr1 = [ + { id: 1, name: 'John', age: 30 }, + { id: 2, name: 'Jane', age: 25 }, + { id: 3, name: 'Bob', age: 40 } + ]; + const arr2 = [ + { id: 1, name: 'John', age: 30 }, + { id: 2, name: 'Jane', age: 25 } + ]; + expect(objectArraysAreEqual(arr1, arr2)).toBe(false); + }); + + test('objectArraysAreEqual returns false for arrays with different objects', () => { + const arr1 = [ + { id: 1, name: 'John', age: 30 }, + { id: 2, name: 'Jane', age: 25 }, + { id: 3, name: 'Bob', age: 40 } + ]; + const arr2 = [ + { id: 1, name: 'John', age: 30 }, + { id: 2, name: 'Jane', age: 35 }, + { id: 3, name: 'Bob', age: 40 } + ]; + expect(objectArraysAreEqual(arr1, arr2)).toBe(false); + }); + +}); diff --git a/src/core/taskUtils.test.js b/src/core/taskUtils.test.js index 7c4822a..b2a3c76 100644 --- a/src/core/taskUtils.test.js +++ b/src/core/taskUtils.test.js @@ -1,41 +1,45 @@ import { hasNew, hasReady } from './taskUtils'; -describe('hasNew', () => { - test('should return false for empty list', () => { - const tasks = []; - const result = hasNew(tasks); - expect(result).toBe(false); - }); - - test('should return false for list with no new items', () => { - const tasks = [{ id: 0, text: 'task1', status: "ready" }]; - const result = hasNew(tasks); - expect(result).toBe(false); - }); - - test('should return true for list with new items', () => { - const tasks = [{ id: 0, text: 'task1', status: "new" }]; - const result = hasNew(tasks); - expect(result).toBe(true); - }); -}); +describe('taskUtils', () => { -describe('hasReady', () => { - test('should return false for empty list', () => { - const tasks = []; - const result = hasReady(tasks); - expect(result).toBe(false); + describe('hasNew', () => { + test('should return false for empty list', () => { + const tasks = []; + const result = hasNew(tasks); + expect(result).toBe(false); + }); + + test('should return false for list with no new items', () => { + const tasks = [{ id: 0, text: 'task1', status: "ready" }]; + const result = hasNew(tasks); + expect(result).toBe(false); + }); + + test('should return true for list with new items', () => { + const tasks = [{ id: 0, text: 'task1', status: "new" }]; + const result = hasNew(tasks); + expect(result).toBe(true); + }); }); - - test('should return false for list with no ready items', () => { - const tasks = [{ id: 0, text: 'task1', status: "new" }]; - const result = hasReady(tasks); - expect(result).toBe(false); - }); - - test('should return true for list with ready items', () => { - const tasks = [{ id: 0, text: 'task1', status: "ready" }]; - const result = hasReady(tasks); - expect(result).toBe(true); + + describe('hasReady', () => { + test('should return false for empty list', () => { + const tasks = []; + const result = hasReady(tasks); + expect(result).toBe(false); + }); + + test('should return false for list with no ready items', () => { + const tasks = [{ id: 0, text: 'task1', status: "new" }]; + const result = hasReady(tasks); + expect(result).toBe(false); + }); + + test('should return true for list with ready items', () => { + const tasks = [{ id: 0, text: 'task1', status: "ready" }]; + const result = hasReady(tasks); + expect(result).toBe(true); + }); }); -}); \ No newline at end of file + +}); diff --git a/src/core/tasksManager.test.js b/src/core/tasksManager.test.js index 20c1992..7640e20 100644 --- a/src/core/tasksManager.test.js +++ b/src/core/tasksManager.test.js @@ -1,109 +1,113 @@ import { addAll, addTask, nextId, completeBenchmarkTask, cancelItem, cloneItem } from './tasksManager'; -describe('nextId function', () => { - test('should return 0 for an empty tasks list', () => { - const tasks = []; - const result = nextId(tasks); - expect(result).toBe(0); - }); +describe('tasksManager', () => { - test('should return 1 for a tasks list with one item having id 0', () => { - const tasks = [{ id: 0, text: 'task1', status: "ready" }]; - const result = nextId(tasks); - expect(result).toBe(1); - }); + describe('nextId function', () => { + test('should return 0 for an empty tasks list', () => { + const tasks = []; + const result = nextId(tasks); + expect(result).toBe(0); + }); + + test('should return 1 for a tasks list with one item having id 0', () => { + const tasks = [{ id: 0, text: 'task1', status: "ready" }]; + const result = nextId(tasks); + expect(result).toBe(1); + }); - test('should return 6 for a tasks list with items having ids 3 and 5', () => { - const tasks = [ - { id: 3, text: 'task1', status: "ready" }, - { id: 5, text: 'task2', status: "new" } - ]; - const result = nextId(tasks); - expect(result).toBe(6); + test('should return 6 for a tasks list with items having ids 3 and 5', () => { + const tasks = [ + { id: 3, text: 'task1', status: "ready" }, + { id: 5, text: 'task2', status: "new" } + ]; + const result = nextId(tasks); + expect(result).toBe(6); + }); }); -}); -describe('addTask function', () => { - test('should add task to empty list at ready status', () => { - const taskText = "New Task"; - let newTasks = []; - newTasks = addTask(newTasks, taskText); + describe('addTask function', () => { + test('should add task to empty list at ready status', () => { + const taskText = "New Task"; + let newTasks = []; + newTasks = addTask(newTasks, taskText); - expect(newTasks.length).toBe(1); - expect(newTasks[0].id).toBe(0); - expect(newTasks[0].text).toBe(taskText); - expect(newTasks[0].status).toBe("ready"); - }); + expect(newTasks.length).toBe(1); + expect(newTasks[0].id).toBe(0); + expect(newTasks[0].text).toBe(taskText); + expect(newTasks[0].status).toBe("ready"); + }); - test('should add new task to list that already has ready items', () => { - let newTasks = []; - newTasks = addTask(newTasks, "a"); - newTasks = addTask(newTasks, "b"); + test('should add new task to list that already has ready items', () => { + let newTasks = []; + newTasks = addTask(newTasks, "a"); + newTasks = addTask(newTasks, "b"); - expect(newTasks.length).toBe(2); - expect(newTasks[0].status).toBe("ready"); - expect(newTasks[1].status).toBe("new"); + expect(newTasks.length).toBe(2); + expect(newTasks[0].status).toBe("ready"); + expect(newTasks[1].status).toBe("new"); + }); }); -}); -describe('completeBenchmarkTask function', () => { - test('should mark the single ready task as done', () => { - const tasks = [{"id": 0, "text": "a", "status": "ready"}]; - const updatedTasks = completeBenchmarkTask(tasks); - expect(updatedTasks).toStrictEqual([{"id": 0, "text": "a", "status": "done"}]); - }); + describe('completeBenchmarkTask function', () => { + test('should mark the single ready task as done', () => { + const tasks = [{"id": 0, "text": "a", "status": "ready"}]; + const updatedTasks = completeBenchmarkTask(tasks); + expect(updatedTasks).toStrictEqual([{"id": 0, "text": "a", "status": "done"}]); + }); - test('should mark the benchmark task and automark the new item', () => { - const tasks = [{"id": 0, "text": "a", "status": "done"}, - {"id": 1, "text": "b", "status": "ready"}, - {"id": 2, "text": "c", "status": "new"}]; - const updatedTasks = completeBenchmarkTask(tasks); - expect(updatedTasks).toStrictEqual([{"id": 0, "text": "a", "status": "done"}, - {"id": 1, "text": "b", "status": "done"}, - {"id": 2, "text": "c", "status": "ready"}]); + test('should mark the benchmark task and automark the new item', () => { + const tasks = [{"id": 0, "text": "a", "status": "done"}, + {"id": 1, "text": "b", "status": "ready"}, + {"id": 2, "text": "c", "status": "new"}]; + const updatedTasks = completeBenchmarkTask(tasks); + expect(updatedTasks).toStrictEqual([{"id": 0, "text": "a", "status": "done"}, + {"id": 1, "text": "b", "status": "done"}, + {"id": 2, "text": "c", "status": "ready"}]); + }); }); -}); -describe('cancelItem function', () => { - test('should mark an item as cancelled', () => { - const tasks = [{ id: 0, text: 'task1', status: "ready" }]; - const result = cancelItem(tasks, 0); - expect(result.length).toBe(1); - expect(result[0].status).toBe('cancelled'); - expect(result[0].was).toBe('ready'); - }); + describe('cancelItem function', () => { + test('should mark an item as cancelled', () => { + const tasks = [{ id: 0, text: 'task1', status: "ready" }]; + const result = cancelItem(tasks, 0); + expect(result.length).toBe(1); + expect(result[0].status).toBe('cancelled'); + expect(result[0].was).toBe('ready'); + }); - test('should trigger the next automarkable item to get automarked', () => { - const tasks = [{ id: 0, text: 'task1', status: "ready" }, - { id: 1, text: 'task2', status: "new" }]; - const result = cancelItem(tasks, 0); - expect(result.length).toBe(2); - expect(result[0].status).toBe('cancelled'); - expect(result[0].was).toBe('ready'); - expect(result[1].status).toBe('ready'); + test('should trigger the next automarkable item to get automarked', () => { + const tasks = [{ id: 0, text: 'task1', status: "ready" }, + { id: 1, text: 'task2', status: "new" }]; + const result = cancelItem(tasks, 0); + expect(result.length).toBe(2); + expect(result[0].status).toBe('cancelled'); + expect(result[0].was).toBe('ready'); + expect(result[1].status).toBe('ready'); + }); }); -}); -describe('cloneItem function', () => { - test('should clone an item and add it to the list', () => { - const tasks = [{ id: 0, text: 'task1', status: "done" }]; - const result = cloneItem(tasks, 0); - expect(result.length).toBe(2); - expect(result[1]).toStrictEqual({ id: 1, text: 'task1', status: "ready"}); + describe('cloneItem function', () => { + test('should clone an item and add it to the list', () => { + const tasks = [{ id: 0, text: 'task1', status: "done" }]; + const result = cloneItem(tasks, 0); + expect(result.length).toBe(2); + expect(result[1]).toStrictEqual({ id: 1, text: 'task1', status: "ready"}); + }); }); -}); -describe('addAll function', () => { - test('should add all items from the new list to the old list', () => { - const initialTasks = [{ id: 0, text: 'task1', status: "done" }]; - const newTasks = [{ id: 1, text: 'task2', status: "ready" }, - { id: 2, text: 'task3', status: "new" }]; - const result = addAll(initialTasks, newTasks); - expect(result.length).toBe(3); - expect(result[0]).toStrictEqual({ id: 0, text: 'task1', status: "done" }); - expect(result[1]).toStrictEqual({ id: 1, text: 'task2', status: "ready" }); - expect(result[2]).toStrictEqual({ id: 2, text: 'task3', status: "new" }); + describe('addAll function', () => { + test('should add all items from the new list to the old list', () => { + const initialTasks = [{ id: 0, text: 'task1', status: "done" }]; + const newTasks = [{ id: 1, text: 'task2', status: "ready" }, + { id: 2, text: 'task3', status: "new" }]; + const result = addAll(initialTasks, newTasks); + expect(result.length).toBe(3); + expect(result[0]).toStrictEqual({ id: 0, text: 'task1', status: "done" }); + expect(result[1]).toStrictEqual({ id: 1, text: 'task2', status: "ready" }); + expect(result[2]).toStrictEqual({ id: 2, text: 'task3', status: "new" }); + }); }); -}); \ No newline at end of file + +});