Skip to content

Commit

Permalink
refactor organize tests into suites
Browse files Browse the repository at this point in the history
  • Loading branch information
avidrucker committed Nov 21, 2023
1 parent 689deba commit 861b1ee
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 189 deletions.
20 changes: 12 additions & 8 deletions src/App.test.js
Original file line number Diff line number Diff line change
@@ -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(<App />);
const addButton = screen.getByText(/Add Task/i);
expect(addButton).toBeInTheDocument();
test('renders add task button', () => {
// Mock console.info method
console.info = jest.fn();

render(<App />);
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();
});
120 changes: 62 additions & 58 deletions src/core/logicUtils.test.js
Original file line number Diff line number Diff line change
@@ -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);
});
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);
});

});
76 changes: 40 additions & 36 deletions src/core/taskUtils.test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
});

});
Loading

0 comments on commit 861b1ee

Please sign in to comment.