Skip to content

Commit

Permalink
- Fixed bug in MemberNamingService firstAndLastNameFrom when name is …
Browse files Browse the repository at this point in the history
…null
  • Loading branch information
nbarrett committed Oct 26, 2024
1 parent 1893890 commit 6f9b160
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export class CommitteeMemberComponent implements OnInit {
roleTypes: KeyValue<string>[] = enumKeyValues(RoleType);

protected readonly faRemove = faRemove;
protected readonly RoleType = RoleType;

ngOnInit() {
this.logger.info("ngOnInit", this.committeeMember);
Expand Down Expand Up @@ -161,10 +162,8 @@ export class CommitteeMemberComponent implements OnInit {
}

markdownLink(committeeMember: CommitteeMember) {
const name = this.memberNamingService.firstAndLastNameFrom(committeeMember.fullName);
const name = this.memberNamingService.firstAndLastNameFrom(committeeMember?.fullName);
const path = this.urlService.pathSegments().join("/");
return "[Contact " + name.firstName + "](?contact-us&role=" + committeeMember.type + "&redirect=" + path + ")";
return name ? "[Contact " + name?.firstName + "](?contact-us&role=" + committeeMember?.type + "&redirect=" + path + ")" : null;
}

protected readonly RoleType = RoleType;
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,22 @@ describe("MemberNamingService", () => {
lastName: "Grant"
}, [])).toEqual("John G");
});
});

it("firstAndLastNameFrom should generate a nam from a single string input", () => {
const service: MemberNamingService = TestBed.inject(MemberNamingService);
expect(service.firstAndLastNameFrom("John Grant")).toEqual({firstName: "John", lastName: "Grant"});
});

it("firstAndLastNameFrom should accept a hyphenated a name", () => {
const service: MemberNamingService = TestBed.inject(MemberNamingService);
expect(service.firstAndLastNameFrom("John Hyphenated-Grant")).toEqual({
firstName: "John",
lastName: "Hyphenated-Grant"
});
});

it("firstAndLastNameFrom should accept a hyphenated a name", () => {
const service: MemberNamingService = TestBed.inject(MemberNamingService);
expect(service.firstAndLastNameFrom(null)).toEqual(null);
});
})
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ export class MemberNamingService {
}

public firstAndLastNameFrom(contactName: string): FirstAndLastName {
const contactNames: string[] = contactName?.split(" ");
const firstName = first(contactNames);
const lastName = contactNames.length > 1 ? contactNames.slice(1).join(" ") : "";
return {firstName, lastName};
if (contactName) {
const contactNames: string[] = contactName?.split(" ");
const firstName = first(contactNames);
const lastName = contactNames.length > 1 ? contactNames.slice(1).join(" ") : "";
return {firstName, lastName};
} else {
return null;
}
}

createUniqueUserName(member: RamblersMember | Member, members: Member[]) {
Expand Down

0 comments on commit 6f9b160

Please sign in to comment.