From f34bd632d897de4154320a2cd49793ed477aa3e4 Mon Sep 17 00:00:00 2001 From: mabashian Date: Tue, 8 Oct 2019 16:10:55 -0400 Subject: [PATCH] Adds unit test coverage for add button rbac on several lists --- .../InventoryList/InventoryList.test.jsx | 44 +++++++++++++++++- .../OrganizationList.test.jsx | 45 ++++++++++++++++++- .../Project/ProjectList/ProjectList.test.jsx | 44 +++++++++++++++++- 3 files changed, 130 insertions(+), 3 deletions(-) diff --git a/awx/ui_next/src/screens/Inventory/InventoryList/InventoryList.test.jsx b/awx/ui_next/src/screens/Inventory/InventoryList/InventoryList.test.jsx index c92966c62b..c312f92b7f 100644 --- a/awx/ui_next/src/screens/Inventory/InventoryList/InventoryList.test.jsx +++ b/awx/ui_next/src/screens/Inventory/InventoryList/InventoryList.test.jsx @@ -128,7 +128,10 @@ describe('', () => { InventoriesAPI.readOptions.mockResolvedValue({ data: { - actions: [], + actions: { + GET: {}, + POST: {}, + }, }, }); }); @@ -280,4 +283,43 @@ describe('', () => { done(); }); + + test('Add button shown for users without ability to POST', async done => { + const wrapper = mountWithContexts(); + await waitForElement( + wrapper, + 'InventoriesList', + el => el.state('hasContentLoading') === true + ); + await waitForElement( + wrapper, + 'InventoriesList', + el => el.state('hasContentLoading') === false + ); + expect(wrapper.find('ToolbarAddButton').length).toBe(1); + done(); + }); + + test('Add button hidden for users without ability to POST', async done => { + InventoriesAPI.readOptions.mockResolvedValue({ + data: { + actions: { + GET: {}, + }, + }, + }); + const wrapper = mountWithContexts(); + await waitForElement( + wrapper, + 'InventoriesList', + el => el.state('hasContentLoading') === true + ); + await waitForElement( + wrapper, + 'InventoriesList', + el => el.state('hasContentLoading') === false + ); + expect(wrapper.find('ToolbarAddButton').length).toBe(0); + done(); + }); }); diff --git a/awx/ui_next/src/screens/Organization/OrganizationList/OrganizationList.test.jsx b/awx/ui_next/src/screens/Organization/OrganizationList/OrganizationList.test.jsx index c56579b99c..a07556f9eb 100644 --- a/awx/ui_next/src/screens/Organization/OrganizationList/OrganizationList.test.jsx +++ b/awx/ui_next/src/screens/Organization/OrganizationList/OrganizationList.test.jsx @@ -73,7 +73,10 @@ describe('', () => { OrganizationsAPI.readOptions = () => Promise.resolve({ data: { - actions: [], + actions: { + GET: {}, + POST: {}, + }, }, }); }); @@ -176,4 +179,44 @@ describe('', () => { ); done(); }); + + test('Add button shown for users without ability to POST', async done => { + wrapper = mountWithContexts(); + await waitForElement( + wrapper, + 'OrganizationsList', + el => el.state('hasContentLoading') === true + ); + await waitForElement( + wrapper, + 'OrganizationsList', + el => el.state('hasContentLoading') === false + ); + expect(wrapper.find('ToolbarAddButton').length).toBe(1); + done(); + }); + + test('Add button hidden for users without ability to POST', async done => { + OrganizationsAPI.readOptions = () => + Promise.resolve({ + data: { + actions: { + GET: {}, + }, + }, + }); + wrapper = mountWithContexts(); + await waitForElement( + wrapper, + 'OrganizationsList', + el => el.state('hasContentLoading') === true + ); + await waitForElement( + wrapper, + 'OrganizationsList', + el => el.state('hasContentLoading') === false + ); + expect(wrapper.find('ToolbarAddButton').length).toBe(0); + done(); + }); }); diff --git a/awx/ui_next/src/screens/Project/ProjectList/ProjectList.test.jsx b/awx/ui_next/src/screens/Project/ProjectList/ProjectList.test.jsx index d37eaca50e..e44970edf0 100644 --- a/awx/ui_next/src/screens/Project/ProjectList/ProjectList.test.jsx +++ b/awx/ui_next/src/screens/Project/ProjectList/ProjectList.test.jsx @@ -71,7 +71,10 @@ describe('', () => { ProjectsAPI.readOptions.mockResolvedValue({ data: { - actions: [], + actions: { + GET: {}, + POST: {}, + }, }, }); }); @@ -219,4 +222,43 @@ describe('', () => { done(); }); + + test('Add button shown for users without ability to POST', async done => { + const wrapper = mountWithContexts(); + await waitForElement( + wrapper, + 'ProjectsList', + el => el.state('hasContentLoading') === true + ); + await waitForElement( + wrapper, + 'ProjectsList', + el => el.state('hasContentLoading') === false + ); + expect(wrapper.find('ToolbarAddButton').length).toBe(1); + done(); + }); + + test('Add button hidden for users without ability to POST', async done => { + ProjectsAPI.readOptions.mockResolvedValue({ + data: { + actions: { + GET: {}, + }, + }, + }); + const wrapper = mountWithContexts(); + await waitForElement( + wrapper, + 'ProjectsList', + el => el.state('hasContentLoading') === true + ); + await waitForElement( + wrapper, + 'ProjectsList', + el => el.state('hasContentLoading') === false + ); + expect(wrapper.find('ToolbarAddButton').length).toBe(0); + done(); + }); });