Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
asamuzaK committed Nov 2, 2024
1 parent e1bbfb6 commit a62bc0b
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 36 deletions.
47 changes: 35 additions & 12 deletions test/content-main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,43 @@ describe('content-main', () => {
'XMLSerializer'
];
// NOTE: not implemented in jsdom https://github.com/jsdom/jsdom/issues/1670
const isContentEditable = elm => {
let bool;
if (elm.hasAttribute('contenteditable')) {
const attr = elm.getAttribute('contenteditable');
if (attr === 'true' || attr === '') {
bool = true;
} else if (attr === 'false') {
bool = false;
}
const isContentEditable = node => {
if (node.nodeType !== 1) {
return false;
}
if (document && document.designMode === 'on') {
bool = true;
if (typeof node.isContentEditable === 'boolean') {
return node.isContentEditable;
} else if (node.ownerDocument.designMode === 'on') {
return true;
} else {
let attr;
if (node.hasAttribute('contenteditable')) {
attr = node.getAttribute('contenteditable');
} else {
attr = 'inherit';
}
switch (attr) {
case '':
case 'true': {
return true;
}
case 'plaintext-only': {
// FIXME:
// @see https://github.com/w3c/editing/issues/470
// @see https://github.com/whatwg/html/issues/10651
return true;
}
case 'false': {
return false;
}
default: {
if (node?.parentNode?.nodeType === 1) {
return isContentEditable(node.parentNode);
}
return false;
}
}
}
return !!bool;
};

beforeEach(() => {
Expand Down
47 changes: 35 additions & 12 deletions test/dom-util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,43 @@ describe('dom util', () => {
'XMLSerializer'
];
// NOTE: not implemented in jsdom https://github.com/jsdom/jsdom/issues/1670
const isContentEditable = elm => {
let bool;
if (elm.hasAttribute('contenteditable')) {
const attr = elm.getAttribute('contenteditable');
if (attr === 'true' || attr === '') {
bool = true;
} else if (attr === 'false') {
bool = false;
}
const isContentEditable = node => {
if (node.nodeType !== 1) {
return false;
}
if (document && document.designMode === 'on') {
bool = true;
if (typeof node.isContentEditable === 'boolean') {
return node.isContentEditable;
} else if (node.ownerDocument.designMode === 'on') {
return true;
} else {
let attr;
if (node.hasAttribute('contenteditable')) {
attr = node.getAttribute('contenteditable');
} else {
attr = 'inherit';
}
switch (attr) {
case '':
case 'true': {
return true;
}
case 'plaintext-only': {
// FIXME:
// @see https://github.com/w3c/editing/issues/470
// @see https://github.com/whatwg/html/issues/10651
return true;
}
case 'false': {
return false;
}
default: {
if (node?.parentNode?.nodeType === 1) {
return isContentEditable(node.parentNode);
}
return false;
}
}
}
return !!bool;
};

beforeEach(() => {
Expand Down
47 changes: 35 additions & 12 deletions test/live-edit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,43 @@ describe('live-edit', () => {
'XMLSerializer'
];
// NOTE: not implemented in jsdom https://github.com/jsdom/jsdom/issues/1670
const isContentEditable = elm => {
let bool;
if (elm.hasAttribute('contenteditable')) {
const attr = elm.getAttribute('contenteditable');
if (attr === 'true' || attr === '') {
bool = true;
} else if (attr === 'false') {
bool = false;
}
const isContentEditable = node => {
if (node.nodeType !== 1) {
return false;
}
if (document && document.designMode === 'on') {
bool = true;
if (typeof node.isContentEditable === 'boolean') {
return node.isContentEditable;
} else if (node.ownerDocument.designMode === 'on') {
return true;
} else {
let attr;
if (node.hasAttribute('contenteditable')) {
attr = node.getAttribute('contenteditable');
} else {
attr = 'inherit';
}
switch (attr) {
case '':
case 'true': {
return true;
}
case 'plaintext-only': {
// FIXME:
// @see https://github.com/w3c/editing/issues/470
// @see https://github.com/whatwg/html/issues/10651
return true;
}
case 'false': {
return false;
}
default: {
if (node?.parentNode?.nodeType === 1) {
return isContentEditable(node.parentNode);
}
return false;
}
}
}
return !!bool;
};

beforeEach(() => {
Expand Down

0 comments on commit a62bc0b

Please sign in to comment.