8000 Mspyx 578 Add VC IDR Link to Toast Message by vincentiussundjaja Β· Pull Request #267 Β· uncefact/tests-untp Β· GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Mspyx 578 Add VC IDR Link to Toast Message #267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions packages/components/src/components/ToastMessage/ToastMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,29 @@
};

// The function for displaying toast messages
export function toastMessage({ status, message }: {
export function toastMessage({ status, message, linkURL }: {
status: Status;
message: string;
linkURL?: string;
}): void {
toast[status](message, {
toast[status](
<div style={{display: 'flex', flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between'}}>
<div>
{message}
</div>
{linkURL && <a style={{fontSize: '12px'}} href={linkURL} target="_blank">Open VC</a> }

Check warning on line 23 in packages/components/src/components/ToastMessage/ToastMessage.tsx

View workflow job for this annotation

GitHub Actions / test_and_build

Using target="_blank" without rel="noreferrer" (which implies rel="noopener") is a security risk in older browsers: see https://mathiasbynens.github.io/rel-noopener/#recommendations
</div>,
{
position: 'top-right',
hideProgressBar: true,
closeOnClick: true,
// closeOnClick: true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// closeOnClick: true,

pauseOnHover: true,
draggable: true,
autoClose: 3000,
autoClose: 4000,
});
}

// ToastMessage component for displaying a ToastContainer
export const ToastMessage = () => {
return <ToastContainer />;
};
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also add e2e tests?

Original file line number Diff line number Diff line change
@@ -1,22 +1,78 @@
import React from 'react';
import { render, waitFor } from '@testing-library/react';
import { render, waitFor, screen } from '@testing-library/react';
import '@testing-library/jest-dom';

import { ToastMessage, toastMessage, Status } from '../../../components/ToastMessage/ToastMessage';

describe('Toast Message', () => {
test('renders ToastMessage component and triggers toast', async () => {
const status = Status.success;
const message = 'Test message';
const linkURL = '';

// Render the component
render(<ToastMessage />);

// Call the toastMessage function
toastMessage({ status, message });
toastMessage({ status, message, linkURL });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add unit tests to verify the functionality (i.e., does the link appear when a URL is provided, and does it not appear when no URL is provided)?


// Check that the toast message is correctly.
await waitFor(() => {
expect(document.body).toHaveTextContent(message);
});
});

test('renders ToastMessage with a link when linkURL is provided', async () => {
const status = Status.info;
const message = 'Linked toast';
const linkURL = 'https://example.com/vc/456';

render(<ToastMessage />);

toastMessage({ status, message, linkURL });

await waitFor(() => {
expect(screen.getByText(message)).toBeInTheDocument();
});

const link = screen.getByText('Open VC');
expect(link).toBeInTheDocument();
expect(link).toHaveAttribute('href', linkURL);
expect(link).toHaveAttribute('target', '_blank');
});

test('does not render link when linkURL is not provided', async () => {
const status = Status.info;
const message = 'No link toast';

render(<ToastMessage />);
toastMessage({ status, message });

await waitFor(() => {
expect(screen.getByText(message)).toBeInTheDocument();
});

// Ensure "Open VC" link is not present
expect(screen.queryByText('Open VC')).not.toBeInTheDocument();
});

test('toast disappears after autoClose duration', async () => {
jest.useFakeTimers();
const message = 'Temporary toast';

render(<ToastMessage />);
toastMessage({ status: Status.warning, message });

await waitFor(() => {
expect(screen.getByText(message)).toBeInTheDocument();
});

jest.advanceTimersByTime(4000);

await waitFor(() => {
expect(screen.queryByText(message)).not.toBeInTheDocument();
});

jest.useRealTimers();
});
});
41 changes: 28 additions & 13 deletions packages/mock-app/src/components/GenericFeature/GenericFeature.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,28 @@ export const GenericFeature: React.FC<IGenericFeatureProps> = ({ components, ser
const [result, setResult] = React.useState<any>();
const props: Record<string, any> = {};

const executeServices = async (services: IServiceDefinition[], parameters: any[]) => {
const [result] = await services.reduce(async (previousResult: any[] | Promise<any[]>, currentService) => {
const prevResult = await previousResult;
const service: any = getService(currentService.name);
const params = [...prevResult, ...currentService.parameters];
const result: any = await service(...params);
return [result];
}, parameters);
return result;
const executeServices = async (
services: IServiceDefinition[],
parameters: any[]
): Promise<[any, any[]]> => {
const allResults = await services.reduce(async (previousResult: any[] | Promise<any[]>, currentService) => {
const prevResults = await previousResult;
const service: any = getService(currentService.name);

const lastResult = prevResults[prevResults.length - 1];
const inputParams = prevResults.length > 0
? [lastResult, ...currentService.parameters]
: [...parameters, ...currentService.parameters];

const result = await service(...inputParams);

return [...prevResults, result];
},
Promise.resolve([]) // Start with an empty result list
);

const finalResult = allResults[allResults.length - 1];
return [finalResult, allResults];
};

return (
Expand All @@ -150,11 +163,13 @@ export const GenericFeature: React.FC<IGenericFeatureProps> = ({ components, ser
case ComponentType.Submit:
props. (handler: (args: any) => void) => {
try {
const result = await executeServices(services, state);
const [finalResult, allResults] = await executeServices(services, state);

handler(finalResult);
setResult(finalResult);

handler(result);
setResult(result);
toastMessage({ status: Status.success, message: 'Action Successful' });
const resultWithLinkResolver = result?.linkResolver ?? allResults.find((item: any) => item?.linkResolver !== undefined);
toastMessage({ status: Status.success, message: 'Action Successful.', linkURL: resultWithLinkResolver?.linkResolver });
} catch (error: any) {
console.log(error.message);
toastMessage({ status: Status.error, message: 'Something went wrong' });
Expand Down
Loading
0