Skip to content

Commit

Permalink
Merge pull request #16 from theRealImy/no-friends
Browse files Browse the repository at this point in the history
No friends yet message added
  • Loading branch information
bourgeoa authored Aug 27, 2021
2 parents 8b9cb83 + 7b8f682 commit 8dc3e57
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
15 changes: 10 additions & 5 deletions src/FriendList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ const styles = {
heading: styleMap(headingLight()),
};

export const FriendList = (
subject: NamedNode,
context: DataBrowserContext
): TemplateResult => html`
const noFriendsFoundMessage = "You have no friends in your list yet";

export const FriendList = (subject: NamedNode, context: DataBrowserContext): TemplateResult => html`
<div style=${styles.root}>
<h3 style=${styles.heading}>Friends</h3>
${createList(subject, context)}
Expand All @@ -28,5 +27,11 @@ const createList = (subject: NamedNode, { dom }: DataBrowserContext) => {
predicate: ns.foaf("knows"),
noun: "friend",
});
return target;
if (target.textContent === "")
return noFriendsInTheListMessage(dom, noFriendsFoundMessage);
else return target;
};

const noFriendsInTheListMessage = (dom: HTMLDocument, message: string): TemplateResult => html`
<div id="no-friends" style=${styles.root}>${message}</div>
`;
10 changes: 8 additions & 2 deletions src/integration-tests/friend-list.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import pane from "../";
import { parse } from "rdflib";
import { store } from "solid-ui";
import { findByTestId } from "@testing-library/dom";
import { findByTestId, findByText } from "@testing-library/dom";
import { context, doc, subject } from "./setup";
import fetchMock from "jest-fetch-mock";

describe("profile-pane", () => {
let friends;
let noFriendsMessage;

describe("with friends", () => {
beforeAll(async () => {
Expand Down Expand Up @@ -43,10 +44,15 @@ describe("profile-pane", () => {
store.removeDocument(doc);
const result = pane.render(subject, context);
friends = await findByTestId(result, "friend-list");
noFriendsMessage = await findByText(result, "You have no friends in your list yet");
});

it("renders the friend list", () => {
expect(friends).toContainHTML("Friends");
});

it("renders an empty friend list", () => {
expect(friends.textContent.trim()).toBe("Friends");
expect(noFriendsMessage).not.toBeNull();
});
});

Expand Down

0 comments on commit 8dc3e57

Please sign in to comment.