mirror of
https://github.com/strapi/strapi.git
synced 2025-09-22 23:09:47 +00:00
Chore: Add tests for getFeature
This commit is contained in:
parent
f4720e22db
commit
1cb0ec8f0d
@ -18,6 +18,11 @@ const server = setupServer(
|
|||||||
ctx.json({
|
ctx.json({
|
||||||
data: {
|
data: {
|
||||||
attribute: 1,
|
attribute: 1,
|
||||||
|
|
||||||
|
features: [
|
||||||
|
{ name: 'without-options' },
|
||||||
|
{ name: 'with-options', options: { something: true } },
|
||||||
|
],
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@ -64,8 +69,9 @@ const setup = (...args) =>
|
|||||||
describe('useLicenseLimits', () => {
|
describe('useLicenseLimits', () => {
|
||||||
beforeAll(() => server.listen());
|
beforeAll(() => server.listen());
|
||||||
|
|
||||||
afterEach(() => {
|
afterAll(() => server.resetHandlers());
|
||||||
server.resetHandlers();
|
|
||||||
|
beforeEach(() => {
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -76,9 +82,12 @@ describe('useLicenseLimits', () => {
|
|||||||
|
|
||||||
await waitFor(() => expect(result.current.isLoading).toBeFalsy());
|
await waitFor(() => expect(result.current.isLoading).toBeFalsy());
|
||||||
|
|
||||||
expect(result.current.license).toEqual({
|
expect(result.current.license).toEqual(
|
||||||
attribute: 1,
|
expect.objectContaining({
|
||||||
});
|
attribute: 1,
|
||||||
|
features: expect.any(Array),
|
||||||
|
})
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it.each(['canRead', 'canCreate', 'canUpdate', 'canDelete'])(
|
it.each(['canRead', 'canCreate', 'canUpdate', 'canDelete'])(
|
||||||
@ -93,7 +102,7 @@ describe('useLicenseLimits', () => {
|
|||||||
|
|
||||||
allowedActions[permission] = false;
|
allowedActions[permission] = false;
|
||||||
|
|
||||||
useRBAC.mockReturnValue({
|
useRBAC.mockReturnValueOnce({
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
allowedActions,
|
allowedActions,
|
||||||
});
|
});
|
||||||
@ -105,4 +114,16 @@ describe('useLicenseLimits', () => {
|
|||||||
expect(result.current.license).toEqual({});
|
expect(result.current.license).toEqual({});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
it('exposes a getFeature() method as a shortcut to feature options', async () => {
|
||||||
|
const { result } = setup();
|
||||||
|
|
||||||
|
expect(result.current.getFeature('without-options')).toStrictEqual({});
|
||||||
|
expect(result.current.getFeature('with-options')).toStrictEqual({});
|
||||||
|
|
||||||
|
await waitFor(() => expect(result.current.isLoading).toBeFalsy());
|
||||||
|
|
||||||
|
expect(result.current.getFeature('without-options')).toStrictEqual({});
|
||||||
|
expect(result.current.getFeature('with-options')).toStrictEqual({ something: true });
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user