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
1 change: 0 additions & 1 deletion galasa-ui/messages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"title": "Experimentelle Funktionen",
"description": "Früher Zugriff auf neue Funktionen. Diese Funktionen sind experimentell und können sich ändern oder entfernt werden.",
"features": {
"testRunSearch": "Testlauf-Suche und Anzeige",
"graph": "Testlauf-Diagramm"
}
},
Expand Down
1 change: 0 additions & 1 deletion galasa-ui/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"title": "Experimental Features",
"description": "Early access to new features. These are experimental and subject to change or removal.",
"features": {
"testRunSearch": "Test Run searching and viewing",
"graph": "Test Run Graphs"
}
},
Expand Down
8 changes: 1 addition & 7 deletions galasa-ui/src/components/headers/PageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ import PageHeaderMenu from './PageHeaderMenu';
import Image from 'next/image';
import galasaLogo from '@/assets/images/galasaLogo.png';
import Link from 'next/link';
import { useFeatureFlags } from '@/contexts/FeatureFlagContext';
import { FEATURE_FLAGS } from '@/utils/featureFlags';
import { useTranslations } from 'next-intl';

export default function PageHeader({ galasaServiceName }: { galasaServiceName: string }) {
const { isFeatureEnabled } = useFeatureFlags();
const translations = useTranslations('PageHeader');
return (
<Theme theme="g90">
Expand All @@ -39,11 +36,8 @@ export default function PageHeader({ galasaServiceName }: { galasaServiceName: s

<HeaderNavigation aria-label="Galasa menu bar navigation">
<HeaderMenuItem href="/users">{translations('users')}</HeaderMenuItem>
{isFeatureEnabled(FEATURE_FLAGS.TEST_RUNS) && (
<HeaderMenuItem href="/test-runs">{translations('testRuns')}</HeaderMenuItem>
)}
<HeaderMenuItem href="/test-runs">{translations('testRuns')}</HeaderMenuItem>
</HeaderNavigation>

<PageHeaderMenu galasaServiceName={galasaServiceName} />
</Header>
</Theme>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ export default function ExperimentalFeaturesSection() {

// Feature configuration for easier management and display
const featureConfig = [
{
key: FEATURE_FLAGS.TEST_RUNS,
label: translations(`features.testRunSearch`),
},
{
key: FEATURE_FLAGS.GRAPH,
label: translations('features.graph'),
Expand Down
37 changes: 16 additions & 21 deletions galasa-ui/src/components/mysettings/ResultsTablePageSizeSetting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,30 @@ import { Dropdown } from '@carbon/react';
import { useTranslations } from 'next-intl';
import styles from '@/styles/mysettings/ResultsTablePageSizingSetting.module.css';
import useResultsTablePageSize from '@/hooks/useResultsTablePageSize';
import { useFeatureFlags } from '@/contexts/FeatureFlagContext';
import { FEATURE_FLAGS } from '@/utils/featureFlags';

export default function ResultsTablePageSizingSetting() {
const translations = useTranslations('ResultsTablePageSizingSetting');
const { isFeatureEnabled } = useFeatureFlags();
const { defaultPageSize, setDefaultPageSize } = useResultsTablePageSize();

return (
<>
{isFeatureEnabled(FEATURE_FLAGS.TEST_RUNS) && (
<section className={styles.section}>
<h3 className={styles.heading}>{translations('title')}</h3>
<div>
<p className={styles.title}>{translations('description')}</p>
<div className={styles.dropdownContainer}>
<p>{translations('defaultTestRunsLabel')}</p>
<Dropdown
data-testid="custom-items-per-page-dropdown-test"
items={RESULTS_TABLE_PAGE_SIZES}
itemToString={(item: number) => item.toString()}
selectedItem={defaultPageSize}
onChange={(e: { selectedItem: number }) => setDefaultPageSize(e.selectedItem)}
size="md"
/>
</div>
<section className={styles.section}>
<h3 className={styles.heading}>{translations('title')}</h3>
<div>
<p className={styles.title}>{translations('description')}</p>
<div className={styles.dropdownContainer}>
<p>{translations('defaultTestRunsLabel')}</p>
<Dropdown
data-testid="custom-items-per-page-dropdown-test"
items={RESULTS_TABLE_PAGE_SIZES}
itemToString={(item: number) => item.toString()}
selectedItem={defaultPageSize}
onChange={(e: { selectedItem: number }) => setDefaultPageSize(e.selectedItem)}
size="md"
/>
</div>
</section>
)}
</div>
</section>
</>
);
}
26 changes: 26 additions & 0 deletions galasa-ui/src/tests/__snapshots__/layout.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,19 @@ exports[`Layout renders the web UI layout 1`] = `
</span>
</a>
</li>
<li>
<a
class="cds--header__menu-item"
href="/test-runs"
tabindex="0"
>
<span
class="cds--text-truncate--end"
>
Test runs
</span>
</a>
</li>
</ul>
</nav>
<div
Expand Down Expand Up @@ -348,6 +361,19 @@ exports[`Layout renders the web UI layout 1`] = `
</span>
</a>
</li>
<li>
<a
class="cds--header__menu-item"
href="/test-runs"
tabindex="0"
>
<span
class="cds--text-truncate--end"
>
Test runs
</span>
</a>
</li>
</ul>
</nav>
<div
Expand Down
15 changes: 1 addition & 14 deletions galasa-ui/src/tests/components/headers/PageHeader.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,13 @@ test('renders the header containing the header menu', () => {
expect(headerMenu).toBeInTheDocument();
});

test('does NOT render the "Test runs" link by default', () => {
test('renders the "Test runs" link by default', () => {
render(
<FeatureFlagProvider>
<PageHeader galasaServiceName="Galasa Service" />
</FeatureFlagProvider>
);

const testRunsLink = screen.queryByText('Test runs');
expect(testRunsLink).not.toBeInTheDocument();
});

test('renders the "Test runs" link when the feature flag is enabled via prop', () => {
const initialFlags = JSON.stringify({ [FEATURE_FLAGS.TEST_RUNS]: true });

render(
<FeatureFlagProvider initialFlags={initialFlags}>
<PageHeader galasaServiceName="Galasa Service" />
</FeatureFlagProvider>
);

const testRunsLink = screen.getByText('Test runs');
expect(testRunsLink).toBeInTheDocument();
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ jest.mock('next-intl', () => ({
title: 'Experimental Features',
description:
'Early access to new features. These are experimental and subject to change or removal.',
'features.testRunSearch': 'Test Run searching and viewing',
'features.graph': 'Test Run Graphs',
};
return translations[key] || key;
},
}));

describe('ExperimentalFeaturesSection', () => {
test('Renders correctly when "testRuns" flag is disabled: Checkbox is unchecked', () => {
const mockIsFeatureEnabled = (key: string) => key !== FEATURE_FLAGS.TEST_RUNS;
test('Renders correctly when "graph" flag is disabled: Checkbox is unchecked', () => {
const mockIsFeatureEnabled = (key: string) => key !== FEATURE_FLAGS.GRAPH;

render(
<FeatureFlagContext.Provider
Expand All @@ -33,13 +33,13 @@ describe('ExperimentalFeaturesSection', () => {
</FeatureFlagContext.Provider>
);

const checkbox = screen.getByLabelText(/Test Run/i);
const checkbox = screen.getByLabelText(/Test Run Graphs/i);
expect(checkbox).not.toBeChecked();
});

test('Renders correctly when a "testRuns" enabled: Checkbox is checked', () => {
test('Renders correctly when a "graph" enabled: Checkbox is checked', () => {
const mockIsFeatureEnabled = (key: string) => {
return key === FEATURE_FLAGS.TEST_RUNS;
return key === FEATURE_FLAGS.GRAPH;
};

render(
Expand All @@ -49,7 +49,7 @@ describe('ExperimentalFeaturesSection', () => {
<ExperimentalFeaturesSection />
</FeatureFlagContext.Provider>
);
const checkbox = screen.getByLabelText(/Test Run/i);
const checkbox = screen.getByLabelText(/Test Run Graphs/i);
expect(checkbox).toBeChecked();
});

Expand All @@ -64,10 +64,10 @@ describe('ExperimentalFeaturesSection', () => {
</FeatureFlagContext.Provider>
);

const checkbox = screen.getByRole('checkbox', { name: /Test Run/i });
const checkbox = screen.getByRole('checkbox', { name: /Test Run Graphs/i });
fireEvent.click(checkbox);

expect(mockToggle).toHaveBeenCalledTimes(1);
expect(mockToggle).toHaveBeenCalledWith(FEATURE_FLAGS.TEST_RUNS);
expect(mockToggle).toHaveBeenCalledWith(FEATURE_FLAGS.GRAPH);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,4 @@ describe('ResultsTablePageSizingSetting', () => {
expect(mockSetDefaultPageSize).toHaveBeenCalledWith(50);
});
});

describe('when feature flag is disabled', () => {
beforeEach(() => {
mockIsFeatureEnabled.mockReturnValue(false);
});

test('does not render the component', () => {
render(<ResultsTablePageSizingSetting />);

expect(screen.queryByText('Test Run Query Results')).toBeNull();
expect(screen.queryByText('Configure the number of results displayed per page.')).toBeNull();
expect(screen.queryByTestId('custom-items-per-page-dropdown-test')).toBeNull();
});
});
});
21 changes: 10 additions & 11 deletions galasa-ui/src/tests/contexts/feature-flag-context.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const TestComponent = () => {

return (
<div>
<p>Test Runs Enabled: {isFeatureEnabled(FEATURE_FLAGS.TEST_RUNS).toString()}</p>
<button onClick={() => toggleFeatureFlag(FEATURE_FLAGS.TEST_RUNS)}>Toggle Test Runs</button>
<p>Test Run Graphs Enabled: {isFeatureEnabled(FEATURE_FLAGS.GRAPH).toString()}</p>
<button onClick={() => toggleFeatureFlag(FEATURE_FLAGS.GRAPH)}>Toggle Test Run Graphs</button>
</div>
);
};
Expand All @@ -40,42 +40,41 @@ describe('Feature Flags Provider and useFeatureFlags Hook', () => {
<TestComponent />
</FeatureFlagProvider>
);
expect(screen.getByText('Test Runs Enabled: false')).toBeInTheDocument();
expect(screen.getByText('Test Run Graphs Enabled: false')).toBeInTheDocument();
});

test('initializes with provided props from the server', () => {
const initialFlags = JSON.stringify({ [FEATURE_FLAGS.TEST_RUNS]: true });
const initialFlags = JSON.stringify({ [FEATURE_FLAGS.GRAPH]: true });
render(
<FeatureFlagProvider initialFlags={initialFlags}>
<TestComponent />
</FeatureFlagProvider>
);

expect(screen.getByText('Test Runs Enabled: true')).toBeInTheDocument();
expect(screen.getByText('Test Run Graphs Enabled: true')).toBeInTheDocument();
});

test('verifies feature flag toggling and updates cookie correctly', () => {
const initialFlags = JSON.stringify({ [FEATURE_FLAGS.TEST_RUNS]: false });
const initialFlags = JSON.stringify({ [FEATURE_FLAGS.GRAPH]: false });
render(
<FeatureFlagProvider initialFlags={initialFlags}>
<TestComponent />
</FeatureFlagProvider>
);

expect(screen.getByText('Test Runs Enabled: false')).toBeInTheDocument();
expect(screen.getByText('Test Run Graphs Enabled: false')).toBeInTheDocument();

// Due to React's strict mode
cookieSpy.mockClear();

const toggleButton = screen.getByText('Toggle Test Runs');
const toggleButton = screen.getByText('Toggle Test Run Graphs');

fireEvent.click(toggleButton);

expect(screen.getByText('Test Runs Enabled: true')).toBeInTheDocument();
expect(screen.getByText('Test Run Graphs Enabled: true')).toBeInTheDocument();

const expectedCookieVal = JSON.stringify({
[FEATURE_FLAGS.TEST_RUNS]: true,
[FEATURE_FLAGS.GRAPH]: false,
[FEATURE_FLAGS.GRAPH]: true,
});

expect(cookieSpy).toHaveBeenCalledTimes(1);
Expand Down
2 changes: 1 addition & 1 deletion galasa-ui/src/tests/mysettings.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jest.mock('next-intl', () => ({
title: 'Experimental Features',
description:
'Early access to new features. These are experimental and subject to change or removal.',
'features.testRunSearch': 'Test Run searching and viewing',
'features.graph': 'Test Run Graphs',
errorTitle: 'Something went wrong!',
errorDescription: 'Please report the problem to your Galasa Ecosystem administrator.',
};
Expand Down
2 changes: 0 additions & 2 deletions galasa-ui/src/utils/featureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@

// Centralized feature flags
export const FEATURE_FLAGS = {
TEST_RUNS: 'testRuns',
GRAPH: 'graph',
// Add other feature flags here
} as const;

export const DEFAULT_FEATURE_FLAGS = {
testRuns: false,
graph: false,
// Add other feature flags here
} as const;
Loading