diff --git a/awx/ui_next/src/screens/Template/shared/LabelSelect.test.jsx b/awx/ui_next/src/screens/Template/shared/LabelSelect.test.jsx
index ebbaba2b4c..07bf0c0a62 100644
--- a/awx/ui_next/src/screens/Template/shared/LabelSelect.test.jsx
+++ b/awx/ui_next/src/screens/Template/shared/LabelSelect.test.jsx
@@ -1,9 +1,53 @@
import React from 'react';
import { mount } from 'enzyme';
+import { LabelsAPI } from '@api';
+import { sleep} from '@testUtils/testUtils';
import LabelSelect from './LabelSelect';
+jest.mock('@api');
+
+const options = [
+ { id: 1, name: 'one' },
+ { id: 2, name: 'two' },
+];
+
describe('', () => {
- test('should', () => {
- wrapper = mount();
- })
+ afterEach(() => {
+ jest.resetAllMocks();
+ });
+
+ test('should fetch labels', async () => {
+ LabelsAPI.read.mockReturnValue({
+ data: { results: options },
+ });
+ const wrapper = mount();
+ await sleep(1);
+ wrapper.update();
+
+ expect(LabelsAPI.read).toHaveBeenCalledTimes(1);
+ expect(wrapper.find('MultiSelect').prop('options')).toEqual(options);
+ });
+
+ test('should fetch two pages labels if present', async () => {
+ LabelsAPI.read.mockReturnValueOnce({
+ data: {
+ results: options,
+ next: '/foo?page=2',
+ },
+ });
+ LabelsAPI.read.mockReturnValueOnce({
+ data: {
+ results: options,
+ },
+ });
+ const wrapper = mount();
+ await sleep(1);
+ wrapper.update();
+
+ expect(LabelsAPI.read).toHaveBeenCalledTimes(2);
+ expect(wrapper.find('MultiSelect').prop('options')).toEqual([
+ ...options,
+ ...options
+ ]);
+ });
});
diff --git a/awx/ui_next/src/screens/Template/shared/PlaybookSelect.test.jsx b/awx/ui_next/src/screens/Template/shared/PlaybookSelect.test.jsx
index a7cb28c491..0a2d979fff 100644
--- a/awx/ui_next/src/screens/Template/shared/PlaybookSelect.test.jsx
+++ b/awx/ui_next/src/screens/Template/shared/PlaybookSelect.test.jsx
@@ -12,6 +12,10 @@ describe('', () => {
});
});
+ afterEach(() => {
+ jest.resetAllMocks();
+ })
+
test('should reload playbooks when project value changes', () => {
const wrapper = mountWithContexts(