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

Update user avatar fallback #472

Merged
merged 5 commits into from
Dec 4, 2023
Merged
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: 5 additions & 7 deletions web/app/components/person/avatar.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@
/>
{{else}}
<div data-test-fallback class="flex text-body-100">
{{#if @email}}
<span class="capitalize">
{{get-first-letter @email}}
</span>
{{else}}
<FlightIcon @name="user" class="scale-90" />
{{/if}}
<FlightIcon
class="default-user-icon text-color-foreground-faint"
@size={{if this.iconIsLarge "24"}}
@name="user"
/>
</div>
{{/if}}
{{/if}}
Expand Down
4 changes: 4 additions & 0 deletions web/app/components/person/avatar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ interface PersonAvatarComponentSignature {

export default class PersonAvatarComponent extends Component<PersonAvatarComponentSignature> {
protected size = this.args.size ?? HermesSize.Small;

protected get iconIsLarge(): boolean {
return this.size === HermesSize.Large || this.size === HermesSize.XL;
}
}

declare module "@glint/environment-ember-loose/registry" {
Expand Down
25 changes: 0 additions & 25 deletions web/app/helpers/get-first-letter.ts

This file was deleted.

4 changes: 4 additions & 0 deletions web/app/styles/hermes/avatar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@

&.small {
@apply h-5 w-5;

.default-user-icon {
@apply scale-[85%];
}
}

&.medium {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,7 @@ module("Acceptance | authenticated/projects/project", function (hooks) {

assert
.dom(JIRA_ASSIGNEE_AVATAR)
.hasAttribute("data-test-assignee", jiraAssignee)
.hasText(jiraAssignee.charAt(0));
.hasAttribute("data-test-assignee", jiraAssignee);

assert.dom(JIRA_OVERFLOW_BUTTON).exists();
});
Expand Down
2 changes: 1 addition & 1 deletion web/tests/integration/components/editable-field-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ module("Integration | Component | editable-field", function (hooks) {

<EditableField
data-test-two
@value={{array (hash email="bar")}}
@value={{array (hash email="bar" imgURL="baz")}}
@onSave={{this.onCommit}}
/>
`);
Expand Down
10 changes: 1 addition & 9 deletions web/tests/integration/components/person-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,15 @@ module("Integration | Component | person", function (hooks) {
.dom(".person .person-email")
.hasText(this.email)
.hasAttribute("title", this.email);
assert.dom(".person span").doesNotExist();
assert.dom(".person svg").doesNotExist();

this.set("imgURL", null);

assert.dom(".person img").doesNotExist();
assert.dom(".person .person-email").hasText(this.email);
assert.dom(".person span").hasText("e");
assert.dom(".person svg").doesNotExist();

this.set("email", null);

assert.dom(".person img").doesNotExist();
assert.dom(".person .person-email").hasText("Unknown");
assert.dom(".person span").doesNotExist();
assert.dom(".person svg").exists();

this.set("email", null);
this.set("ignoreUnknown", true);

assert.dom(".person").doesNotExist();
Expand Down
17 changes: 13 additions & 4 deletions web/tests/integration/components/person/avatar-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,32 @@ module("Integration | Component | person/avatar", async function (hooks) {
<Person::Avatar class="xl" @email="" @size="xl" />
`);

function assertIconSize(containerClass: string, size: string) {
assert
.dom(`.${containerClass} .flight-icon`)
.hasAttribute("width", size)
.hasAttribute("height", size);
}

assert.dom(".default").hasStyle({ width: "20px" });
assert.dom(".default").hasStyle({ height: "20px" });
assertIconSize("default", "16");

assert.dom(".small").hasStyle({ width: "20px" });
assert.dom(".small").hasStyle({ height: "20px" });
assertIconSize("small", "16");

assert.dom(".medium").hasStyle({ width: "28px" });
assert.dom(".medium").hasStyle({ height: "28px" });
assertIconSize("medium", "16");

assert.dom(".large").hasStyle({ width: "36px" });
assert.dom(".large").hasStyle({ height: "36px" });
assertIconSize("large", "24");

assert.dom(".xl").hasStyle({ width: "64px" });
assert.dom(".xl").hasStyle({ height: "64px" });
assertIconSize("xl", "24");
});

test("it can render a loading state", async function (this: PersonAvatarTestContext, assert) {
Expand All @@ -49,13 +61,10 @@ module("Integration | Component | person/avatar", async function (hooks) {
`);

assert.dom(LOADING).exists();
assert.dom(IMAGE).doesNotExist();
assert.dom(FALLBACK).doesNotExist();

this.set("isLoading", false);

assert.dom(LOADING).doesNotExist();
assert.dom(FALLBACK).exists();
});

test("it renders an image if provided and a fallback if not", async function (this: PersonAvatarTestContext, assert) {
Expand All @@ -71,6 +80,6 @@ module("Integration | Component | person/avatar", async function (hooks) {
this.set("imgURL", undefined);

assert.dom(IMAGE).doesNotExist();
assert.dom(FALLBACK).hasText("B");
assert.dom(FALLBACK).exists();
});
});
36 changes: 0 additions & 36 deletions web/tests/integration/helpers/get-first-letter-test.js

This file was deleted.