-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
9 changed files
with
66 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
{ | ||
"name": "portal-components", | ||
"name": "@portal/components", | ||
"version": "1.0.0", | ||
"license": "MIT", | ||
"scripts": { | ||
"build": "tsc" | ||
"build": "tsc", | ||
"test": "vitest --silent --run", | ||
"test:coverage": "vitest run --coverage" | ||
} | ||
} |
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
38 changes: 38 additions & 0 deletions
38
client/packages/components/src/components/my-roles-tab/utils/expires-in.test.ts
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Import the expiresIn function | ||
import { expiresIn } from './expires-in'; | ||
import { it, describe, expect } from 'vitest'; | ||
|
||
describe('expiresIn function', () => { | ||
it('should return "Expired" if the target date is in the past', () => { | ||
// Specify a past date | ||
const pastDate = '2023-01-01T00:00:00.000Z'; | ||
|
||
// Call the expiresIn function with the past date | ||
const result = expiresIn(pastDate); | ||
|
||
// Expect the result to be 'Expired' | ||
expect(result).toBe('Expired'); | ||
}); | ||
|
||
it('should return a string indicating the remaining time in hours if the target date is in the future', () => { | ||
// Specify a future date, e.g., 2 hours from now | ||
const futureDate = new Date(Date.now() + 2 * 3600000).toISOString(); | ||
|
||
// Call the expiresIn function with the future date | ||
const result = expiresIn(futureDate); | ||
|
||
// Expect the result to match the expected format, e.g., "Expires in 2 hours" | ||
expect(result).toMatch(/^Expires in \d+ hours$/); | ||
}); | ||
|
||
it('should handle invalid date input and return "Expired"', () => { | ||
// Provide an invalid date format | ||
const invalidDate = 'invalid-date-format'; | ||
|
||
// Call the expiresIn function with the invalid date | ||
const result = expiresIn(invalidDate); | ||
|
||
// Expect the result to be 'Expired' | ||
expect(result).toBe('Expired'); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
client/packages/components/src/components/my-roles-tab/utils/expires-in.ts
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Calculates the time remaining until a specified date and returns a human-readable string. | ||
* | ||
* @param activeTo - A string representing the target expiration date in a valid date format. | ||
* @returns A string indicating the remaining time until the specified date. | ||
*/ | ||
export const expiresIn = (activeTo: string) => { | ||
const activeToDate = new Date(activeTo).getTime(); | ||
const now = new Date().getTime(); | ||
|
||
if (isNaN(activeToDate) || now > activeToDate) { | ||
return 'Expired'; | ||
} | ||
|
||
const millisecondsInAnHour = 36e5; | ||
|
||
return `Expires in ${Math.ceil(Math.abs(activeToDate - now) / millisecondsInAnHour)} hours`; | ||
}; |
2 changes: 1 addition & 1 deletion
2
client/packages/portal-core/src/providers/menu/MenuProvider.tsx
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
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