Skip to content

Commit

Permalink
Fix styling in activity footer (#1579)
Browse files Browse the repository at this point in the history
* Fix footer styling

* Move percentage to align with text

* Add test to check name truncating

* Remove fdescribe
  • Loading branch information
arinehouse authored Sep 5, 2018
1 parent 8211deb commit b3172b6
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ComponentFixture, TestBed } from "@angular/core/testing";
import { By } from "@angular/platform-browser";
import { MaterialModule } from "@batch-flask/core";
import { ActivityMonitorFooterItemComponent } from "@batch-flask/ui/activity-monitor";
import { BehaviorSubject } from "rxjs";
import { AsyncSubject, BehaviorSubject } from "rxjs";

@Component({
template: `
Expand Down Expand Up @@ -54,36 +54,39 @@ describe("ActivityMonitorFooterItemComponent", () => {
const nameEl = de.query(By.css(".name"));

expect(nameEl.nativeElement.textContent).toContain("Test activity");
expect(nameEl.nativeElement.textContent).not.toContain("...");
});

it("should display the activity name trucated to 20 characters", () => {
it("should not truncate the activity name if it is short enough to fit", () => {
const nameEl = de.query(By.css(".name"));
expect(nameEl.nativeElement.offsetWidth).toBe(nameEl.nativeElement.scrollWidth);
});

it("should truncate the activity name if it is too long to fit", () => {
testComponent.activity = new MockActivity(
"Test activity but it's longer than 20 characters",
"loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong name",
testComponent.subj,
);
fixture.detectChanges();

expect(nameEl.nativeElement.textContent).toContain("Test activity but it...");
const nameEl = de.query(By.css(".name"));
expect(nameEl.nativeElement.offsetWidth < nameEl.nativeElement.scrollWidth).toBe(true);
});

it("should display the percentage if an activity is emitting progress", () => {
const nameEl = de.query(By.css(".name"));
const progressEl = de.query(By.css(".progress-percent"));

const progressSubj = new BehaviorSubject(0);

testComponent.activity = new MockActivity("Test activity with progress subject", progressSubj);
fixture.detectChanges();

expect(component.progress).toBe(0);
expect(nameEl.nativeElement.textContent).toContain("(0%)");
expect(progressEl.nativeElement.textContent).toContain("(0%)");

progressSubj.next(50);
fixture.detectChanges();

expect(component.progress).toBe(50);
expect(nameEl.nativeElement.textContent).toContain("(50%)");
expect(progressEl.nativeElement.textContent).toContain("(50%)");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
HostBinding,
Input,
OnChanges,
} from "@angular/core";
import { Activity } from "@batch-flask/ui/activity-monitor/activity";
import { Subscription } from "rxjs";

import "./activity-monitor-footer-item.scss";

@Component({
selector: "bl-activity-monitor-footer-item",
templateUrl: "activity-monitor-footer-item.html",
Expand All @@ -16,8 +19,8 @@ import { Subscription } from "rxjs";
export class ActivityMonitorFooterItemComponent implements OnChanges {
@Input() public activity: Activity;
public progress: number;
public progressString: string;

private _progressString: string;
private _sub: Subscription;

constructor(private changeDetector: ChangeDetectorRef) {}
Expand All @@ -28,6 +31,7 @@ export class ActivityMonitorFooterItemComponent implements OnChanges {
}
}

@HostBinding("attr.title")
public get name() {
return this.activity.name;
}
Expand All @@ -36,23 +40,14 @@ export class ActivityMonitorFooterItemComponent implements OnChanges {
return this.activity.isComplete;
}

public prettyPrint() {
if (this.name.length < 20) {
return `${this.name} ${this._progressString}`;
} else {
return `${this.name.slice(0, 20)}... ${this._progressString}`;
}
}

private _subscribeToProgress() {
if (this._sub && this._sub.closed) {
if (this._sub) {
this._sub.unsubscribe();
}

this._sub = this.activity.progress.subscribe((progress) => {

this.progress = progress;
this._progressString = `(${Math.floor(progress)}%)`;
this.progressString = `(${Math.floor(progress)}%)`;
this.changeDetector.markForCheck();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
</div>
<i class="fa fa-check" *ngIf="isComplete"></i>
</div>
<span class="name">{{prettyPrint()}}</span>
<span class="name">{{name}}</span>
<span class="progress-percent">{{progressString}}</span>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
@import "app/styles/variables";

bl-activity-monitor-footer-item {
display: flex;
align-items: center;
width: 100%;

> .status-icon {
width: 18px;
height: 18px;
margin-right: 10px;
.mat-progress-spinner {
path {
stroke: $whiteSmoke;
}
}
.fa {
vertical-align: middle;
line-height: 24px;
font-size: 18px;
}
}

> .name {
min-width: 0;
text-align: left;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
padding-right: 5px;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ bl-activity-monitor-footer {
display: flex;
align-items: center;

> bl-activity-monitor-footer-item {flex: 1;};
> bl-activity-monitor-footer-item {
flex: 1;
min-width: 0;
};

> .other-task-count {
width: 21px;
Expand All @@ -41,31 +44,4 @@ bl-activity-monitor-footer {
.flash {
animation: flash 1s infinite;
}

bl-activity-monitor-footer-item {
display: flex;
align-items: center;
width: 100%;

> .status-icon {
width: 18px;
height: 18px;
margin-right: 10px;
.mat-progress-spinner {
path {
stroke: $whiteSmoke;
}
}
.fa {
vertical-align: middle;
line-height: 24px;
font-size: 18px;
}
}

> .name {
flex: 1;
text-align: left;
}
}
}

0 comments on commit b3172b6

Please sign in to comment.