fix: refresh token no handler attached error (#11234)

* fix: refresh token no handler attached error

* fix: explore component tab flicker

* fix: revert trySilentSignIn changes

* fix: throw error if renew promise not available

* fix: add unit tests for glossary version component
This commit is contained in:
karanh37 2023-04-26 18:53:20 +05:30 committed by GitHub
parent 4603fbc91c
commit dfcd7c7029
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 104 additions and 10 deletions

View File

@ -151,12 +151,12 @@ const Explore: React.FC<ExploreProps> = ({
})
);
return !loading && searchQueryParam
return searchQueryParam
? items.filter((tabItem) => {
return tabItem.count > 0 || tabItem.key === searchCriteria;
})
: items;
}, [tab, loading, tabsInfo, tabCounts]);
}, [tab, tabsInfo, tabCounts]);
const activeTabKey = useMemo(() => {
if (tab) {
@ -423,7 +423,7 @@ const Explore: React.FC<ExploreProps> = ({
</Row>
</>
)}
{searchQueryParam && tabItems.length === 0 && (
{searchQueryParam && tabItems.length === 0 && !loading && (
<Space
align="center"
className="w-full h-full flex-center"
@ -436,6 +436,7 @@ const Explore: React.FC<ExploreProps> = ({
/>
</Space>
)}
{searchQueryParam && tabItems.length === 0 && loading && <Loader />}
</PageLayoutV1>
);
};

View File

@ -0,0 +1,92 @@
/*
* Copyright 2023 Collate.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { render, screen } from '@testing-library/react';
import React from 'react';
import { MemoryRouter, Route } from 'react-router-dom';
import GlossaryVersion from './GlossaryVersion.component';
/* eslint-disable max-len */
const MOCK_VERSIONS_LIST = {
entityType: 'glossary',
versions: [
'{"id":"305b0130-b9c1-4441-a0fc-6463fd019540","name":"Business_Glossary","fullyQualifiedName":"Business_Glossary","displayName":"Business Glossary","description":"Business Glossary","version":0.1,"updatedAt":1681762798036,"updatedBy":"suresh","reviewers":[],"owner":{"id":"eeca9594-abd5-4dde-bc38-8b411e821087","type":"user","name":"suresh","fullyQualifiedName":"suresh","displayName":"Suresh Srinivas","deleted":false},"tags":[],"deleted":false,"provider":"user","mutuallyExclusive":false}',
],
};
const MOCK_VERSION = {
id: '305b0130-b9c1-4441-a0fc-6463fd019540',
name: 'Business_Glossary',
fullyQualifiedName: 'Business_Glossary',
displayName: 'Business Glossary',
description: 'Business Glossary',
version: 0.1,
updatedAt: 1681762798036,
updatedBy: 'suresh',
reviewers: [],
owner: {
id: 'eeca9594-abd5-4dde-bc38-8b411e821087',
type: 'user',
name: 'suresh',
fullyQualifiedName: 'suresh',
displayName: 'Suresh Srinivas',
deleted: false,
},
tags: [],
deleted: false,
provider: 'user',
mutuallyExclusive: false,
};
jest.mock('rest/glossaryAPI', () => ({
getGlossaryVersionsList: jest
.fn()
.mockImplementation(() => Promise.resolve(MOCK_VERSIONS_LIST)),
getGlossaryVersion: jest
.fn()
.mockImplementation(() => Promise.resolve(MOCK_VERSION)),
}));
jest.mock('components/Glossary/GlossaryV1.component', () => {
return jest.fn().mockReturnValue(<>Glossary component</>);
});
describe('GlossaryVersion', () => {
beforeEach(() => {
jest.clearAllMocks();
});
it('renders glossary version', async () => {
const glossaryName = '305b0130-b9c1-4441-a0fc-6463fd019540';
const version = '0.1';
render(
<MemoryRouter
initialEntries={[`/glossary/${glossaryName}/versions/${version}`]}>
<Route path="/glossary/:glossaryName/versions/:version">
<GlossaryVersion isGlossary />
</Route>
</MemoryRouter>
);
// Check that the version data is displayed
expect(await screen.findByText('Glossary component')).toBeInTheDocument();
// Check that the version timeline is displayed
expect(
screen.getByText('label.version-plural-history')
).toBeInTheDocument();
// check active version visible
expect(screen.getByText('v0.1')).toBeInTheDocument();
});
});

View File

@ -120,7 +120,6 @@ export const AuthProvider = ({
>([]);
let silentSignInRetries = 0;
const handleUserCreated = (isUser: boolean) => setIsUserCreated(isUser);
const onLoginHandler = () => {
@ -254,14 +253,16 @@ export const AuthProvider = ({
* This method will be called when the id token is about to expire.
*/
const renewIdToken = async () => {
const onRenewIdTokenHandlerPromise = onRenewIdTokenHandler();
if (onRenewIdTokenHandlerPromise) {
await onRenewIdTokenHandlerPromise;
try {
const onRenewIdTokenHandlerPromise = onRenewIdTokenHandler();
onRenewIdTokenHandlerPromise && (await onRenewIdTokenHandlerPromise);
} catch (error) {
console.error((error as AxiosError).message);
return localState.getOidcToken();
} else {
throw new Error('No handler attached for Renew Token.');
throw error;
}
return localState.getOidcToken();
};
/**