webpack/scenes/Subscriptions/__tests__/SubscriptionsPage.test.js in katello-3.15.0.rc1.3 vs webpack/scenes/Subscriptions/__tests__/SubscriptionsPage.test.js in katello-3.15.0.rc2
- old
+ new
@@ -13,13 +13,21 @@
const loadTables = () => new Promise((resolve) => {
resolve();
});
+const pollTasks = jest.fn();
+const handleTask = jest.fn();
+
+afterEach(() => {
+ pollTasks.mockClear();
+ handleTask.mockClear();
+});
+
describe('subscriptions page', () => {
const noop = () => {};
- const organization = { owner_details: { upstreamConsumer: 'blah' } };
+ const organization = { owner_details: { upstreamConsumer: {} } };
const page = shallow(<SubscriptionsPage
setModalOpen={noop}
setModalClosed={noop}
organization={organization}
subscriptions={successState}
@@ -29,24 +37,25 @@
loadTableColumns={loadTableColumns}
createColumns={createColumns}
updateColumns={updateColumns}
loadSubscriptions={loadSubscriptions}
updateQuantity={updateQuantity}
+ handleTask={handleTask}
pollTaskUntilDone={noop}
pollBulkSearch={noop}
+ pollTasks={pollTasks}
+ cancelPollTasks={noop}
deleteSubscriptions={() => {}}
resetTasks={noop}
uploadManifest={noop}
deleteManifest={noop}
refreshManifest={noop}
updateSearchQuery={noop}
openManageManifestModal={noop}
closeManageManifestModal={noop}
openDeleteModal={noop}
closeDeleteModal={noop}
- openTaskModal={noop}
- closeTaskModal={noop}
disableDeleteButton={noop}
enableDeleteButton={noop}
/>);
const permissionDeniedPage = shallow(<SubscriptionsPage
@@ -60,24 +69,25 @@
loadTableColumns={loadTableColumns}
createColumns={createColumns}
updateColumns={updateColumns}
loadSubscriptions={loadSubscriptions}
updateQuantity={updateQuantity}
+ handleTask={handleTask}
pollTaskUntilDone={noop}
pollBulkSearch={noop}
+ pollTasks={pollTasks}
+ cancelPollTasks={noop}
deleteSubscriptions={() => {}}
resetTasks={noop}
uploadManifest={noop}
deleteManifest={noop}
refreshManifest={noop}
updateSearchQuery={noop}
openManageManifestModal={noop}
closeManageManifestModal={noop}
openDeleteModal={noop}
closeDeleteModal={noop}
- openTaskModal={noop}
- closeTaskModal={noop}
disableDeleteButton={noop}
enableDeleteButton={noop}
/>);
it('should render', async () => {
@@ -87,12 +97,29 @@
it('should render <PermissionDenied /> when permissions are missing', async () => {
expect(toJson(permissionDeniedPage)).toMatchSnapshot();
});
it('should poll tasks when org changes', async () => {
- jest.spyOn(page.instance(), 'pollTasks');
-
page.setProps({ organization: { id: 1 } });
- expect(page.instance().pollTasks).toHaveBeenCalled();
+ expect(pollTasks).toHaveBeenCalled();
+ });
+
+ it('should not poll tasks if org has not changed', async () => {
+ page.setProps({ simpleContentAccess: true });
+
+ expect(pollTasks).not.toHaveBeenCalled();
+ });
+
+ it('should handle its task', async () => {
+ const mockTask = {
+ id: '12345',
+ humanized: {
+ action: 'Manifest Refresh',
+ },
+ };
+
+ page.setProps({ task: mockTask });
+
+ expect(handleTask).toHaveBeenCalledWith(mockTask);
});
});