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

fix(summary-widget): sort tests #561

Merged
merged 1 commit into from
Dec 24, 2024
Merged
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
36 changes: 34 additions & 2 deletions frontend/Views/Widgets/SummaryWidget/SummaryWidget.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
let showFilters = {};
let versionItems = [];
let selectedVersionItem = {};
type TestInfo = {
build_id: string;
name: string | null;
};

$: currentVersionIndex = selectedVersionItem.value;

Expand All @@ -39,11 +43,36 @@
});
$: if (versions.length > 0) fetchRunResults(currentVersionIndex);

/**
* Assigns a name to each test if it is null and sorts the test info by test name.
*
* @param data - The test info data to process and sort.
* @returns The processed and sorted test info data.
*/
function assignAndSortTestInfo(data: Record<string, TestInfo>): Record<string, TestInfo> {

Object.entries(data).forEach(([key, value]) => {
if (value.name === null) {
const parts = value.build_id.split("/");
value.name = parts[parts.length - 1];
}
});

const sortedEntries = Object.entries(data).sort(([, a], [, b]) => {
if (a.name && b.name) {
return a.name.localeCompare(b.name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, I can write test names in hebrew :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently it takes mostly from build_id - I didn't see yet any test_name to be specified in sct_test_run table...
You need use hebrew in jenkins thou 😛

}
return 0;
});

return Object.fromEntries(sortedEntries);
}

async function fetchResults() {
const response = await fetch(`/api/v1/views/widgets/summary/versioned_runs?view_id=${dashboardObject.id}`);
const responseJson = await response.json();
versioned_runs = responseJson.response.versions;
test_info = responseJson.response.test_info;
test_info = assignAndSortTestInfo(responseJson.response.test_info);
versions = Object.keys(versioned_runs);
versionItems = versions.map((version, index) => ({
value: index,
Expand Down Expand Up @@ -94,6 +123,9 @@
}
}
});
runResults = Object.fromEntries(
Object.keys(selectedVersionTestInfo).map(testId => [testId, runResults[testId] || {notRun: true}])
);
extractFiltersPerTest();
}

Expand Down Expand Up @@ -256,7 +288,7 @@
<div class="mb-4 p-3 border rounded {testData.notRun ? 'border-warning' : testData.hasFailedStatus ? 'border-danger' : 'border-success'}">
<h4 class="d-flex justify-content-between align-items-center">
<span class={testData.notRun ? 'text-warning' : testData.hasFailedStatus ? 'text-danger' : 'text-success'}>
{selectedVersionTestInfo[testId]?.name || selectedVersionTestInfo[testId]?.build_id?.split("/")?.pop() || testId}
{selectedVersionTestInfo[testId]?.name || testId}
{#if testData.notRun}
<Fa icon={faExclamationTriangle} class="text-warning ms-2"/>
{:else if testData.hasFailedStatus}
Expand Down
Loading