Skip to content

Commit

Permalink
chore: fix pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Noggling committed Nov 6, 2023
1 parent 4845634 commit 30646d5
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 20 deletions.
6 changes: 4 additions & 2 deletions client/packages/components/package.json
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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const ProfileListItem = ({ href, title, text, icon, toCopy }: ProfileList
</Styles.LinkContent>
<Button
aria-label="copy_content"
title=""
title={`Copy ${toCopy}`}
variant="ghost_icon"
onClick={async (e) => {
e.preventDefault();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Switch } from '@equinor/eds-core-react';
import { arrow_back } from '@equinor/eds-icons';
import { tokens } from '@equinor/eds-tokens';
import { useUpdateMyRoles } from './hooks/use-update-my-roles-query';
import { expiresIn } from './utils/expires-in';

export const Style = {
Wrapper: styled.div`
Expand Down Expand Up @@ -44,19 +45,6 @@ export const Style = {
`,
};

const expiresIn = (activeTo: string) => {
const activeToDate = new Date(activeTo).getTime();
const now = new Date().getTime();

if (now > activeToDate) {
return 'Expired';
}

const millisecondsInAnHour = 36e5;

return `Expires in ${Math.ceil(Math.abs(activeToDate - now) / millisecondsInAnHour)} hours`;
};

export const MyRolesTab = ({ onClick, user }: { onClick: VoidFunction; user?: PersonDetails }) => {
const { roles, mutate } = useUpdateMyRoles(user?.roles);

Expand Down
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');
});
});
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`;
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { storage } from 'packages/utils/src';
import { storage } from '@portal/utils';
import { createContext, PropsWithChildren, useState } from 'react';
import { useAppGroupsQuery } from '../../queries';
import { IMenuContext, IMenuState } from './menu-types';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Icon } from '@equinor/eds-core-react';
import { tokens } from '@equinor/eds-tokens';
import { menuFavoritesController, useMenuContext, useTelemetry } from '@equinor/portal-core';
import { useObservable } from 'packages/utils/src';
import { useObservable } from '@portal/utils';
import { Link } from 'react-router-dom';
import { map } from 'rxjs';
import styled from 'styled-components';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AppGroup } from '@equinor/portal-core';
import { InfoMessage } from '../../info-message/InfoMessage';
import { Group } from '../group/Group';
import { styles } from '../styles';
import { getColumnCount } from 'packages/utils/src';
import { getColumnCount } from '@portal/utils';

type GroupWrapperProps = {
appGroups: AppGroup[];
Expand Down
2 changes: 1 addition & 1 deletion client/packages/portal-ui/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
},
"files": [],

"include": ["**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx", "**/*.d.ts", "src/mock", "../components/src/components/presence-indicator/index.ts"]
"include": ["**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx", "**/*.d.ts", "src/mock"]
}

0 comments on commit 30646d5

Please sign in to comment.