Skip to content
Open
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
13 changes: 5 additions & 8 deletions frontend/OWNERS
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
reviewers:
- cajieh
- jhadvig
- kyoto
- krishagarwal278
- Leo6Leo
- rhamilto
- sg00dwin
- spadgett
- TheRealJon
- cajieh
- Mylanos
approvers:
- christoph-jerolimov
- cajieh
- invincibleJai
- jhadvig
- kyoto
- logonoff
- rawagner
- rhamilto
- spadgett
- vikram-raj
- vojtechszocs
- logonoff
- Mylanos
2 changes: 0 additions & 2 deletions frontend/integration-tests/OWNERS
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
reviewers:
- sanketpathak
- the-anton
- yapei
approvers:
- jrichter1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { useLocation } from 'react-router-dom-v5-compat';
import { FC, useEffect } from 'react';
import { createPath, useLocation } from 'react-router-dom-v5-compat';
import { Perspective, PerspectiveContext } from '@console/dynamic-plugin-sdk';
import { usePerspectives } from '@console/shared/src';
import PerspectiveDetector from './PerspectiveDetector';
Expand All @@ -19,14 +19,14 @@ const getPerspectiveURLParam = (perspectives: Perspective[]) => {
return perspectiveParam && perspectiveIDs.includes(perspectiveParam) ? perspectiveParam : '';
};

const DetectPerspective: React.FC<DetectPerspectiveProps> = ({ children }) => {
const DetectPerspective: FC<DetectPerspectiveProps> = ({ children }) => {
const [activePerspective, setActivePerspective, loaded] = useValuesForPerspectiveContext();
const perspectiveExtensions = usePerspectives();
const perspectiveParam = getPerspectiveURLParam(perspectiveExtensions);
const location = useLocation();
React.useEffect(() => {
useEffect(() => {
if (perspectiveParam && perspectiveParam !== activePerspective) {
setActivePerspective(perspectiveParam, location.pathname);
setActivePerspective(perspectiveParam, createPath(location));
}
}, [perspectiveParam, activePerspective, setActivePerspective, location]);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { useLocation } from 'react-router';
import { FC, useEffect, useState } from 'react';
import { useLocation, createPath } from 'react-router-dom-v5-compat';
import { Perspective, ResolvedExtension } from '@console/dynamic-plugin-sdk';
import { usePerspectives } from '@console/shared/src';

Expand All @@ -16,12 +16,12 @@ type PerspectiveDetectorProps = {
setActivePerspective: (perspective: string, next: string) => void;
};

const Detector: React.FC<DetectorProps> = ({
const Detector: FC<DetectorProps> = ({
setActivePerspective,
perspectiveExtensions,
detectors,
}) => {
const { pathname } = useLocation() ?? {};
const location = useLocation();
let detectedPerspective: string | undefined;
const defaultPerspective =
perspectiveExtensions.find((p) => p.properties.default) || perspectiveExtensions[0];
Expand All @@ -38,31 +38,31 @@ const Detector: React.FC<DetectorProps> = ({
return true;
});

React.useEffect(() => {
useEffect(() => {
if (detectedPerspective) {
setActivePerspective(detectedPerspective, pathname);
setActivePerspective(detectedPerspective, createPath(location));
} else if (defaultPerspective && (detectors.length < 1 || detectionComplete)) {
// set default perspective if there are no detectors or none of the detections were successfull
setActivePerspective(defaultPerspective.properties.id, pathname);
// set default perspective if there are no detectors or none of the detections were successful
setActivePerspective(defaultPerspective.properties.id, createPath(location));
}
}, [
defaultPerspective,
detectedPerspective,
detectionComplete,
detectors.length,
pathname,
location,
setActivePerspective,
]);

return null;
};

const PerspectiveDetector: React.FC<PerspectiveDetectorProps> = ({ setActivePerspective }) => {
const PerspectiveDetector: FC<PerspectiveDetectorProps> = ({ setActivePerspective }) => {
const perspectiveExtensions = usePerspectives();
const [detectors, setDetectors] = React.useState<
const [detectors, setDetectors] = useState<
(undefined | ResolvedExtension<Perspective>['properties']['usePerspectiveDetection'])[]
>();
React.useEffect(() => {
useEffect(() => {
let resolveCount = 0;
const resolvedDetectors: ResolvedExtension<
Perspective
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { mount } from 'enzyme';
import { act } from 'react-dom/test-utils';
import { render, waitFor } from '@testing-library/react';
import { useLocation } from 'react-router-dom-v5-compat';
import { Perspective } from '@console/dynamic-plugin-sdk';
import { LoadedExtension } from '@console/plugin-sdk';
import { usePerspectives } from '@console/shared/src';
Expand All @@ -13,12 +13,10 @@ jest.mock('@console/shared/src', () => ({
usePerspectives: jest.fn(),
}));

jest.mock('react-router', () => {
return {
...jest.requireActual('react-router'),
useLocation: jest.fn(() => ({ pathname: '' })),
};
});
jest.mock('react-router-dom-v5-compat', () => ({
...jest.requireActual('react-router-dom-v5-compat'),
useLocation: jest.fn(() => ({ pathname: '' })),
}));

const mockPerspectives = [
{
Expand All @@ -41,18 +39,24 @@ const mockPerspectives = [

const setActivePerspective = jest.fn();

const useLocationMock = useLocation as jest.Mock;

describe('PerspectiveDetector', () => {
it('should set default perspective if there are no perspective detectors available', async () => {
beforeEach(() => {
setActivePerspective.mockClear();
});

it('should set default perspective when there are no perspective detectors available', async () => {
(usePerspectives as jest.Mock).mockImplementation(() => mockPerspectives);

const wrapper = mount(<PerspectiveDetector setActivePerspective={setActivePerspective} />);
expect(wrapper.isEmptyRender()).toBe(true);
expect(setActivePerspective).toHaveBeenCalledWith('admin', '');
render(<PerspectiveDetector setActivePerspective={setActivePerspective} />);

await waitFor(() => {
expect(setActivePerspective).toHaveBeenCalledWith('admin', '');
});
});

it('should set detected perspective if detection is successful', async () => {
// create a promise and capture the resolver such that we can use act later on to ensure
// the test waits for this promise to resolve before continuing
it('should set detected perspective when detection is successful', async () => {
let promiseResolver: (value: () => [boolean, boolean]) => void;
const testPromise = new Promise<() => [boolean, boolean]>(
(resolver) => (promiseResolver = resolver),
Expand All @@ -61,17 +65,16 @@ describe('PerspectiveDetector', () => {

(usePerspectives as jest.Mock).mockImplementation(() => mockPerspectives);

const wrapper = mount(<PerspectiveDetector setActivePerspective={setActivePerspective} />);
await act(async () => {
promiseResolver(() => [true, false]);
render(<PerspectiveDetector setActivePerspective={setActivePerspective} />);

promiseResolver(() => [true, false]);

await waitFor(() => {
expect(setActivePerspective).toHaveBeenCalledWith('dev', '');
});
expect(wrapper.isEmptyRender()).toBe(true);
expect(setActivePerspective).toHaveBeenCalledWith('dev', '');
});

it('should set default perspective if detection fails', async () => {
// create a promise and capture the resolver such that we can use act later on to ensure
// the test waits for this promise to resolve before continuing
it('should set default perspective when detection fails', async () => {
let promiseResolver: (value: () => [boolean, boolean]) => void;
const testPromise = new Promise<() => [boolean, boolean]>(
(resolver) => (promiseResolver = resolver),
Expand All @@ -80,15 +83,16 @@ describe('PerspectiveDetector', () => {

(usePerspectives as jest.Mock).mockImplementation(() => mockPerspectives);

const wrapper = mount(<PerspectiveDetector setActivePerspective={setActivePerspective} />);
await act(async () => {
promiseResolver(() => [false, false]);
render(<PerspectiveDetector setActivePerspective={setActivePerspective} />);

promiseResolver(() => [false, false]);

await waitFor(() => {
expect(setActivePerspective).toHaveBeenCalledWith('admin', '');
});
expect(wrapper.isEmptyRender()).toBe(true);
expect(setActivePerspective).toHaveBeenCalledWith('admin', '');
});

it('should set admin as default perspective if all perspectives are disabled', async () => {
it('should set admin as default perspective when all perspectives are disabled', async () => {
const perspectives: PerspectiveType[] = [
{
id: 'dev',
Expand Down Expand Up @@ -118,8 +122,7 @@ describe('PerspectiveDetector', () => {
},
];
window.SERVER_FLAGS.perspectives = JSON.stringify(perspectives);
// create a promise and capture the resolver such that we can use act later on to ensure
// the test waits for this promise to resolve before continuing

let promiseResolver: (value: () => [boolean, boolean]) => void;
const testPromise = new Promise<() => [boolean, boolean]>(
(resolver) => (promiseResolver = resolver),
Expand All @@ -128,11 +131,35 @@ describe('PerspectiveDetector', () => {

(usePerspectives as jest.Mock).mockImplementation(() => mockPerspectives);

const wrapper = mount(<PerspectiveDetector setActivePerspective={setActivePerspective} />);
await act(async () => {
promiseResolver(() => [false, false]);
render(<PerspectiveDetector setActivePerspective={setActivePerspective} />);

promiseResolver(() => [false, false]);

await waitFor(() => {
expect(setActivePerspective).toHaveBeenCalledWith('admin', '');
});
});

it('preserves query and hash when setting perspective', async () => {
let promiseResolver: (value: () => [boolean, boolean]) => void;
const testPromise = new Promise<() => [boolean, boolean]>(
(resolver) => (promiseResolver = resolver),
);
mockPerspectives[1].properties.usePerspectiveDetection = () => testPromise;

(usePerspectives as jest.Mock).mockImplementation(() => mockPerspectives);
useLocationMock.mockImplementation(() => ({
pathname: '/some/path',
search: '?query=param',
hash: '#some-hash',
}));

render(<PerspectiveDetector setActivePerspective={setActivePerspective} />);

promiseResolver(() => [true, false]);

await waitFor(() => {
expect(setActivePerspective).toHaveBeenCalledWith('dev', '/some/path?query=param#some-hash');
});
expect(wrapper.isEmptyRender()).toBe(true);
expect(setActivePerspective).toHaveBeenCalledWith('admin', '');
});
});
4 changes: 0 additions & 4 deletions frontend/packages/console-telemetry-plugin/OWNERS
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
reviewers:
- christoph-jerolimov
- lokanandaprabhu
- vikram-raj
approvers:
- christoph-jerolimov
- debsmita1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
reviewers:
- sanketpathak
- the-anton
approvers:
- jrichter1
- psrna
Expand Down
4 changes: 0 additions & 4 deletions frontend/packages/dev-console/OWNERS
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
reviewers:
- jerolimov
- lokanandaprabhu
- vikram-raj
approvers:
- debsmita1
- divyanshiGupta
Expand Down
3 changes: 0 additions & 3 deletions frontend/packages/dev-console/integration-tests/OWNERS
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
reviewers:
- sanketpathak
- the-anton
approvers:
- jrichter1
- psrna
Expand Down
4 changes: 0 additions & 4 deletions frontend/packages/git-service/OWNERS
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
reviewers:
- jerolimov
- lokanandaprabhu
- vikram-raj
approvers:
- debsmita1
- divyanshiGupta
Expand Down
4 changes: 0 additions & 4 deletions frontend/packages/gitops-plugin/OWNERS
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
reviewers:
- christoph-jerolimov
- lokanandaprabhu
- vikram-raj
approvers:
- christoph-jerolimov
- debsmita1
Expand Down
3 changes: 0 additions & 3 deletions frontend/packages/gitops-plugin/integration-tests/OWNERS
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
reviewers:
- sanketpathak
- the-anton
approvers:
- jrichter1
- psrna
Expand Down
4 changes: 0 additions & 4 deletions frontend/packages/helm-plugin/OWNERS
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
reviewers:
- christoph-jerolimov
- lokanandaprabhu
- vikram-raj
approvers:
- christoph-jerolimov
- debsmita1
Expand Down
3 changes: 0 additions & 3 deletions frontend/packages/helm-plugin/integration-tests/OWNERS
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
reviewers:
- sanketpathak
- the-anton
approvers:
- jrichter1
- psrna
Expand Down
4 changes: 0 additions & 4 deletions frontend/packages/knative-plugin/OWNERS
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
reviewers:
- christoph-jerolimov
- lokanandaprabhu
- vikram-raj
approvers:
- christoph-jerolimov
- debsmita1
Expand Down
3 changes: 0 additions & 3 deletions frontend/packages/knative-plugin/integration-tests/OWNERS
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
reviewers:
- sanketpathak
- the-anton
approvers:
- jrichter1
- psrna
Expand Down
5 changes: 0 additions & 5 deletions frontend/packages/pipelines-plugin/OWNERS
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
reviewers:
- christoph-jerolimov
- karthikjeeyar
- lokanandaprabhu
- vikram-raj
approvers:
- christoph-jerolimov
- debsmita1
Expand Down
5 changes: 0 additions & 5 deletions frontend/packages/pipelines-plugin/integration-tests/OWNERS
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
reviewers:
- ppitonak
- sanketpathak
- VeereshAradhya
- the-anton
approvers:
- jrichter1
- psrna
Expand Down
4 changes: 0 additions & 4 deletions frontend/packages/shipwright-plugin/OWNERS
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
reviewers:
- christoph-jerolimov
- lokanandaprabhu
- vikram-raj
approvers:
- christoph-jerolimov
- debsmita1
Expand Down
3 changes: 0 additions & 3 deletions frontend/packages/shipwright-plugin/integration-tests/OWNERS
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
reviewers:
- sanketpathak
- the-anton
approvers:
- jrichter1
- psrna
Expand Down
Loading