Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/user_popovers_spec.js')
-rw-r--r--spec/frontend/user_popovers_spec.js26
1 files changed, 23 insertions, 3 deletions
diff --git a/spec/frontend/user_popovers_spec.js b/spec/frontend/user_popovers_spec.js
index 7c9c3d69efa..5c6053f413f 100644
--- a/spec/frontend/user_popovers_spec.js
+++ b/spec/frontend/user_popovers_spec.js
@@ -6,6 +6,19 @@ describe('User Popovers', () => {
preloadFixtures(fixtureTemplate);
const selector = '.js-user-link, .gfm-project_member';
+ const findFixtureLinks = () => {
+ return Array.from(document.querySelectorAll(selector)).filter(
+ ({ dataset }) => dataset.user || dataset.userId,
+ );
+ };
+ const createUserLink = () => {
+ const link = document.createElement('a');
+
+ link.classList.add('js-user-link');
+ link.setAttribute('data-user', '1');
+
+ return link;
+ };
const dummyUser = { name: 'root' };
const dummyUserStatus = { message: 'active' };
@@ -37,13 +50,20 @@ describe('User Popovers', () => {
});
it('initializes a popover for each user link with a user id', () => {
- const linksWithUsers = Array.from(document.querySelectorAll(selector)).filter(
- ({ dataset }) => dataset.user || dataset.userId,
- );
+ const linksWithUsers = findFixtureLinks();
expect(linksWithUsers.length).toBe(popovers.length);
});
+ it('adds popovers to user links added to the DOM tree after the initial call', async () => {
+ document.body.appendChild(createUserLink());
+ document.body.appendChild(createUserLink());
+
+ const linksWithUsers = findFixtureLinks();
+
+ expect(linksWithUsers.length).toBe(popovers.length + 2);
+ });
+
it('does not initialize the user popovers twice for the same element', () => {
const newPopovers = initUserPopovers(document.querySelectorAll(selector));
const samePopovers = popovers.every((popover, index) => newPopovers[index] === popover);