Skip to content

Commit

Permalink
Merge pull request #1357 from vektor-inc/fix/highlighter/rgba
Browse files Browse the repository at this point in the history
【確認中】Highlighter alpha付きのカラーパレットに対応
  • Loading branch information
sysbird authored Aug 12, 2022
2 parents 7ef13a9 + b2f2bd8 commit e6b414b
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 0 deletions.
2 changes: 2 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ e.g.

== Changelog ==

[ Bug Fix ][ highlighter ] cope with color palette with alpha.

= 1.41.1 =
[ Bug Fix ] Fix don't display Admin screen in case of spacific option value

Expand Down
4 changes: 4 additions & 0 deletions src/utils/hex-to-rgba.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
//hexカラーコード定義をrgbaに変換
export default function hex2rgba(hex, alpha) {
// rgbaの場合は、そのまま返す(例:rgba( 255,255,255,0.1 ))
if (hex.substring(0, 4) === 'rgba') {
return hex;
}
// ロングバージョンの場合(例:#FF0000)
let r = hex.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i);
let c = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Lightning Highlighter Lightning Highlighter 1`] = `
"<!-- wp:paragraph -->
<p><span data-color=\\"#000000\\" style=\\"background: linear-gradient(transparent 60%,rgba(0, 0, 0, 0.7) 0);\\" class=\\"vk_highlighter\\">1</span></p>
<!-- /wp:paragraph -->"
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`x-t9 Highlighter x-t9 Highlighter 1`] = `
"<!-- wp:paragraph -->
<p><span data-color=\\"rgba(0,0,0,0.5)\\" style=\\"background: linear-gradient(transparent 60%,rgba(0,0,0,0.5) 0);\\" class=\\"vk_highlighter\\">1</span></p>
<!-- /wp:paragraph -->"
`;
66 changes: 66 additions & 0 deletions test/e2e-tests/specs/highlighter-lightning.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* WordPress dependencies
*/
import {
pressKeyWithModifier,
createNewPost,
clickBlockAppender,
clickBlockToolbarButton,
getEditedPostContent,
activateTheme,
installTheme,
} from '@wordpress/e2e-test-utils';

/**
* Internal dependencies
*/
import { changeSiteLang } from '../helper/changeSiteLang';

describe( 'Lightning Highlighter', () => {
let oldLanguage;
beforeAll( async () => {
await installTheme( 'lightning' );
await activateTheme( 'lightning' );
} );
beforeEach( async () => {
oldLanguage = await changeSiteLang( 'en' );
await createNewPost();
} );
afterEach( async () => {
await changeSiteLang( oldLanguage );
});
afterAll( async () => {
await activateTheme( 'twentytwentytwo' );
} );

it( 'Lightning Highlighter', async () => {
/**
* 新しく投稿を作る
*/
await createNewPost();

await clickBlockAppender();

// Add text and select to color.
await page.keyboard.type( '1' );
await pressKeyWithModifier( 'primary', 'a' );
await clickBlockToolbarButton( 'More' );

const button = await page.waitForXPath(
`//button[text()='Highlighter']`
);
// Clicks may fail if the button is out of view. Assure it is before click.
await button.evaluate( ( element ) => element.scrollIntoView() );
await button.click();

const option = await page.waitForSelector(
'[aria-label="Color: Black"]'
);

await option.click();

expect( await getEditedPostContent() ).toMatchSnapshot();

} )

});
66 changes: 66 additions & 0 deletions test/e2e-tests/specs/highlighter-x-t9.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* WordPress dependencies
*/
import {
pressKeyWithModifier,
createNewPost,
clickBlockAppender,
clickBlockToolbarButton,
getEditedPostContent,
activateTheme,
installTheme,
} from '@wordpress/e2e-test-utils';

/**
* Internal dependencies
*/
import { changeSiteLang } from '../helper/changeSiteLang';

describe( 'x-t9 Highlighter', () => {
let oldLanguage;
beforeAll( async () => {
await installTheme( 'x-t9' );
await activateTheme( 'x-t9' );
} );
beforeEach( async () => {
oldLanguage = await changeSiteLang( 'en' );
await createNewPost();
} );
afterEach( async () => {
await changeSiteLang( oldLanguage );
});
afterAll( async () => {
await activateTheme( 'twentytwentytwo' );
} );

it( 'x-t9 Highlighter', async () => {
/**
* 新しく投稿を作る
*/
await createNewPost();

await clickBlockAppender();

// Add text and select to color.
await page.keyboard.type( '1' );
await pressKeyWithModifier( 'primary', 'a' );
await clickBlockToolbarButton( 'More' );

const button = await page.waitForXPath(
`//button[text()='Highlighter']`
);
// Clicks may fail if the button is out of view. Assure it is before click.
await button.evaluate( ( element ) => element.scrollIntoView() );
await button.click();

const option = await page.waitForSelector(
'[aria-label="Color: Text Secondary"]'
);

await option.click();

expect( await getEditedPostContent() ).toMatchSnapshot();

} )

});

0 comments on commit e6b414b

Please sign in to comment.