LandingPage/ImagesTable/Wizard: Remove all insights global calls

This commit replaces all calls to the insights.chrome global with calls
to the useChrome() hook (or the useGetEnvironment() custom hook that
wraps useChrome()).
This commit is contained in:
lucasgarfield 2023-04-26 16:40:54 +02:00 committed by Lucas Garfield
parent ef1d077c2e
commit 7bca4c7438
10 changed files with 55 additions and 98 deletions

View file

@ -12,6 +12,17 @@ import { renderWithReduxRouter } from '../../testUtils';
jest.mock('@redhat-cloud-services/frontend-components/useChrome', () => ({
useChrome: () => ({
auth: {
getUser: () => {
return {
identity: {
internal: {
org_id: 5,
},
},
};
},
},
isBeta: () => true,
isProd: () => true,
getEnvironment: () => 'prod',
@ -41,33 +52,12 @@ describe('Step Upload to Azure', () => {
jest
.spyOn(api, 'getRepositories')
.mockImplementation(() => Promise.resolve(mockRepositoryResults));
global.insights = {
chrome: {
auth: {
getUser: () => {
return {
identity: {
internal: {
org_id: 5,
},
},
};
},
},
},
};
});
afterEach(() => {
jest.clearAllMocks();
});
// restore global mock
afterAll(() => {
global.insights = undefined;
});
const user = userEvent.setup();
const setUp = async () => {
renderWithReduxRouter('imagewizard', {});

View file

@ -32,6 +32,17 @@ const mockComposes = {
jest.mock('@redhat-cloud-services/frontend-components/useChrome', () => ({
useChrome: () => ({
auth: {
getUser: () => {
return {
identity: {
internal: {
org_id: 5,
},
},
};
},
},
isBeta: () => true,
isProd: () => true,
getEnvironment: () => 'prod',
@ -159,29 +170,9 @@ const searchForChosenPackages = async (searchbox, searchTerm) => {
}
};
// mock the insights dependency
beforeAll(() => {
// scrollTo is not defined in jsdom
window.HTMLElement.prototype.scrollTo = function () {};
global.insights = {
chrome: {
auth: {
getUser: () => {
return {
identity: {
internal: {
org_id: 5,
},
},
};
},
},
isProd: () => {
return true;
},
},
};
});
afterEach(() => {
@ -189,11 +180,6 @@ afterEach(() => {
router = undefined;
});
// restore global mock
afterAll(() => {
global.insights = undefined;
});
describe('Create Image Wizard', () => {
test('renders component', () => {
renderWithReduxRouter('imagewizard', {});

View file

@ -33,6 +33,17 @@ jest
jest.mock('@redhat-cloud-services/frontend-components/useChrome', () => ({
useChrome: () => ({
auth: {
getUser: () => {
return {
identity: {
internal: {
org_id: 5,
},
},
};
},
},
isBeta: () => false,
isProd: () => true,
getEnvironment: () => 'prod',
@ -124,35 +135,9 @@ const searchForChosenPackages = async (searchbox, searchTerm) => {
}
};
// mock the insights dependency
beforeAll(() => {
// scrollTo is not defined in jsdom
window.HTMLElement.prototype.scrollTo = function () {};
global.insights = {
chrome: {
auth: {
getUser: () => {
return {
identity: {
internal: {
org_id: 5,
},
},
};
},
},
isBeta: () => {
return false;
},
isProd: () => {
return true;
},
getEnvironment: () => {
return 'prod';
},
},
};
});
afterEach(() => {
@ -160,11 +145,6 @@ afterEach(() => {
router = undefined;
});
// restore global mock
afterAll(() => {
global.insights = undefined;
});
describe('Create Image Wizard', () => {
test('renders component', () => {
renderWithReduxRouter('imagewizard', {});