Fix snackbar messages

Test: npm run build:all && npm run test:all
Change-Id: I0f77bfe0e703b076296c5c4ee87af795d41aeca4
This commit is contained in:
Kean Mariotti
2022-12-19 18:06:54 +00:00
parent 3f5843666f
commit b228591503
4 changed files with 30 additions and 21 deletions

View File

@@ -475,7 +475,7 @@ export class CollectTracesComponent implements OnInit, OnDestroy {
this.traceData.clear();
const parserErrors = await this.traceData.loadTraces(this.connect.adbData());
ParserErrorSnackBarComponent.open(this.ngZone, this.snackBar, parserErrors);
ParserErrorSnackBarComponent.showIfNeeded(this.ngZone, this.snackBar, parserErrors);
this.traceDataLoaded.emit();
console.log("finished loading data!");
}

View File

@@ -44,31 +44,30 @@ import {ParserError, ParserErrorType} from "parsers/parser_factory";
})
export class ParserErrorSnackBarComponent {
messages: string[] = [];
constructor(
@Inject(MatSnackBarRef) public snackBarRef: MatSnackBarRef<ParserErrorSnackBarComponent>,
@Inject(MAT_SNACK_BAR_DATA) public messages: string[]
) {
}
static showIfNeeded(ngZone: NgZone, snackBar: MatSnackBar, errors: ParserError[]) {
const messages = this.convertErrorsToMessages(errors);
if (messages.length === 0) {
return;
}
static open(ngZone: NgZone, snackBar: MatSnackBar, parserErrors: ParserError[]) {
ngZone.run(() => {
// The snackbar needs to be opened within ngZone,
// otherwise it will first display on the left and then will jump to the center
snackBar.openFromComponent(ParserErrorSnackBarComponent, {
data: parserErrors,
data: messages,
duration: 10000,
});
});
}
constructor(
@Inject(MatSnackBarRef) public snackBarRef: MatSnackBarRef<ParserErrorSnackBarComponent>,
@Inject(MAT_SNACK_BAR_DATA) errors: ParserError[]
) {
this.messages = this.convertErrorsToMessages(errors);
if (this.messages.length === 0) {
this.snackBarRef.dismiss();
}
}
private convertErrorsToMessages(errors: ParserError[]): string[] {
private static convertErrorsToMessages(errors: ParserError[]): string[] {
const messages: string[] = [];
const groups = this.groupErrorsByType(errors);
@@ -89,7 +88,7 @@ export class ParserErrorSnackBarComponent {
return messages;
}
private convertErrorToMessage(error: ParserError): string {
private static convertErrorToMessage(error: ParserError): string {
let message = `${error.trace.name}: unknown error occurred`;
if (error.type === ParserErrorType.OVERRIDE && error.traceType) {
message = `${error.trace.name}:` +
@@ -100,7 +99,7 @@ export class ParserErrorSnackBarComponent {
return message;
}
private makeCroppedMessage(type: ParserErrorType, count: number): string {
private static makeCroppedMessage(type: ParserErrorType, count: number): string {
switch(type) {
case ParserErrorType.OVERRIDE:
return `... (cropped ${count} overridden trace messages)`;
@@ -111,7 +110,7 @@ export class ParserErrorSnackBarComponent {
}
}
private groupErrorsByType(errors: ParserError[]): Map<ParserErrorType, ParserError[]> {
private static groupErrorsByType(errors: ParserError[]): Map<ParserErrorType, ParserError[]> {
const groups = new Map<ParserErrorType, ParserError[]>();
errors.forEach(error => {

View File

@@ -221,7 +221,7 @@ export class UploadTracesComponent implements UploadTracesComponentDependencyInv
this.isLoadingFiles = false;
this.changeDetectorRef.detectChanges();
ParserErrorSnackBarComponent.open(this.ngZone, this.snackBar, parserErrors);
ParserErrorSnackBarComponent.showIfNeeded(this.ngZone, this.snackBar, parserErrors);
}
public onViewTracesButtonClick() {

View File

@@ -28,14 +28,20 @@ describe("Upload traces", () => {
it("can process bugreport", async () => {
await E2eTestUtils.uploadFixture("bugreports/bugreport_stripped.zip");
await E2eTestUtils.closeSnackBarIfNeeded();
await checkHasLoadedTraces();
expect(await areMessagesEmitted()).toBeTruthy();
await checkEmitsUnsupportedFileFormatMessages();
await checkEmitsOverriddenTracesMessages();
await E2eTestUtils.closeSnackBarIfNeeded();
await E2eTestUtils.clickViewTracesButton();
await checkRendersSurfaceFlingerView();
});
it("doesn't emit messages for valid trace file", async () => {
await E2eTestUtils.uploadFixture("traces/elapsed_and_real_timestamp/SurfaceFlinger.pb");
expect(await areMessagesEmitted()).toBeFalsy();
});
const checkHasLoadedTraces = async () => {
const text = await element(by.css(".uploaded-files")).getText();
expect(text).toContain("wm_log.winscope (ProtoLog)");
@@ -57,6 +63,10 @@ describe("Upload traces", () => {
expect(text).toContain("overridden by another trace");
};
const areMessagesEmitted = async (): Promise<boolean> => {
return element(by.css("upload-snack-bar")).isPresent();
};
const checkRendersSurfaceFlingerView = async () => {
const viewerPresent = await element(by.css("viewer-surface-flinger")).isPresent();
expect(viewerPresent).toBeTruthy();