mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-04-12 19:10:59 +00:00
The pages listed when browsing the /admin/pages/ explorer differed from the pages listed in the new React/admin API powered pop-out explorer. The latter did not pass the queryset through the 'construct_explorer_page_queryset' hook, so pages that should have been hidden were visible. Visiting these pages in the explorer could then lead to unexpected behaviours, as hidden sections of the site became browsable. A new `for_explorer=1` query parameter has been added to the admin API, which will pass the page queryset through the 'construct_explorer_page_queryset' hooks.
53 lines
1.5 KiB
JavaScript
53 lines
1.5 KiB
JavaScript
import { ADMIN_API } from '../config/wagtailConfig';
|
|
import { getPageChildren, getPage } from './admin';
|
|
import * as client from './client';
|
|
|
|
const stubResult = {
|
|
__types: {
|
|
test: {
|
|
verbose_name: 'Test',
|
|
},
|
|
},
|
|
items: [
|
|
{ meta: { type: 'test' } },
|
|
{ meta: { type: 'foo' } },
|
|
],
|
|
};
|
|
|
|
client.get = jest.fn(() => Promise.resolve(stubResult));
|
|
|
|
describe('admin API', () => {
|
|
describe('getPageChildren', () => {
|
|
it('works', () => {
|
|
getPageChildren(3);
|
|
expect(client.get).toBeCalledWith(`${ADMIN_API.PAGES}?child_of=3&for_explorer=1`);
|
|
});
|
|
|
|
it('#fields', () => {
|
|
getPageChildren(3, { fields: ['title', 'latest_revision_created_at'] });
|
|
// eslint-disable-next-line max-len
|
|
expect(client.get).toBeCalledWith(`${ADMIN_API.PAGES}?child_of=3&for_explorer=1&fields=title%2Clatest_revision_created_at`);
|
|
});
|
|
|
|
it('#onlyWithChildren', () => {
|
|
getPageChildren(3, { onlyWithChildren: true });
|
|
expect(client.get).toBeCalledWith(`${ADMIN_API.PAGES}?child_of=3&for_explorer=1&has_children=1`);
|
|
});
|
|
|
|
it('#offset', () => {
|
|
getPageChildren(3, { offset: 5 });
|
|
expect(client.get).toBeCalledWith(`${ADMIN_API.PAGES}?child_of=3&for_explorer=1&offset=5`);
|
|
});
|
|
});
|
|
|
|
describe('getPage', () => {
|
|
it('should return a result by with a default id argument', () => {
|
|
getPage(3);
|
|
expect(client.get).toBeCalledWith(`${ADMIN_API.PAGES}3/`);
|
|
});
|
|
});
|
|
|
|
afterEach(() => {
|
|
client.get.mockClear();
|
|
});
|
|
});
|