-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b24610f
commit c86f957
Showing
9 changed files
with
4,945 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,50 @@ | ||
const { getStateFromDates } = require('../js/global'); | ||
const { getStateFromDates } = require("../js/global"); | ||
|
||
describe('getStateFromDates', () => { | ||
describe("getStateFromDates", () => { | ||
beforeEach(() => { | ||
// Mock the system time to ensure consistent results | ||
jest.useFakeTimers().setSystemTime(new Date('2024-11-21T12:00:00Z')); // Mock current time: 7 AM ET | ||
jest.useFakeTimers().setSystemTime(new Date("2024-11-21T12:00:00Z")); // Mock current time: 7 AM ET | ||
}); | ||
|
||
afterEach(() => { | ||
jest.useRealTimers(); // Restore real timers | ||
}); | ||
|
||
test('should return "unknown" if both opens and closes are undefined', () => { | ||
expect(getStateFromDates(null, null)).toBe('unknown'); | ||
expect(getStateFromDates(undefined, undefined)).toBe('unknown'); | ||
expect(getStateFromDates(null, null)).toBe("unknown"); | ||
expect(getStateFromDates(undefined, undefined)).toBe("unknown"); | ||
}); | ||
|
||
test('should return "upcoming" if now is before opens', () => { | ||
const opens = '2024-11-22T00:00:00Z'; // Opens tomorrow at midnight UTC | ||
expect(getStateFromDates(opens, null)).toBe('upcoming'); | ||
const opens = "2024-11-22T00:00:00Z"; // Opens tomorrow at midnight UTC | ||
expect(getStateFromDates(opens, null)).toBe("upcoming"); | ||
}); | ||
|
||
test('should return "open" if now is after opens and before closes', () => { | ||
const opens = '2024-11-20T00:00:00Z'; // Opened yesterday at midnight UTC | ||
const closes = '2024-11-22T00:00:00Z'; // Closes tomorrow at midnight UTC | ||
expect(getStateFromDates(opens, closes)).toBe('open'); | ||
const opens = "2024-11-20T00:00:00Z"; // Opened yesterday at midnight UTC | ||
const closes = "2024-11-22T00:00:00Z"; // Closes tomorrow at midnight UTC | ||
expect(getStateFromDates(opens, closes)).toBe("open"); | ||
}); | ||
|
||
test('should return "closed" if now is after closes', () => { | ||
const opens = '2024-11-19T00:00:00Z'; // Opened two days ago at midnight UTC | ||
const closes = '2024-11-20T23:59:59Z'; // Closed yesterday at 11:59:59 PM UTC | ||
expect(getStateFromDates(opens, closes)).toBe('closed'); | ||
const opens = "2024-11-19T00:00:00Z"; // Opened two days ago at midnight UTC | ||
const closes = "2024-11-20T23:59:59Z"; // Closed yesterday at 11:59:59 PM UTC | ||
expect(getStateFromDates(opens, closes)).toBe("closed"); | ||
}); | ||
|
||
test('should handle cases with only opens defined', () => { | ||
const opens = '2024-11-20T00:00:00Z'; // Opened yesterday at midnight UTC | ||
expect(getStateFromDates(opens, null)).toBe('open'); | ||
test("should handle cases with only opens defined", () => { | ||
const opens = "2024-11-20T00:00:00Z"; // Opened yesterday at midnight UTC | ||
expect(getStateFromDates(opens, null)).toBe("open"); | ||
}); | ||
|
||
test('should handle cases with only closes defined', () => { | ||
const closes = '2024-11-22T00:00:00Z'; // Closes tomorrow at midnight UTC | ||
expect(getStateFromDates(null, closes)).toBe('unknown'); // No opens means "unknown" | ||
test("should handle cases with only closes defined", () => { | ||
const closes = "2024-11-22T00:00:00Z"; // Closes tomorrow at midnight UTC | ||
expect(getStateFromDates(null, closes)).toBe("unknown"); // No opens means "unknown" | ||
}); | ||
|
||
test('should handle edge cases for opens and closes on the same day', () => { | ||
const opens = '2024-11-21T00:00:00Z'; // Opens today at midnight UTC | ||
const closes = '2024-11-21T23:59:59Z'; // Closes today at 11:59:59 PM UTC | ||
expect(getStateFromDates(opens, closes)).toBe('open'); // Current time is 7 AM ET | ||
test("should handle edge cases for opens and closes on the same day", () => { | ||
const opens = "2024-11-21T00:00:00Z"; // Opens today at midnight UTC | ||
const closes = "2024-11-21T23:59:59Z"; // Closes today at 11:59:59 PM UTC | ||
expect(getStateFromDates(opens, closes)).toBe("open"); // Current time is 7 AM ET | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,28 @@ | ||
const { minNumber } = require('../js/global'); | ||
const { minNumber } = require("../js/global"); | ||
|
||
describe('minNumber', () => { | ||
test('should return the smallest number from a list of numbers', () => { | ||
describe("minNumber", () => { | ||
test("should return the smallest number from a list of numbers", () => { | ||
const result = minNumber(5, 10, 3, 8, 2); | ||
expect(result).toBe(2); | ||
}); | ||
|
||
test('should return the only number when a single number is provided', () => { | ||
test("should return the only number when a single number is provided", () => { | ||
const result = minNumber(7); | ||
expect(result).toBe(7); | ||
}); | ||
|
||
test('should handle negative numbers correctly', () => { | ||
test("should handle negative numbers correctly", () => { | ||
const result = minNumber(-10, -5, -30, 0); | ||
expect(result).toBe(-30); | ||
}); | ||
|
||
test('should handle a mix of positive and negative numbers', () => { | ||
test("should handle a mix of positive and negative numbers", () => { | ||
const result = minNumber(15, -20, 35, 0, -5); | ||
expect(result).toBe(-20); | ||
}); | ||
|
||
test('should return NaN if any of the inputs are not numbers', () => { | ||
const result = minNumber(5, 'a', 10, {}, []); | ||
test("should return NaN if any of the inputs are not numbers", () => { | ||
const result = minNumber(5, "a", 10, {}, []); | ||
expect(result).toBeNaN(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,112 +1,112 @@ | ||
const { sortByProp } = require("../js/global"); | ||
|
||
describe('sortByProp', () => { | ||
test('should sort an array of objects by a numeric property (Data Analyst)', () => { | ||
describe("sortByProp", () => { | ||
test("should sort an array of objects by a numeric property (Data Analyst)", () => { | ||
const input = [ | ||
{ id: 3, name: 'Data Analyst' }, | ||
{ id: 1, name: 'Content Manager' }, | ||
{ id: 2, name: 'Web Developer' }, | ||
{ id: 3, name: "Data Analyst" }, | ||
{ id: 1, name: "Content Manager" }, | ||
{ id: 2, name: "Web Developer" }, | ||
]; | ||
|
||
const result = sortByProp(input, 'id'); | ||
const result = sortByProp(input, "id"); | ||
expect(result).toEqual([ | ||
{ id: 1, name: 'Content Manager' }, | ||
{ id: 2, name: 'Web Developer' }, | ||
{ id: 3, name: 'Data Analyst' }, | ||
{ id: 1, name: "Content Manager" }, | ||
{ id: 2, name: "Web Developer" }, | ||
{ id: 3, name: "Data Analyst" }, | ||
]); | ||
}); | ||
|
||
test('should sort an array of objects by a string property alphabetically (Content Manager)', () => { | ||
test("should sort an array of objects by a string property alphabetically (Content Manager)", () => { | ||
const input = [ | ||
{ id: 1, name: 'Data Analyst' }, | ||
{ id: 2, name: 'Content Manager' }, | ||
{ id: 3, name: 'Web Developer' }, | ||
{ id: 1, name: "Data Analyst" }, | ||
{ id: 2, name: "Content Manager" }, | ||
{ id: 3, name: "Web Developer" }, | ||
]; | ||
|
||
const result = sortByProp(input, 'name'); | ||
const result = sortByProp(input, "name"); | ||
expect(result).toEqual([ | ||
{ id: 2, name: 'Content Manager' }, | ||
{ id: 1, name: 'Data Analyst' }, | ||
{ id: 3, name: 'Web Developer' }, | ||
{ id: 2, name: "Content Manager" }, | ||
{ id: 1, name: "Data Analyst" }, | ||
{ id: 3, name: "Web Developer" }, | ||
]); | ||
}); | ||
|
||
test('should handle mixed data types (Web Developer)', () => { | ||
test("should handle mixed data types (Web Developer)", () => { | ||
const input = [ | ||
{ id: 3, name: 'Web Developer' }, | ||
{ id: 2, name: 'Data Analyst' }, | ||
{ id: 1, name: 'Content Manager' }, | ||
{ id: 3, name: "Web Developer" }, | ||
{ id: 2, name: "Data Analyst" }, | ||
{ id: 1, name: "Content Manager" }, | ||
]; | ||
|
||
const result = sortByProp(input, 'id'); | ||
const result = sortByProp(input, "id"); | ||
expect(result).toEqual([ | ||
{ id: 1, name: 'Content Manager' }, | ||
{ id: 2, name: 'Data Analyst' }, | ||
{ id: 3, name: 'Web Developer' }, | ||
{ id: 1, name: "Content Manager" }, | ||
{ id: 2, name: "Data Analyst" }, | ||
{ id: 3, name: "Web Developer" }, | ||
]); | ||
}); | ||
|
||
test('should handle an empty array', () => { | ||
test("should handle an empty array", () => { | ||
const input = []; | ||
const result = sortByProp(input, 'id'); | ||
const result = sortByProp(input, "id"); | ||
expect(result).toEqual([]); | ||
}); | ||
|
||
test('should return a new array without modifying the original array', () => { | ||
test("should return a new array without modifying the original array", () => { | ||
const input = [ | ||
{ id: 2, name: 'Web Developer' }, | ||
{ id: 1, name: 'Content Manager' }, | ||
{ id: 2, name: "Web Developer" }, | ||
{ id: 1, name: "Content Manager" }, | ||
]; | ||
|
||
const result = sortByProp(input, 'id'); | ||
const result = sortByProp(input, "id"); | ||
expect(result).toEqual([ | ||
{ id: 1, name: 'Content Manager' }, | ||
{ id: 2, name: 'Web Developer' }, | ||
{ id: 1, name: "Content Manager" }, | ||
{ id: 2, name: "Web Developer" }, | ||
]); | ||
|
||
expect(input).toEqual([ | ||
{ id: 2, name: 'Web Developer' }, | ||
{ id: 1, name: 'Content Manager' }, | ||
{ id: 2, name: "Web Developer" }, | ||
{ id: 1, name: "Content Manager" }, | ||
]); // Ensure original array is unchanged | ||
}); | ||
|
||
test('should handle properties that do not exist on all objects', () => { | ||
test("should handle properties that do not exist on all objects", () => { | ||
const input = [ | ||
{ id: 3, name: 'Data Analyst' }, | ||
{ id: 3, name: "Data Analyst" }, | ||
{ id: 1 }, | ||
{ id: 2, name: 'Web Developer' }, | ||
{ id: 2, name: "Web Developer" }, | ||
]; | ||
|
||
const result = sortByProp(input, 'name'); | ||
const result = sortByProp(input, "name"); | ||
expect(result).toEqual([ | ||
{ id: 3, name: 'Data Analyst' }, | ||
{ id: 2, name: 'Web Developer' }, | ||
{ id: 3, name: "Data Analyst" }, | ||
{ id: 2, name: "Web Developer" }, | ||
{ id: 1 }, // Objects without the property should stay at their original position | ||
]); | ||
}); | ||
|
||
test('should handle an array with non-object elements gracefully', () => { | ||
test("should handle an array with non-object elements gracefully", () => { | ||
const input = [ | ||
{ id: 1, name: 'Content Manager' }, | ||
'randomString', | ||
{ id: 2, name: 'Web Developer' }, | ||
{ id: 1, name: "Content Manager" }, | ||
"randomString", | ||
{ id: 2, name: "Web Developer" }, | ||
]; | ||
|
||
expect(() => sortByProp(input, 'id')).toThrow(); | ||
expect(() => sortByProp(input, "id")).toThrow(); | ||
}); | ||
|
||
test('should handle sorting with numeric strings correctly', () => { | ||
test("should handle sorting with numeric strings correctly", () => { | ||
const input = [ | ||
{ id: '3', name: 'Web Developer' }, | ||
{ id: '2', name: 'Data Analyst' }, | ||
{ id: '1', name: 'Content Manager' }, | ||
{ id: "3", name: "Web Developer" }, | ||
{ id: "2", name: "Data Analyst" }, | ||
{ id: "1", name: "Content Manager" }, | ||
]; | ||
|
||
const result = sortByProp(input, 'id'); | ||
const result = sortByProp(input, "id"); | ||
expect(result).toEqual([ | ||
{ id: '1', name: 'Content Manager' }, | ||
{ id: '2', name: 'Data Analyst' }, | ||
{ id: '3', name: 'Web Developer' }, | ||
{ id: "1", name: "Content Manager" }, | ||
{ id: "2", name: "Data Analyst" }, | ||
{ id: "3", name: "Web Developer" }, | ||
]); | ||
}); | ||
}); |
Oops, something went wrong.