From 1cb0ec8f0d2b45ef0a9428e77cc99bb054d10310 Mon Sep 17 00:00:00 2001 From: Gustav Hansen Date: Wed, 5 Jul 2023 12:32:38 +0200 Subject: [PATCH] Chore: Add tests for getFeature --- .../useLicenseLimits/tests/index.test.js | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/packages/core/admin/ee/admin/hooks/useLicenseLimits/tests/index.test.js b/packages/core/admin/ee/admin/hooks/useLicenseLimits/tests/index.test.js index 09172a416a..186a2cc66d 100644 --- a/packages/core/admin/ee/admin/hooks/useLicenseLimits/tests/index.test.js +++ b/packages/core/admin/ee/admin/hooks/useLicenseLimits/tests/index.test.js @@ -18,6 +18,11 @@ const server = setupServer( ctx.json({ data: { attribute: 1, + + features: [ + { name: 'without-options' }, + { name: 'with-options', options: { something: true } }, + ], }, }) ); @@ -64,8 +69,9 @@ const setup = (...args) => describe('useLicenseLimits', () => { beforeAll(() => server.listen()); - afterEach(() => { - server.resetHandlers(); + afterAll(() => server.resetHandlers()); + + beforeEach(() => { jest.clearAllMocks(); }); @@ -76,9 +82,12 @@ describe('useLicenseLimits', () => { await waitFor(() => expect(result.current.isLoading).toBeFalsy()); - expect(result.current.license).toEqual({ - attribute: 1, - }); + expect(result.current.license).toEqual( + expect.objectContaining({ + attribute: 1, + features: expect.any(Array), + }) + ); }); it.each(['canRead', 'canCreate', 'canUpdate', 'canDelete'])( @@ -93,7 +102,7 @@ describe('useLicenseLimits', () => { allowedActions[permission] = false; - useRBAC.mockReturnValue({ + useRBAC.mockReturnValueOnce({ isLoading: false, allowedActions, }); @@ -105,4 +114,16 @@ describe('useLicenseLimits', () => { 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 }); + }); });