Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update popup #168

Merged
merged 1 commit into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/mjs/popup-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,20 +211,24 @@ export const updateMenu = async data => {
if (isObjectNotEmpty(data)) {
const { contextInfo: info } = data;
if (info) {
const { canonicalUrl, content, isLink, title, url } = info;
const elm = document.getElementById(LINK_DETAILS);
const nodes = document.querySelectorAll(LINK_MENU);
const { canonicalUrl, content, isLink, selectionText, title, url } = info;
contextInfo.canonicalUrl = canonicalUrl;
contextInfo.content = content;
contextInfo.isLink = !!isLink;
contextInfo.selectionText = selectionText;
contextInfo.title = title;
contextInfo.url = url;
const elm = document.getElementById(LINK_DETAILS);
if (isLink) {
elm.removeAttribute(ATTR_HIDDEN);
document.getElementById(CONTENT_LINK).value = content;
} else {
elm.setAttribute(ATTR_HIDDEN, ATTR_HIDDEN);
}
if (selectionText) {
document.getElementById(CONTENT_PAGE).value = selectionText;
}
const nodes = document.querySelectorAll(LINK_MENU);
for (const node of nodes) {
if (isLink) {
node.removeAttribute(ATTR_DISABLED);
Expand Down
46 changes: 36 additions & 10 deletions test/popup-main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,17 +541,27 @@ describe('popup-main', () => {
const func = mjs.updateMenu;
beforeEach(() => {
const div = document.createElement('div');
const elm = document.createElement('button');
const elm2 = document.createElement('button');
const elm3 = document.createElement('input');
const div2 = document.createElement('div');
const button = document.createElement('button');
const button2 = document.createElement('button');
const button3 = document.createElement('button');
const button4 = document.createElement('button');
const input = document.createElement('input');
const input2 = document.createElement('input');
const body = document.querySelector('body');
input.id = CONTENT_LINK;
div.id = 'copyLinkDetails';
div.appendChild(elm);
div.appendChild(elm2);
div.setAttribute('hidden', 'hidden');
elm3.id = CONTENT_LINK;
div.appendChild(input);
div.appendChild(button);
div.appendChild(button2);
body.appendChild(div);
body.appendChild(elm3);
input2.id = CONTENT_PAGE;
div2.id = 'copyPageDetails';
div2.appendChild(input2);
div2.appendChild(button3);
div2.appendChild(button4);
body.appendChild(div2);
});

it('should not set attr', async () => {
Expand All @@ -578,7 +588,7 @@ describe('popup-main', () => {

it('should set attr but not value', async () => {
const elm = document.getElementById('copyLinkDetails');
const items = document.querySelectorAll('button');
const items = document.querySelectorAll('#copyLinkDetails button');
const contentLink = document.getElementById(CONTENT_LINK);
const data = {
contextInfo: {
Expand All @@ -599,7 +609,7 @@ describe('popup-main', () => {

it('should set attr but not value', async () => {
const elm = document.getElementById('copyLinkDetails');
const items = document.querySelectorAll('button');
const items = document.querySelectorAll('#copyLinkDetails button');
const contentLink = document.getElementById(CONTENT_LINK);
const data = {
contextInfo: {
Expand All @@ -620,7 +630,7 @@ describe('popup-main', () => {

it('should set attr and value', async () => {
const elm = document.getElementById('copyLinkDetails');
const items = document.querySelectorAll('button');
const items = document.querySelectorAll('#copyLinkDetails button');
const contentLink = document.getElementById(CONTENT_LINK);
const data = {
contextInfo: {
Expand All @@ -641,6 +651,22 @@ describe('popup-main', () => {
}
assert.strictEqual(contentLink.value, 'foo', 'value link');
});

it('should set value', async () => {
const contentPage = document.getElementById(CONTENT_PAGE);
const data = {
contextInfo: {
canonicalUrl: null,
content: '',
isLink: false,
selectionText: 'baz qux',
title: 'bar',
url: 'https://example.com'
}
};
await func(data);
assert.strictEqual(contentPage.value, 'baz qux', 'value pqge');
});
});

describe('prepare tab', () => {
Expand Down