Skip to content

Commit 5e1ee85

Browse files
committed
tests
1 parent 7c62207 commit 5e1ee85

File tree

13 files changed

+265
-36
lines changed

13 files changed

+265
-36
lines changed

lib/gui/app/app.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,18 @@ observe(() => {
130130

131131
function setDrives(drives: Dictionary<DrivelistDrive>) {
132132
// prevent setting drives while flashing otherwise we might lose some while we unmount them
133-
if (!flashState.isFlashing()) {
134-
availableDrives.setDrives(values(drives));
135-
}
133+
availableDrives.setDrives(values(drives));
136134
}
137135

138136
// Spawning the child process without privileges to get the drives list
139137
// TODO: clean up this mess of exports
140-
export let requestMetadata: any;
138+
export let requestMetadata: (params: any) => Promise<SourceMetadata>;
139+
export let startScanner: () => void = () => {
140+
console.log('stopScanner is not yet set');
141+
};
142+
export let stopScanner: () => void = () => {
143+
console.log('stopScanner is not yet set');
144+
};
141145

142146
// start the api and spawn the child process
143147
spawnChildAndConnect({
@@ -147,6 +151,18 @@ spawnChildAndConnect({
147151
// start scanning
148152
emit('scan', {});
149153

154+
// make startScanner available for the end of flash
155+
startScanner = () => {
156+
console.log('startScanner');
157+
emit('scan', {});
158+
};
159+
160+
// make stopScanner available for the start of flash
161+
stopScanner = () => {
162+
console.log('stopScanner');
163+
emit('scan', {});
164+
};
165+
150166
// make the sourceMetada awaitable to be used on source selection
151167
requestMetadata = async (params: any): Promise<SourceMetadata> => {
152168
emit('sourceMetadata', JSON.stringify(params));

lib/gui/app/components/flash-another/flash-another.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ export interface FlashAnotherProps {
2525

2626
export const FlashAnother = (props: FlashAnotherProps) => {
2727
return (
28-
<BaseButton primary onClick={props.onClick}>
28+
<BaseButton
29+
primary
30+
data-testid="flash-another-button"
31+
onClick={props.onClick}
32+
>
2933
{i18next.t('flash.another')}
3034
</BaseButton>
3135
);

lib/gui/app/components/source-selector/source-selector.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,7 @@ export class SourceSelector extends React.Component<
640640
</StepNameButton>
641641
{!flashing && !imageLoading && (
642642
<ChangeButton
643+
data-testid="change-image-button"
643644
plain
644645
mb={14}
645646
onClick={() => this.reselectSource()}

lib/gui/app/modules/progress-status.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ export function fromFlashState({
3434
status: string;
3535
position?: string;
3636
} {
37-
console.log(i18next.t('progress.starting'));
38-
3937
if (type === undefined) {
4038
return { status: i18next.t('progress.starting') };
4139
} else if (type === 'decompressing') {

lib/gui/app/pages/main/Flash.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,6 @@ async function flashImageToDrive(
122122
errorMessage = messages.error.genericFlashError(error);
123123
}
124124
return errorMessage;
125-
} finally {
126-
availableDrives.setDrives([]);
127125
}
128126

129127
return '';

lib/util/api.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { toJSON } from '../shared/errors';
2424
import { GENERAL_ERROR, SUCCESS } from '../shared/exit-codes';
2525
import type { WriteOptions } from './types/types';
2626
import { write, cleanup } from './child-writer';
27-
import { startScanning } from './scanner';
27+
import { startScanning, stopScanning } from './scanner';
2828
import { getSourceMetadata } from './source-metadata';
2929
import type { DrivelistDrive } from '../shared/drive-constraints';
3030
import type { SourceMetadata } from '../shared/typings/source-selector';
@@ -222,6 +222,11 @@ function setup(): Promise<EmitLog> {
222222
startScanning();
223223
},
224224

225+
stopScan: () => {
226+
log('Stop scan requested');
227+
stopScanning();
228+
},
229+
225230
// route `cancel` from client
226231
cancel: () => onAbort(GENERAL_ERROR),
227232

lib/util/scanner.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,15 @@ const COMPUTE_MODULE_DESCRIPTIONS: Dictionary<string> = {
172172
};
173173

174174
const startScanning = () => {
175-
driveScanner.on('attach', (drive) => addDrive(drive));
176-
driveScanner.on('detach', (drive) => removeDrive(drive));
175+
driveScanner.on('attach', addDrive);
176+
driveScanner.on('detach', removeDrive);
177177
driveScanner.start();
178178
};
179179

180180
const stopScanning = () => {
181+
driveScanner.removeListener('attach', addDrive);
182+
driveScanner.removeListener('detach', removeDrive);
183+
availableDrives = [];
181184
driveScanner.stop();
182185
};
183186

0 commit comments

Comments
 (0)