5663 i should be able to accept an invite even if i have an inactive workspace (#5839)

- make invitation and reset password available on every page
- add a sleep after setKeyPair as tokens are sometimes not updated when
redirecting to Index
- refactor sleep
This commit is contained in:
martmull
2024-06-13 11:47:00 +02:00
committed by GitHub
parent d93c2d6408
commit b26fd00a40
30 changed files with 95 additions and 75 deletions

View File

@ -19,7 +19,7 @@ import {
mockDefaultWorkspace,
mockedWorkspaceMemberData,
} from '~/testing/mock-data/users';
import { sleep } from '~/testing/sleep';
import { sleep } from '~/utils/sleep';
import { CommandMenu } from '../CommandMenu';

View File

@ -6,24 +6,10 @@ import {
displayedExportProgress,
download,
generateCsv,
sleep,
} from '../useExportTableData';
jest.useFakeTimers();
describe('sleep', () => {
it('waits the provided number of milliseconds', async () => {
const spy = jest.fn();
sleep(1000).then(spy);
jest.advanceTimersByTime(999);
expect(spy).not.toHaveBeenCalled();
jest.advanceTimersByTime(1);
await Promise.resolve(); // let queued promises execute
expect(spy).toHaveBeenCalledTimes(1);
});
});
describe('download', () => {
it('creates a download link and clicks it', () => {
const link = document.createElement('a');

View File

@ -8,12 +8,10 @@ import { useRecordTableStates } from '@/object-record/record-table/hooks/interna
import { ColumnDefinition } from '@/object-record/record-table/types/ColumnDefinition';
import { isDefined } from '~/utils/isDefined';
import { isUndefinedOrNull } from '~/utils/isUndefinedOrNull';
import { sleep } from '~/utils/sleep';
import { useFindManyParams } from '../../hooks/useLoadRecordIndexTable';
export const sleep = (ms: number) =>
new Promise((resolve) => setTimeout(resolve, ms));
export const download = (blob: Blob, filename: string) => {
const url = URL.createObjectURL(blob);
const link = document.createElement('a');

View File

@ -9,7 +9,7 @@ import { RelationPickerDecorator } from '~/testing/decorators/RelationPickerDeco
import { SnackBarDecorator } from '~/testing/decorators/SnackBarDecorator';
import { graphqlMocks } from '~/testing/graphqlMocks';
import { getPeopleMock } from '~/testing/mock-data/people';
import { sleep } from '~/testing/sleep';
import { sleep } from '~/utils/sleep';
import { EntityForSelect } from '../../types/EntityForSelect';
import { SingleEntitySelect } from '../SingleEntitySelect';

View File

@ -1,5 +1,6 @@
import { defaultSpreadsheetImportProps } from '@/spreadsheet-import/provider/components/SpreadsheetImport';
import { Fields, SpreadsheetOptions } from '@/spreadsheet-import/types';
import { sleep } from '~/utils/sleep';
const fields = [
{
@ -102,22 +103,16 @@ export const mockRsiValues = mockComponentBehaviourForTypes({
return;
},
uploadStepHook: async (data) => {
await new Promise((resolve) => {
setTimeout(() => resolve(data), 4000);
});
await sleep(4000, (resolve) => resolve(data));
return data;
},
selectHeaderStepHook: async (hData, data) => {
await new Promise((resolve) => {
setTimeout(
() =>
resolve({
headerValues: hData,
data,
}),
4000,
);
});
await sleep(4000, (resolve) =>
resolve({
headerValues: hData,
data,
}),
);
return {
headerValues: hData,
data,
@ -125,9 +120,7 @@ export const mockRsiValues = mockComponentBehaviourForTypes({
},
// Runs after column matching and on entry change, more performant
matchColumnsStepHook: async (data) => {
await new Promise((resolve) => {
setTimeout(() => resolve(data), 4000);
});
await sleep(4000, (resolve) => resolve(data));
return data;
},
});

View File

@ -4,7 +4,7 @@ import { expect, userEvent, within } from '@storybook/test';
import { ComponentDecorator } from 'twenty-ui';
import { IconsProviderDecorator } from '~/testing/decorators/IconsProviderDecorator';
import { sleep } from '~/testing/sleep';
import { sleep } from '~/utils/sleep';
import { IconPicker, IconPickerProps } from '../IconPicker';

View File

@ -5,6 +5,7 @@ import { tokenPairState } from '@/auth/states/tokenPairState';
import { AppPath } from '@/types/AppPath';
import { useGenerateJwtMutation } from '~/generated/graphql';
import { isDefined } from '~/utils/isDefined';
import { sleep } from '~/utils/sleep';
export const useWorkspaceSwitching = () => {
const setTokenPair = useSetRecoilState(tokenPairState);
@ -29,6 +30,7 @@ export const useWorkspaceSwitching = () => {
const { tokens } = jwt.data.generateJWT;
setTokenPair(tokens);
await sleep(0); // This hacky workaround is necessary to ensure the tokens stored in the cookie are updated correctly.
window.location.href = AppPath.Index;
};