[15 min fix] Fixed broken share button on article page. (#13688)

This commit is contained in:
Nick Taylor 2021-05-07 06:33:30 -04:00 committed by GitHub
parent 5462e0a1f9
commit c48e31731d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 8 deletions

View file

@ -50,6 +50,7 @@ function initializeCommentDropdown() {
var isCopyIconChild = copyIcon && copyIcon.contains(event.target);
return !(
event.target.matches('.dropdown-icon') ||
event.target.parentElement.classList.contains('dropdown-icon') ||
event.target.matches('.dropbtn') ||
event.target.matches('clipboard-copy') ||
isCopyIconChild ||
@ -85,7 +86,7 @@ function initializeCommentDropdown() {
}
}
function initializeCommentEvents(commentsContainer) {
function initializeDropDownClick(dropdownOrDropdownContainer) {
return (event) => {
const { target } = event;
const button = (function getButton(potentialButton) {
@ -93,7 +94,7 @@ function initializeCommentDropdown() {
!potentialButton.classList.contains('dropbtn') ||
!potentialButton
) {
if (potentialButton === commentsContainer) {
if (potentialButton === dropdownOrDropdownContainer) {
break;
}
@ -156,14 +157,16 @@ function initializeCommentDropdown() {
}
const commentsContainer = document.getElementById('comment-trees-container');
const articleShowMoreButton = document.getElementById(
'article-show-more-button',
);
// We only want to add an event listener for the click once
if (commentsContainer && !commentsContainer.dataset.initialized) {
commentsContainer.dataset.initialized = true;
commentsContainer.addEventListener(
'click',
initializeCommentEvents(commentsContainer),
);
for (const element of [commentsContainer, articleShowMoreButton]) {
if (element && !element.dataset.initialized) {
element.dataset.initialized = true;
element.addEventListener('click', initializeDropDownClick(element));
}
}
setTimeout(function addListeners() {

View file

@ -0,0 +1,35 @@
describe('Post sidebar actions', () => {
beforeEach(() => {
cy.testSetup();
cy.fixture('users/articleEditorV2User.json').as('user');
cy.get('@user').then((user) => {
cy.loginUser(user).then(() => {
cy.createArticle({
title: 'Test Article',
tags: ['beginner', 'ruby', 'go'],
content: `This is a test article's contents.`,
published: true,
}).then((response) => {
cy.visit(response.body.current_state_path);
});
});
});
});
it('should open the share menu for the post', () => {
cy.findByRole('button', { name: /^Toggle dropdown menu$/i }).click();
cy.findByTitle(/^Copy article link to the clipboard$/i);
cy.findByRole('link', { name: /^Share to Twitter$/i });
cy.findByRole('link', { name: /^Share to LinkedIn$/i });
cy.findByRole('link', { name: /^Share to Reddit$/i });
cy.findByRole('link', { name: /^Share to Hacker News$/i });
cy.findByRole('link', { name: /^Share to Facebook$/i });
// There is a report abuse link a the bottom of the post too
cy.findAllByRole('link', { name: /^Report Abuse$/i }).should(
'have.length',
2,
);
});
});