Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aethernet committed May 7, 2024
1 parent 7c62207 commit 5e1ee85
Show file tree
Hide file tree
Showing 13 changed files with 265 additions and 36 deletions.
24 changes: 20 additions & 4 deletions lib/gui/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,18 @@ observe(() => {

function setDrives(drives: Dictionary<DrivelistDrive>) {
// prevent setting drives while flashing otherwise we might lose some while we unmount them
if (!flashState.isFlashing()) {
availableDrives.setDrives(values(drives));
}
availableDrives.setDrives(values(drives));
}

// Spawning the child process without privileges to get the drives list
// TODO: clean up this mess of exports
export let requestMetadata: any;
export let requestMetadata: (params: any) => Promise<SourceMetadata>;
export let startScanner: () => void = () => {
console.log('stopScanner is not yet set');
};
export let stopScanner: () => void = () => {
console.log('stopScanner is not yet set');
};

// start the api and spawn the child process
spawnChildAndConnect({
Expand All @@ -147,6 +151,18 @@ spawnChildAndConnect({
// start scanning
emit('scan', {});

// make startScanner available for the end of flash
startScanner = () => {
console.log('startScanner');
emit('scan', {});
};

// make stopScanner available for the start of flash
stopScanner = () => {
console.log('stopScanner');
emit('scan', {});
};

// make the sourceMetada awaitable to be used on source selection
requestMetadata = async (params: any): Promise<SourceMetadata> => {
emit('sourceMetadata', JSON.stringify(params));
Expand Down
6 changes: 5 additions & 1 deletion lib/gui/app/components/flash-another/flash-another.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ export interface FlashAnotherProps {

export const FlashAnother = (props: FlashAnotherProps) => {
return (
<BaseButton primary onClick={props.onClick}>
<BaseButton
primary
data-testid="flash-another-button"
onClick={props.onClick}
>
{i18next.t('flash.another')}
</BaseButton>
);
Expand Down
1 change: 1 addition & 0 deletions lib/gui/app/components/source-selector/source-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,7 @@ export class SourceSelector extends React.Component<
</StepNameButton>
{!flashing && !imageLoading && (
<ChangeButton
data-testid="change-image-button"
plain
mb={14}
onClick={() => this.reselectSource()}
Expand Down
2 changes: 0 additions & 2 deletions lib/gui/app/modules/progress-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ export function fromFlashState({
status: string;
position?: string;
} {
console.log(i18next.t('progress.starting'));

if (type === undefined) {
return { status: i18next.t('progress.starting') };
} else if (type === 'decompressing') {
Expand Down
2 changes: 0 additions & 2 deletions lib/gui/app/pages/main/Flash.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ async function flashImageToDrive(
errorMessage = messages.error.genericFlashError(error);
}
return errorMessage;
} finally {
availableDrives.setDrives([]);
}

return '';
Expand Down
7 changes: 6 additions & 1 deletion lib/util/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { toJSON } from '../shared/errors';
import { GENERAL_ERROR, SUCCESS } from '../shared/exit-codes';
import type { WriteOptions } from './types/types';
import { write, cleanup } from './child-writer';
import { startScanning } from './scanner';
import { startScanning, stopScanning } from './scanner';
import { getSourceMetadata } from './source-metadata';
import type { DrivelistDrive } from '../shared/drive-constraints';
import type { SourceMetadata } from '../shared/typings/source-selector';
Expand Down Expand Up @@ -222,6 +222,11 @@ function setup(): Promise<EmitLog> {
startScanning();
},

stopScan: () => {
log('Stop scan requested');
stopScanning();
},

// route `cancel` from client
cancel: () => onAbort(GENERAL_ERROR),

Expand Down
7 changes: 5 additions & 2 deletions lib/util/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,15 @@ const COMPUTE_MODULE_DESCRIPTIONS: Dictionary<string> = {
};

const startScanning = () => {
driveScanner.on('attach', (drive) => addDrive(drive));
driveScanner.on('detach', (drive) => removeDrive(drive));
driveScanner.on('attach', addDrive);
driveScanner.on('detach', removeDrive);
driveScanner.start();
};

const stopScanning = () => {
driveScanner.removeListener('attach', addDrive);
driveScanner.removeListener('detach', removeDrive);
availableDrives = [];
driveScanner.stop();
};

Expand Down
Loading

0 comments on commit 5e1ee85

Please sign in to comment.