Merge "Refactor: Make VectorMenu template data conform with MenuDefinition"

This commit is contained in:
jenkins-bot 2020-04-27 17:59:40 +00:00 committed by Gerrit Code Review
commit f522973a34
4 changed files with 46 additions and 28 deletions

View File

@ -435,10 +435,11 @@ class VectorTemplate extends BaseTemplate {
*/ */
private function buildVariantsProps() : array { private function buildVariantsProps() : array {
$props = [ $props = [
'empty-portlet' => ( count( $this->get( 'variant_urls', [] ) ) == 0 ) ? 'emptyPortlet' : '', 'class' => ( count( $this->get( 'variant_urls', [] ) ) == 0 ) ?
'menu-id' => 'p-variants', 'emptyPortlet vectorMenu' : 'vectorMenu',
'menu-label-id' => 'p-variants-label', 'id' => 'p-variants',
'msg-label' => $this->getMsg( 'variants' )->text(), 'label-id' => 'p-variants-label',
'label' => $this->getMsg( 'variants' )->text(),
'html-items' => '', 'html-items' => '',
]; ];
@ -485,10 +486,11 @@ class VectorTemplate extends BaseTemplate {
*/ */
private function buildActionsProps() : array { private function buildActionsProps() : array {
$props = [ $props = [
'empty-portlet' => ( count( $this->get( 'action_urls', [] ) ) == 0 ) ? 'emptyPortlet' : '', 'class' => ( count( $this->get( 'action_urls', [] ) ) == 0 ) ?
'msg-label' => $this->getMsg( 'vector-more-actions' )->text(), 'emptyPortlet vectorMenu' : 'vectorMenu',
'menu-id' => 'p-cactions', 'label' => $this->getMsg( 'vector-more-actions' )->text(),
'menu-label-id' => 'p-cactions-label', 'id' => 'p-cactions',
'label-id' => 'p-cactions-label',
'html-userlangattributes' => $this->get( 'userlangattributes', '' ), 'html-userlangattributes' => $this->get( 'userlangattributes', '' ),
'html-items' => '', 'html-items' => '',
]; ];

View File

@ -1,15 +1,10 @@
{{! {{!
string|null empty-portlet See @typedef MenuDefinition
string msg-label
string menu-id
string menu-label-id
string|null html-items
string|null html-userlangattributes
}} }}
<div id="{{menu-id}}" role="navigation" class="vectorMenu {{empty-portlet}}" aria-labelledby="{{menu-label-id}}"> <div id="{{id}}" role="navigation" class="{{class}}" aria-labelledby="{{label-id}}">
<input type="checkbox" class="vectorMenuCheckbox" aria-labelledby="{{menu-label-id}}" /> <input type="checkbox" class="vectorMenuCheckbox" aria-labelledby="{{label-id}}" />
<h3 id="{{menu-label-id}}"> <h3 id="{{label-id}}">
<span>{{msg-label}}</span> <span>{{label}}</span>
</h3> </h3>
<ul class="menu" {{{html-userlangattributes}}}> <ul class="menu" {{{html-userlangattributes}}}>
{{{html-items}}} {{{html-items}}}

View File

@ -3,11 +3,14 @@ import { htmluserlangattributes } from './utils';
export { vectorMenuTemplate }; export { vectorMenuTemplate };
/**
* @type {MenuDefinition}
*/
export const moreData = { export const moreData = {
'empty-portlet': '', class: 'vectorMenu',
'msg-label': 'More', label: 'More',
'menu-id': 'p-cactions', id: 'p-cactions',
'menu-label-id': 'p-cactions-label', 'label-id': 'p-cactions-label',
'html-userlangattributes': htmluserlangattributes, 'html-userlangattributes': htmluserlangattributes,
'html-items': `<li id="ca-delete"> 'html-items': `<li id="ca-delete">
<a href="/w/index.php?title=Main_Page&amp;action=delete" <a href="/w/index.php?title=Main_Page&amp;action=delete"
@ -23,10 +26,14 @@ export const moreData = {
</li>` </li>`
}; };
/**
* @type {MenuDefinition}
*/
export const variantsData = { export const variantsData = {
'msg-label': '新加坡简体', class: 'vectorMenu',
'menu-id': 'p-variants', label: '新加坡简体',
'menu-label-id': 'p-variants-label', id: 'p-variants',
'label-id': 'p-variants-label',
'html-userlangattributes': htmluserlangattributes, 'html-userlangattributes': htmluserlangattributes,
'html-items': `<li id="ca-varlang-0"> 'html-items': `<li id="ca-varlang-0">
<a href="/zh/%E4%B8%AD%E5%8D%8E%E4%BA%BA%E6%B0%91%E5%85%B1%E5%92%8C%E5%9B%BD" <a href="/zh/%E4%B8%AD%E5%8D%8E%E4%BA%BA%E6%B0%91%E5%85%B1%E5%92%8C%E5%9B%BD"

View File

@ -132,17 +132,22 @@ class VectorTemplateTest extends MediaWikiIntegrationTestCase {
/** /**
* @covers ::buildViewsProps * @covers ::buildViewsProps
* @covers ::buildActionsProps
* @covers ::buildVariantsProps
* @covers ::getMenuProps
*/ */
public function testbuildViewsProps() { public function testGetMenuProps() {
$langAttrs = 'LANG_ATTRIBUTES'; $langAttrs = 'LANG_ATTRIBUTES';
$vectorTemplate = $this->provideVectorTemplateObject(); $vectorTemplate = $this->provideVectorTemplateObject();
$vectorTemplate->set( 'view_urls', [] ); $vectorTemplate->set( 'view_urls', [] );
$vectorTemplate->set( 'personal_urls', [] );
$vectorTemplate->set( 'skin', new \SkinVector() ); $vectorTemplate->set( 'skin', new \SkinVector() );
$vectorTemplate->set( 'userlangattributes', $langAttrs ); $vectorTemplate->set( 'userlangattributes', $langAttrs );
$openVectorTemplate = TestingAccessWrapper::newFromObject( $vectorTemplate ); $openVectorTemplate = TestingAccessWrapper::newFromObject( $vectorTemplate );
$props = $openVectorTemplate->buildViewsProps(); $props = $openVectorTemplate->getMenuProps();
$this->assertSame( $props, [ $views = $openVectorTemplate->buildViewsProps();
$this->assertSame( $views, [
'tabs-id' => 'p-views', 'tabs-id' => 'p-views',
'empty-portlet' => 'emptyPortlet', 'empty-portlet' => 'emptyPortlet',
'label-id' => 'p-views-label', 'label-id' => 'p-views-label',
@ -150,6 +155,15 @@ class VectorTemplateTest extends MediaWikiIntegrationTestCase {
'html-userlangattributes' => $langAttrs, 'html-userlangattributes' => $langAttrs,
'html-items' => '', 'html-items' => '',
] ); ] );
$variants = $openVectorTemplate->buildVariantsProps();
$actions = $openVectorTemplate->buildActionsProps();
$this->assertSame( $variants['class'],
'emptyPortlet vectorMenu' );
$this->assertSame( $actions['class'],
'emptyPortlet vectorMenu' );
$this->assertSame( $props['data-personal-menu']['class'],
'emptyPortlet' );
} }
} }