diff --git a/ee/app/assets/javascripts/projects/custom_project_templates.js b/ee/app/assets/javascripts/projects/custom_project_templates.js index d631458df2b16d8ac553468217cda8aee470c2e9..44a3acf232047a2b4f7826bf737de13fb7dff342 100644 --- a/ee/app/assets/javascripts/projects/custom_project_templates.js +++ b/ee/app/assets/javascripts/projects/custom_project_templates.js @@ -135,11 +135,31 @@ export default () => { const groupNavElement = document.querySelector('.js-custom-group-project-templates-nav-link'); const groupTabContent = document.querySelector(GROUP_TAB_CONTENT_SELECTOR); + const initPagination = (content, handler) => { + // This is a temporary workaround as part of a P1 bug fix + // In a future iteration the pagination should be implemented on the frontend + const el = content.querySelector('.js-custom-group-project-templates-tab-content .pagination'); + if (!el) return; + + el.querySelectorAll('a').forEach((anchor) => anchor.addEventListener('click', handler)); + }; + + const handlePaginate = async (e) => { + e.preventDefault(); + const response = await axios.get(e.currentTarget.href); + const secureContent = sanitize(response.data); + + groupTabContent.innerHTML = secureContent; + initPagination(groupTabContent, handlePaginate); + bindEvents(); + }; + const fetchHtmlForTabContent = async (content) => { const response = await axios.get(content.dataset.initialTemplates); const secureContent = sanitize(response.data); // eslint-disable-next-line no-param-reassign content.innerHTML = secureContent; + initPagination(groupTabContent, handlePaginate); bindEvents(); }; diff --git a/ee/spec/frontend/projects/custom_project_templates_spec.js b/ee/spec/frontend/projects/custom_project_templates_spec.js new file mode 100644 index 0000000000000000000000000000000000000000..aa79c0dbf8cb79f741cdc9b604a94a760f083e5a --- /dev/null +++ b/ee/spec/frontend/projects/custom_project_templates_spec.js @@ -0,0 +1,59 @@ +import MockAdapter from 'axios-mock-adapter'; +import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures'; +import axios from '~/lib/utils/axios_utils'; +import { HTTP_STATUS_OK } from '~/lib/utils/http_status'; +import { TEST_HOST } from 'helpers/test_constants'; +import waitForPromises from 'helpers/wait_for_promises'; +import initCustomProjectTemplates from 'ee/projects/custom_project_templates'; + +const TAB_LINK_SELECTOR = '.js-custom-group-project-templates-nav-link'; +const TAB_CONTENT_SELECTOR = '.js-custom-group-project-templates-tab-content'; +const ENDPOINT = `${TEST_HOST}/users/root/available_group_templates`; +const INITIAL_CONTENT = 'initial content'; +const NEXT_PAGE_CONTENT = 'page 2 content'; + +describe('initCustomProjectTemplates', () => { + const generateContent = (content) => { + return ` +