Skip to content

Commit b4c801d

Browse files
authored
routes/crate: Fetch crate when peeked crate lacks included values (#10666)
1 parent 39ee9c5 commit b4c801d

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

app/routes/crate.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@ export default class CrateRoute extends Route {
1212
let crateName = params.crate_id;
1313

1414
try {
15-
return this.store.peekRecord('crate', crateName) || (await this.store.queryRecord('crate', { name: crateName }));
15+
// We would like the peeked crate to include information (such as keywords) for further
16+
// processing. Currently, we determine this by checking if associated versions exist,
17+
// as default_version is included in the queryRecord call.
18+
// See: https://github.com/rust-lang/crates.io/issues/10663
19+
let crate = this.store.peekRecord('crate', crateName);
20+
if (!crate || crate.hasMany('versions').value() == null) {
21+
crate = await this.store.queryRecord('crate', { name: crateName });
22+
}
23+
return crate;
1624
} catch (error) {
1725
if (error instanceof NotFoundError) {
1826
let title = `${crateName}: Crate not found`;

e2e/acceptance/crate.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,4 +245,14 @@ test.describe('Acceptance | crate page', { tag: '@acceptance' }, () => {
245245

246246
await expect(page).toHaveURL('/crates/nanomsg/settings');
247247
});
248+
249+
test('keywords are shown when navigating from search', async ({ page, msw }) => {
250+
loadFixtures(msw.db);
251+
252+
await page.goto('/search?q=nanomsg');
253+
await page.getByRole('link', { name: 'nanomsg', exact: true }).click();
254+
255+
await expect(page).toHaveURL('/crates/nanomsg');
256+
await expect(page.locator('[data-test-keyword]')).toBeVisible();
257+
});
248258
});

tests/acceptance/crate-test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,4 +249,14 @@ module('Acceptance | crate page', function (hooks) {
249249

250250
assert.strictEqual(currentURL(), '/crates/nanomsg/settings');
251251
});
252+
253+
test('keywords are shown when navigating from search', async function (assert) {
254+
loadFixtures(this.db);
255+
256+
await visit('/search?q=nanomsg');
257+
await click('[data-test-crate-link]');
258+
259+
assert.strictEqual(currentURL(), '/crates/nanomsg');
260+
assert.dom('[data-test-keyword]').exists();
261+
});
252262
});

0 commit comments

Comments
 (0)