Skip to content
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
18 changes: 18 additions & 0 deletions app/serializers/crate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import ApplicationSerializer from './application';

const SKIP_NULL_FIELDS = new Set(['categories', 'keywords']);

export default class CrateSerializer extends ApplicationSerializer {
isNewSerializerAPI = true;

Expand All @@ -10,4 +12,20 @@ export default class CrateSerializer extends ApplicationSerializer {

return super.extractRelationships(...arguments);
}

normalizeQueryResponse(_store, _modelClass, payload) {
// We don't want existing relationships overwritten by results with null values.
// See: https://github.com/rust-lang/crates.io/issues/10711
if (payload.crates) {
payload.crates = payload.crates.map(crate => {
for (const rel of SKIP_NULL_FIELDS) {
if (crate[rel] === null) {
delete crate[rel];
}
}
return crate;
});
}
return super.normalizeQueryResponse(...arguments);
}
}
29 changes: 29 additions & 0 deletions e2e/acceptance/crate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,33 @@ test.describe('Acceptance | crate page', { tag: '@acceptance' }, () => {
await expect(page).toHaveURL('/crates/nanomsg');
await expect(page.locator('[data-test-keyword]')).toBeVisible();
});

test('keywords are shown when navigating from crate to keywords, and then back to crate', async ({ page, msw }) => {
loadFixtures(msw.db);

await page.goto('/crates/nanomsg');
await expect(page.locator('[data-test-keyword]')).toBeVisible();

await page.getByRole('link', { name: '#network', exact: true }).click();
await expect(page).toHaveURL('/keywords/network');
await page.getByRole('link', { name: 'nanomsg', exact: true }).click();

await expect(page).toHaveURL('/crates/nanomsg');
await expect(page.locator('[data-test-keyword]')).toBeVisible();
});

test('keywords are shown when navigating from crate to searchs, and then back to crate', async ({ page, msw }) => {
loadFixtures(msw.db);

await page.goto('/crates/nanomsg');
await expect(page.locator('[data-test-keyword]')).toBeVisible();

await page.fill('[data-test-search-input]', 'nanomsg');
await page.locator('[data-test-search-form]').getByRole('button', { name: 'Submit' }).click();
await expect(page).toHaveURL('/search?q=nanomsg');
await page.getByRole('link', { name: 'nanomsg', exact: true }).click();

await expect(page).toHaveURL('/crates/nanomsg');
await expect(page.locator('[data-test-keyword]')).toBeVisible();
});
});
31 changes: 30 additions & 1 deletion tests/acceptance/crate-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { click, currentRouteName, currentURL, waitFor } from '@ember/test-helpers';
import { click, currentRouteName, currentURL, fillIn, triggerEvent, waitFor } from '@ember/test-helpers';
import { module, skip, test } from 'qunit';

import { loadFixtures } from '@crates-io/msw/fixtures.js';
Expand Down Expand Up @@ -271,4 +271,33 @@ module('Acceptance | crate page', function (hooks) {
assert.strictEqual(currentURL(), '/crates/nanomsg');
assert.dom('[data-test-keyword]').exists();
});

test('keywords are shown when navigating from crate to keywords, and then back to crate', async function (assert) {
loadFixtures(this.db);

await visit('/crates/nanomsg');
assert.dom('[data-test-keyword]').exists();

await click('[data-test-keyword="network"]');
assert.strictEqual(currentURL(), '/keywords/network');
await click('[href="/crates/nanomsg"]');

assert.strictEqual(currentURL(), '/crates/nanomsg');
assert.dom('[data-test-keyword]').exists();
});

test('keywords are shown when navigating from crate to searchs, and then back to crate', async function (assert) {
loadFixtures(this.db);

await visit('/crates/nanomsg');
assert.dom('[data-test-keyword]').exists();

await fillIn('[data-test-search-input]', 'nanomsg');
await triggerEvent('[data-test-search-form]', 'submit');
assert.strictEqual(currentURL(), '/search?q=nanomsg');
await click('[href="/crates/nanomsg"]');

assert.strictEqual(currentURL(), '/crates/nanomsg');
assert.dom('[data-test-keyword]').exists();
});
});
Loading