Skip to content
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

Shayan/checking auth failing issue + fixed test failing issue #129

Merged
merged 7 commits into from
Jun 14, 2024
Merged
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
14 changes: 14 additions & 0 deletions src/components/AppFooter/__tests__/AppFooter.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ import AppFooter from '../AppFooter';
jest.mock('@deriv-com/translations');
jest.mock('@/hooks');

Object.defineProperty(window, 'matchMedia', {
value: jest.fn().mockImplementation(query => ({
addEventListener: jest.fn(),
addListener: jest.fn(), // Deprecated
dispatchEvent: jest.fn(),
matches: false,
media: query,
onchange: null,
removeEventListener: jest.fn(),
removeListener: jest.fn(), // Deprecated
})),
writable: true,
});

const AppFooterComponent = () => (
<BrowserRouter>
<QueryParamProvider adapter={ReactRouter5Adapter}>
Expand Down
14 changes: 14 additions & 0 deletions src/components/AppFooter/__tests__/ServerTime.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ jest.mock('@/utils', () => ({
epochToUTC: jest.fn(),
}));

Object.defineProperty(window, 'matchMedia', {
value: jest.fn().mockImplementation(query => ({
addEventListener: jest.fn(),
addListener: jest.fn(), // Deprecated
dispatchEvent: jest.fn(),
matches: false,
media: query,
onchange: null,
removeEventListener: jest.fn(),
removeListener: jest.fn(), // Deprecated
})),
writable: true,
});

describe('ServerTime component', () => {
const mockTime = 1625074800; // Example epoch time
const mockUTCFormat = '2021-06-30 14:00 GMT';
Expand Down
19 changes: 17 additions & 2 deletions src/components/AppHeader/__tests__/AppHeader.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { ReactNode } from 'react';
import { BrowserRouter } from 'react-router-dom';
import { QueryParamProvider } from 'use-query-params';
import { ReactRouter5Adapter } from 'use-query-params/adapters/react-router-5';
import { useAuthData } from '@deriv-com/api-hooks';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
Expand Down Expand Up @@ -81,7 +84,13 @@ describe('<AppHeader/>', () => {
});

it('should render the header and handle login when there are no P2P accounts', async () => {
render(<AppHeader />);
render(
<BrowserRouter>
<QueryParamProvider adapter={ReactRouter5Adapter}>
<AppHeader />
</QueryParamProvider>
</BrowserRouter>
);
await userEvent.click(screen.getByRole('button', { name: 'Log in' }));

expect(window.open).toHaveBeenCalledWith(expect.any(String), '_self');
Expand All @@ -104,7 +113,13 @@ describe('<AppHeader/>', () => {
writable: true,
});

render(<AppHeader />);
render(
<BrowserRouter>
<QueryParamProvider adapter={ReactRouter5Adapter}>
<AppHeader />
</QueryParamProvider>
</BrowserRouter>
);
const logoutButton = screen.getByRole('button', { name: 'Logout' });
const { logout } = mockUseAuthData();
expect(logoutButton).toBeInTheDocument();
Expand Down
14 changes: 1 addition & 13 deletions src/components/DerivIframe/DerivIframe.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
import { URLConstants } from '@deriv-com/utils';

const DerivIframe = () => {
const getAllowedLocalStorageOrigin = () => {
const hostName = window.location.hostname;
if (/^staging-p2p\.deriv\.com$/i.test(hostName)) {
return URLConstants.derivP2pStaging;
} else if (/^localhost$/i.test(hostName)) {
return window.location.origin;
}
return URLConstants.derivP2pProduction;
};

const origin = getAllowedLocalStorageOrigin();
const origin = window.location.origin;

return (
<iframe
Expand Down
Loading