Skip to content

Commit

Permalink
Fix RecentlyViewedDocs draft hrefs (#300)
Browse files Browse the repository at this point in the history
* Fix RecentlyViewedDocs draft hrefs

* Fix test selector
  • Loading branch information
jeffdaley authored Aug 21, 2023
1 parent ab87e2b commit b6fa8c9
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
2 changes: 1 addition & 1 deletion web/app/components/doc/tile.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="group relative">
<div class="group relative" ...attributes>
<LinkTo
@route="authenticated.document"
@model={{@docID}}
Expand Down
1 change: 1 addition & 0 deletions web/app/components/doc/tile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Component from "@glimmer/component";

interface DocTileComponentSignature {
Element: HTMLDivElement;
Args: {
avatar?: string;
docID?: string;
Expand Down
14 changes: 7 additions & 7 deletions web/app/services/recently-viewed-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ export default class RecentlyViewedDocsService extends Service {
let docResponses = await Promise.allSettled(
(this.index as IndexedDoc[]).map(async ({ id, isDraft }) => {
let endpoint = isDraft ? "drafts" : "documents";
let fetchResponse = await this.fetchSvc.fetch(
`/api/v1/${endpoint}/${id}`
);
return {
doc: await fetchResponse?.json(),
isDraft,
};
let doc = await this.fetchSvc
.fetch(`/api/v1/${endpoint}/${id}`)
.then((resp) => resp?.json());

doc.isDraft = isDraft;

return { doc, isDraft };
})
);
/**
Expand Down
1 change: 1 addition & 0 deletions web/app/templates/authenticated/dashboard.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<div class="tile-list">
{{#each this.recentDocs.all as |r|}}
<Doc::Tile
data-test-recently-viewed-doc
@isDraft={{r.doc.isDraft}}
@avatar={{get r.doc.ownerPhotos 0}}
@docID={{r.doc.objectID}}
Expand Down
24 changes: 24 additions & 0 deletions web/tests/acceptance/authenticated/dashboard-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { authenticateSession } from "ember-simple-auth/test-support";
import { MirageTestContext, setupMirage } from "ember-cli-mirage/test-support";
import { getPageTitle } from "ember-page-title/test-support";

const RECENTLY_VIEWED_DOC_SELECTOR = "[data-test-recently-viewed-doc]";

interface AuthenticatedDashboardRouteTestContext extends MirageTestContext {}

module("Acceptance | authenticated/dashboard", function (hooks) {
Expand All @@ -19,4 +21,26 @@ module("Acceptance | authenticated/dashboard", function (hooks) {
await visit("/dashboard");
assert.equal(getPageTitle(), "Dashboard | Hermes");
});

test("recently viewed docs have the correct href", async function (this: AuthenticatedDashboardRouteTestContext, assert) {
this.server.create("recently-viewed-doc", { id: "1", isDraft: false });
this.server.create("recently-viewed-doc", { id: "2", isDraft: true });

this.server.create("document", { objectID: "1", title: "Foo" });
this.server.create("document", { objectID: "2", title: "Bar" });

await visit("/dashboard");

assert.dom(RECENTLY_VIEWED_DOC_SELECTOR).exists({ count: 2 });

assert
.dom(`${RECENTLY_VIEWED_DOC_SELECTOR} a`)
.containsText("Foo")
.hasAttribute("href", "/document/1");

assert
.dom(`${RECENTLY_VIEWED_DOC_SELECTOR}:nth-child(2) a`)
.containsText("Bar")
.hasAttribute("href", "/document/2?draft=true");
});
});

0 comments on commit b6fa8c9

Please sign in to comment.