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

Test DISCOVERY-437 (bonus: smoke test viewScanList!) #518

Open
wants to merge 4 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
12 changes: 11 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
module.exports = {};

module.exports = (api) => {
api.cache(true)
const presets = ["@babel/preset-react", "@babel/preset-env"];
const plugins = ["@babel/plugin-transform-modules-commonjs"];

return {
presets,
plugins
};
}
2 changes: 2 additions & 0 deletions config/cspell.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"elit",
"fadein",
"generatedid",
"haspopup",
"labelledby",
"mturley",
"nocolor",
Expand All @@ -30,6 +31,7 @@
"rescan",
"rhacs",
"rowgroup",
"rowindex",
"runas",
"scanjob",
"srcset",
Expand Down
9 changes: 6 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ module.exports = {
testMatch: ['<rootDir>/**/__tests__/**/*.{ts,tsx}', '<rootDir>/**/*.{spec,test}.{ts,tsx}'],
testEnvironment: 'jsdom',
transform: {
'^.+\\.(js|jsx|ts|tsx)$': '<rootDir>/node_modules/ts-jest',
'^.+\\.(jsx|ts|tsx)$': '<rootDir>/node_modules/ts-jest',
// @mturley-latest/react-table-batteries lib proved to be challenging to properly transform
// using ts-jest; for this reason, js files are transformed with babel for now;
'^.+\\.js$': '<rootDir>/node_modules/babel-jest',
'^.+\\.css$': '<rootDir>/config/jest.transform.style.js',
'^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '<rootDir>/config/jest.transform.file.js'
},
transformIgnorePatterns: [
'[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|cjs|ts|tsx)$',
'[/\\\\]node_modules[/\\\\][/\\.+\\\\]*.+\\.(jsx|mjs|cjs|ts|tsx)$',
'^.+\\.module\\.(css|sass|scss)$'
],
watchPlugins: ['jest-watch-typeahead/filename', 'jest-watch-typeahead/testname']
watchPlugins: ['jest-watch-typeahead/filename', 'jest-watch-typeahead/testname'],
};
1 change: 1 addition & 0 deletions public/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@
"label_satellite": "Satellite",
"label_rhacs": "RHACS",
"label_rescan": "Rescan",
"label_download": "Download",
"label_scan": "Scan",
"label_source": "Source",
"label_source_other": "Sources",
Expand Down
3 changes: 2 additions & 1 deletion src/components/actionMenu/actionMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { EllipsisVIcon } from '@patternfly/react-icons';

interface ActionMenuProps<T = unknown> {
item: T;
actions: { label: string; onClick: (item: T) => void }[];
actions: { label: string; onClick: (item: T) => void; disabled?: boolean }[];
}

const ActionMenu = <T,>({ item, actions }: ActionMenuProps<T>) => {
Expand Down Expand Up @@ -43,6 +43,7 @@ const ActionMenu = <T,>({ item, actions }: ActionMenuProps<T>) => {
onClick={() => {
a.onClick(item);
}}
isDisabled={a.disabled}
>
{a.label}
</DropdownItem>
Expand Down
13 changes: 12 additions & 1 deletion src/helpers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React from 'react';
import moment, { type MomentInput } from 'moment';
import titleImg from '../images/title.svg';
import titleImgBrand from '../images/titleBrand.svg';
import { type CredentialType } from '../types/types';
import { type CredentialType, type MostRecentScan, type scanJob } from '../types/types';

/**
* Is dev mode active.
Expand Down Expand Up @@ -226,8 +226,19 @@ const getCurrentDate = () => (TEST_MODE && moment.utc('20241001').toDate()) || m
*/
const getTitleImg = (isBrand = UI_BRAND) => ((isBrand && titleImgBrand) || titleImg) as string;

/**
* Return if a report associated with given ScanJob can be downloaded
*
* @param {scanJob | MostRecentScan} job
* @returns {boolean}
*/
const canDownloadReport = (job?: scanJob | MostRecentScan) => {
return job?.status === 'completed' && job?.report_id !== undefined;
};

const helpers = {
authType,
canDownloadReport,
downloadData,
noopTranslate,
generateId,
Expand Down
4 changes: 4 additions & 0 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,16 @@ export type ScanOptions = {
export type scanJob = {
id: number;
report_id: number;
status: string;
};

export type StatusDetails = {
job_status_message: string;
};

// TODO: Considerations for a future refactor: merge and/or rename scanJob and MostRecentScan.
// Reason: the object returned from the api representing scanJob and MostRecentScan are the same;
// also, in quipucords jargon, MostRecentScan is a ScanJob, not a Scan.
export type MostRecentScan = {
id: number;
report_id: number;
Expand Down
Loading
Loading