Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: merge develop into main #1464

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
27 changes: 15 additions & 12 deletions .github/workflows/build-test-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ jobs:
path: Splunk_TA_UCCExample*.tar.gz

test-ui:
name: test-ui Splunk ${{ matrix.splunk.version }} -m ${{ matrix.test-mark }}
name: test-ui Splunk ${{ matrix.splunk.version }} -group ${{ matrix.test-group }}
runs-on: ubuntu-22.04
permissions:
id-token: write
Expand All @@ -243,14 +243,17 @@ jobs:
fail-fast: false
matrix:
splunk: ${{ fromJson(needs.meta.outputs.matrix_supportedSplunk) }}
test-mark:
- "logging"
- "proxy"
- "account"
- "custom"
- "alert"
- "input"
- "configuration"
test-group:
- "1"
- "2"
- "3"
- "4"
- "5"
- "6"
- "7"
- "8"
- "9"
- "10"
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
Expand All @@ -272,16 +275,16 @@ jobs:
./scripts/run_splunk.sh ${{ matrix.splunk.version }}
until curl -Lsk "https://localhost:8088/services/collector/health" &>/dev/null ; do echo -n "Waiting for HEC-" && sleep 5 ; done
timeout-minutes: 5
- run: poetry run pytest tests/ui -m "${{ matrix.test-mark }}" --headless --junitxml=test-results/junit.xml
- run: poetry run pytest tests/ui --test-group-count 10 --test-group ${{ matrix.test-group }} --test-group-random-seed 123456 --headless --junitxml=test-results/junit.xml
- uses: actions/upload-artifact@v4
if: success() || failure()
with:
name: test-results-ui-${{ matrix.splunk.version }}-${{ matrix.test-mark }}
name: test-results-ui-${{ matrix.splunk.version }}-${{ matrix.test-group }}
path: test-results/*
- uses: dorny/test-reporter@v1
if: success() || failure()
with:
name: test-report-ui-${{ matrix.splunk.version }}-${{ matrix.test-mark }}
name: test-report-ui-${{ matrix.splunk.version }}-${{ matrix.test-group }}
path: "test-results/*.xml"
reporter: java-junit

Expand Down
16 changes: 15 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ mkdocs-print-site-plugin = "^2.3.6"
pytest-cov = "^4.0.0"
covdefaults = "^2.3.0"
xmldiff = "^2.6.3"
pytest-split-tests = "^1.1.0"

[tool.poetry.scripts]
ucc-gen="splunk_add_on_ucc_framework.main:main"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
const mockedEntries = [
{ name: 'dataApiTest1', content: { testLabel: 'firstLabel', testValue: 'firstValue' } },
{ name: 'dataApiTest2', content: { testLabel: 'secondLabel', testValue: 'secondValue' } },
{ name: 'dataApiTest3', content: { testLabel: 'thirdLabel', testValue: 'thirdValue' } },
{ name: 'dataApiTest4', content: { testLabel: 'fourthLabel', testValue: 'fourthValue' } },
{ name: 'true', content: { testLabel: 'thirdLabel', testValue: 'thirdValue' } },
{ name: '0', content: { testLabel: 'fourthLabel', testValue: 'fourthValue' } },
];

const MOCK_API_URL = '/demo_addon_for_splunk/some_API_endpint_for_select_data';
Expand Down Expand Up @@ -167,3 +167,67 @@
const { label } = autoCompleteFields[0];
expect(within(inputComponent).getByText(label)).toBeInTheDocument();
});

it('should fetch options from API when endpointUrl is provided', async () => {

Check warning on line 171 in ui/src/components/SingleInputComponent/SingleInputComponent.test.tsx

View workflow job for this annotation

GitHub Actions / Build UCC UI / build-ui

Test has no assertions

Check warning on line 171 in ui/src/components/SingleInputComponent/SingleInputComponent.test.tsx

View workflow job for this annotation

GitHub Actions / Build UCC UI / build-ui

Test has no assertions
// server responses with a filtered mockedEntries based on the name parameter
server.use(
http.get(MOCK_API_URL, ({ request }) => {
const url = new URL(request.url);

const nameParameter = url.searchParams.get('name');
return HttpResponse.json(
getMockServerResponseForInput(
mockedEntries.filter((entry) => entry.name === nameParameter)
)
);
})
);
const baseProps = {
...defaultInputProps,
value: '',
controlOptions: {
createSearchChoice: true,
dependencies: ['name', 'region'],
endpointUrl: MOCK_API_URL,
labelField: 'testLabel',
valueField: 'testValue',
},
};
const { rerender } = render(<SingleInputComponent {...baseProps} />);

await userEvent.click(screen.getByRole('combobox'));
await screen.findByRole('menuitem', { name: 'No matches' });

// undefined value must be omitted
const firstEntry = mockedEntries[0];
rerender(
<SingleInputComponent
{...baseProps}
dependencyValues={{ name: firstEntry.name, region: undefined }}
/>
);
await userEvent.click(screen.getByRole('combobox'));
await screen.findByRole('option', { name: firstEntry.content.testLabel });

const secondEntry = mockedEntries[1];
rerender(
<SingleInputComponent
{...baseProps}
dependencyValues={{ name: secondEntry.name, region: 1 }}
/>
);
await userEvent.click(screen.getByRole('combobox'));
await screen.findByRole('option', { name: secondEntry.content.testLabel });

const thirdEntry = mockedEntries[2];
rerender(
<SingleInputComponent {...baseProps} dependencyValues={{ name: true, region: false }} />
);
await userEvent.click(screen.getByRole('combobox'));
await screen.findByRole('option', { name: thirdEntry.content.testLabel });

const fourthEntry = mockedEntries[3];
rerender(<SingleInputComponent {...baseProps} dependencyValues={{ name: 0, region: 0 }} />);
await userEvent.click(screen.getByRole('combobox'));
await screen.findByRole('option', { name: fourthEntry.content.testLabel });
});
12 changes: 7 additions & 5 deletions ui/src/util/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import { generateToast, getUnifiedConfigs } from './util';
import { parseErrorMsg } from './messageUtil';
import { ResponseError } from './ResponseError';

type ParamsRecord = Record<string, string | number | undefined>;

export interface RequestParams {
endpointUrl: string;
params?: Record<string, string | number>;
params?: ParamsRecord;
signal?: AbortSignal;
body?: BodyInit;
handleError: boolean;
Expand All @@ -21,14 +23,14 @@ export function generateEndPointUrl(name: string) {

const DEFAULT_PARAMS = { output_mode: 'json' };

function createUrl(endpointUrl: string, params: Record<string, string | number>): URL {
function createUrl(endpointUrl: string, params: ParamsRecord): URL {
const url = new URL(
createRESTURL(endpointUrl, { app, owner: 'nobody' }),
window.location.origin
);
Object.entries({ ...DEFAULT_PARAMS, ...params }).forEach(([key, value]) =>
url.searchParams.append(key, value.toString())
);
Object.entries({ ...DEFAULT_PARAMS, ...params })
.filter(([, value]) => value !== undefined && value !== null)
.forEach(([key, value]) => url.searchParams.append(key, value.toString()));
return url;
}

Expand Down
Loading