mirror of
https://github.com/SigNoz/signoz.git
synced 2025-12-23 10:26:40 +00:00
* feat: time picker hint and timezone picker UI with basic functionality + helper to get timezones * feat: add support for esc keypress to close the timezone picker * chore: add the selected timezone as url param and close timezone picker on select * fix: overall improvement + add searchIndex to timezone * feat: timezone preferences UI * chore: improve timezone utils * chore: change timezone item from div to button * feat: display timezone in timepicker input * chore: fix the typo * fix: don't focus on time picker when timezone is clicked * fix: fix the issue of timezone breaking for browser and utc timezones * fix: display the timezone in timepicker hint 'You are at' * feat: timezone basic functionality (#6492) * chore: change div to fragment + change type to any as the ESLint complains otherwise * chore: manage etc timezone filtering with an arg * chore: update timezone wrapper class name * fix: add timezone support to downloaded logs * feat: add current timezone to dashboard list and configure metadata modal * fix: add pencil icon next to timezone hint + change the copy to Current timezone * fix: properly handle the escape button behavior for timezone picker * chore: replace @vvo/tzdb with native Intl API for timezones * feat: lightmode for timezone picker and timezone adaptation components * fix: use normald tz in browser timezone * fix: timezone picker lightmode fixes * feat: display selected time range in 12 hour format * chore: remove unnecessary optional chaining * fix: fix the typo in css variable * chore: add em dash and change icon for timezone hint in date/time picker * chore: move pen line icon to the right of timezone offset * fix: fix the failing tests * feat: handle switching off the timezone adaptation
114 lines
2.6 KiB
TypeScript
114 lines
2.6 KiB
TypeScript
import { render, RenderOptions, RenderResult } from '@testing-library/react';
|
|
import ROUTES from 'constants/routes';
|
|
import { ResourceProvider } from 'hooks/useResourceAttribute';
|
|
import TimezoneProvider from 'providers/Timezone';
|
|
import React, { ReactElement } from 'react';
|
|
import { QueryClient, QueryClientProvider } from 'react-query';
|
|
import { Provider } from 'react-redux';
|
|
import { BrowserRouter } from 'react-router-dom';
|
|
import configureStore from 'redux-mock-store';
|
|
import store from 'store';
|
|
|
|
const queryClient = new QueryClient({
|
|
defaultOptions: {
|
|
queries: {
|
|
refetchOnWindowFocus: false,
|
|
},
|
|
},
|
|
});
|
|
|
|
beforeEach(() => {
|
|
jest.useFakeTimers();
|
|
jest.setSystemTime(new Date('2023-10-20'));
|
|
});
|
|
|
|
afterEach(() => {
|
|
queryClient.clear();
|
|
jest.useRealTimers();
|
|
});
|
|
|
|
const mockStore = configureStore([]);
|
|
|
|
const mockStored = (role?: string): any =>
|
|
mockStore({
|
|
...store.getState(),
|
|
app: {
|
|
...store.getState().app,
|
|
role, // Use the role provided
|
|
user: {
|
|
userId: '6f532456-8cc0-4514-a93b-aed665c32b47',
|
|
email: 'test@signoz.io',
|
|
name: 'TestUser',
|
|
profilePictureURL: '',
|
|
accessJwt: '',
|
|
refreshJwt: '',
|
|
},
|
|
isLoggedIn: true,
|
|
org: [
|
|
{
|
|
createdAt: 0,
|
|
hasOptedUpdates: false,
|
|
id: 'xyz',
|
|
isAnonymous: false,
|
|
name: 'Test Inc. - India',
|
|
},
|
|
],
|
|
},
|
|
});
|
|
|
|
jest.mock('react-i18next', () => ({
|
|
useTranslation: (): {
|
|
t: (str: string) => string;
|
|
i18n: {
|
|
changeLanguage: () => Promise<void>;
|
|
};
|
|
} => ({
|
|
t: (str: string): string => str,
|
|
i18n: {
|
|
changeLanguage: (): Promise<void> => new Promise(() => {}),
|
|
},
|
|
}),
|
|
}));
|
|
|
|
jest.mock('react-router-dom', () => ({
|
|
...jest.requireActual('react-router-dom'),
|
|
useLocation: (): { pathname: string } => ({
|
|
pathname: `${process.env.FRONTEND_API_ENDPOINT}/${ROUTES.TRACES_EXPLORER}/`,
|
|
}),
|
|
}));
|
|
|
|
function AllTheProviders({
|
|
children,
|
|
role, // Accept the role as a prop
|
|
}: {
|
|
children: React.ReactNode;
|
|
role: string; // Define the role prop
|
|
}): ReactElement {
|
|
return (
|
|
<ResourceProvider>
|
|
<QueryClientProvider client={queryClient}>
|
|
<Provider store={mockStored(role)}>
|
|
{' '}
|
|
{/* Use the mock store with the provided role */}
|
|
<BrowserRouter>
|
|
<TimezoneProvider>{children}</TimezoneProvider>
|
|
</BrowserRouter>
|
|
</Provider>
|
|
</QueryClientProvider>
|
|
</ResourceProvider>
|
|
);
|
|
}
|
|
|
|
const customRender = (
|
|
ui: ReactElement,
|
|
options?: Omit<RenderOptions, 'wrapper'>,
|
|
role = 'ADMIN', // Set a default role
|
|
): RenderResult =>
|
|
render(ui, {
|
|
wrapper: () => <AllTheProviders role={role}>{ui}</AllTheProviders>,
|
|
...options,
|
|
});
|
|
|
|
export * from '@testing-library/react';
|
|
export { customRender as render };
|