mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CodeMirror
synced 2024-12-12 14:25:06 +00:00
81ec0c292a
Use Codex design tokens where possible, and implement custom dark theming for things for which there is no suitable design token. This means we're changing the colors for light mode ever so slightly. We need to style the search panel for dark mode, so we might as well tackle T371436 and use CSS-only Codex components. The same is done for the "Go to line" panel (can be opened with Mod+Alt+g). The messages in this panel are now also localizable. The search panel (and goto line panel) are abstracted, with helpers to create the Codex components. These will not only be used here but also for the upcoming preferences panel (T359498). Visually, the search and goto panels were inspired by the 2017 editor and share a similar layout. CodeMirror similarly uses a more compact design than usual to maximize the real estate of the editor itself. Other changes: * Bump codemirror/search to get latest bug fixes * Remove stylelint ignorance and fix errors * Move CM5 styles to ext.CodeMirror.less * Move CM-specific styles out of mediawiki.less and into codemirror.less * Move WikiEditor-specific styles to codemirror.wikieditor.less (incidentally, these only apply to CodeMirror 6) * Correct qqq documentation; the "dialog" should be called a "panel" * extension.json: alphabetize list of messages Bug: T365311 Bug: T371436 Bug: T359498 Change-Id: I6a3bbc6bce4e490886753ff484e377c1763de456
95 lines
4.5 KiB
JavaScript
95 lines
4.5 KiB
JavaScript
const CodeMirrorPanel = require( '../../resources/codemirror.panel.js' );
|
|
|
|
// CodeMirrorPanel is tagged as abstract, but being JavaScript it isn't a
|
|
// "real" abstract class, so we can instantiate it directly for testing purposes.
|
|
const cmPanel = new CodeMirrorPanel();
|
|
|
|
describe( 'CodeMirrorPanel', () => {
|
|
it( 'should create a Codex TextInput', () => {
|
|
const [ inputWrapper, input ] = cmPanel.getTextInput( 'foo', 'bar', 'codemirror-find' );
|
|
expect( inputWrapper.className ).toBe( 'cdx-text-input cm-mw-panel--text-input' );
|
|
expect( input.className ).toBe( 'cdx-text-input__input' );
|
|
expect( input.type ).toBe( 'text' );
|
|
expect( input.name ).toBe( 'foo' );
|
|
// No i18n in unit tests, so we only check for the key.
|
|
expect( input.placeholder ).toBe( 'codemirror-find' );
|
|
expect( input.value ).toBe( 'bar' );
|
|
} );
|
|
|
|
it( 'should create a Codex Button with no icon', () => {
|
|
const buttonNoIcon = cmPanel.getButton( 'foo' );
|
|
expect( buttonNoIcon.tagName ).toBe( 'BUTTON' );
|
|
expect( buttonNoIcon.className ).toBe( 'cdx-button cm-mw-panel--button' );
|
|
expect( buttonNoIcon.type ).toBe( 'button' );
|
|
expect( buttonNoIcon.children.length ).toBe( 0 );
|
|
} );
|
|
|
|
it( 'should create a Codex button with an icon and a label', () => {
|
|
const buttonWithIcon = cmPanel.getButton( 'foo', 'bar' );
|
|
expect( buttonWithIcon.tagName ).toBe( 'BUTTON' );
|
|
expect( buttonWithIcon.className ).toBe( 'cdx-button cm-mw-panel--button' );
|
|
expect( buttonWithIcon.type ).toBe( 'button' );
|
|
expect( buttonWithIcon.children.length ).toBe( 1 );
|
|
const iconSpan = buttonWithIcon.children[ 0 ];
|
|
expect( iconSpan.tagName ).toBe( 'SPAN' );
|
|
expect( iconSpan.className ).toBe( 'cdx-button__icon cm-mw-icon--bar' );
|
|
expect( iconSpan.getAttribute( 'aria-hidden' ) ).toBe( 'true' );
|
|
} );
|
|
|
|
it( 'should create an icon-only Codex button', () => {
|
|
const buttonIconOnly = cmPanel.getButton( 'foo', 'bar', true );
|
|
expect( buttonIconOnly.tagName ).toBe( 'BUTTON' );
|
|
expect( buttonIconOnly.className ).toBe(
|
|
'cdx-button cm-mw-panel--button cdx-button--icon-only'
|
|
);
|
|
expect( buttonIconOnly.type ).toBe( 'button' );
|
|
expect( buttonIconOnly.children.length ).toBe( 1 );
|
|
expect( buttonIconOnly.getAttribute( 'aria-label' ) ).toBe( 'foo' );
|
|
expect( buttonIconOnly.title ).toBe( 'foo' );
|
|
const iconSpan = buttonIconOnly.children[ 0 ];
|
|
expect( iconSpan.tagName ).toBe( 'SPAN' );
|
|
expect( iconSpan.className ).toBe( 'cdx-button__icon cm-mw-icon--bar' );
|
|
expect( iconSpan.getAttribute( 'aria-hidden' ) ).toBeNull();
|
|
} );
|
|
|
|
it( 'should create a Codex Checkbox', () => {
|
|
const [ checkboxWrapper, checkbox ] = cmPanel.getCheckbox( 'foo', 'bar', true );
|
|
expect( checkboxWrapper.className ).toBe( 'cdx-checkbox cdx-checkbox--inline cm-mw-panel--checkbox' );
|
|
expect( checkboxWrapper.children.length ).toBe( 3 );
|
|
const labelWrapper = checkboxWrapper.children[ 2 ];
|
|
expect( labelWrapper.tagName ).toBe( 'DIV' );
|
|
expect( labelWrapper.className ).toBe( 'cdx-checkbox__label cdx-label' );
|
|
const label = labelWrapper.children[ 0 ];
|
|
expect( label.tagName ).toBe( 'LABEL' );
|
|
expect( label.className ).toBe( 'cdx-label__label' );
|
|
expect( label.textContent ).toBe( 'bar' );
|
|
expect( checkbox.className ).toBe( 'cdx-checkbox__input' );
|
|
expect( checkbox.type ).toBe( 'checkbox' );
|
|
expect( checkbox.name ).toBe( 'foo' );
|
|
expect( checkbox.checked ).toBe( true );
|
|
} );
|
|
|
|
it( 'should create a Codex ToggleButton', () => {
|
|
const toggleButtonOn = cmPanel.getToggleButton( 'foo', 'bar', 'baz', true );
|
|
expect( toggleButtonOn.tagName ).toBe( 'BUTTON' );
|
|
expect( toggleButtonOn.className ).toBe(
|
|
'cdx-toggle-button cdx-toggle-button--framed cdx-toggle-button--toggled-on cm-mw-panel--toggle-button'
|
|
);
|
|
expect( toggleButtonOn.dataset.checked ).toBe( 'true' );
|
|
expect( toggleButtonOn.getAttribute( 'aria-pressed' ) ).toBe( 'true' );
|
|
expect( toggleButtonOn.title ).toBe( 'bar' );
|
|
expect( toggleButtonOn.getAttribute( 'aria-label' ) ).toBe( 'bar' );
|
|
expect( toggleButtonOn.children.length ).toBe( 1 );
|
|
const iconSpan = toggleButtonOn.children[ 0 ];
|
|
expect( iconSpan.tagName ).toBe( 'SPAN' );
|
|
expect( iconSpan.className ).toBe( 'cdx-icon cdx-icon--medium cm-mw-icon--baz' );
|
|
|
|
const toggleButtonOff = cmPanel.getToggleButton( 'foo', 'bar', 'baz', false );
|
|
expect( toggleButtonOff.className ).toBe(
|
|
'cdx-toggle-button cdx-toggle-button--framed cdx-toggle-button--toggled-off cm-mw-panel--toggle-button'
|
|
);
|
|
expect( toggleButtonOff.dataset.checked ).toBe( 'false' );
|
|
expect( toggleButtonOff.getAttribute( 'aria-pressed' ) ).toBe( 'false' );
|
|
} );
|
|
} );
|