Skip to content

Commit

Permalink
feat(plugins): add menu-bar extension point (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aracturat authored Jun 11, 2021
1 parent ad67970 commit 6115ada
Show file tree
Hide file tree
Showing 16 changed files with 131 additions and 12 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,10 @@ directory.
}
```

Currently the only registered extension points is `result` - allows to extend each test result; adds `resultId` and `testName` props to the plugin component.

Currently, there are extension points:
* `result` - allows to extend each test result; adds `resultId` and `testName` props to the plugin component.
* `menu-bar` - allows to extend menu bar.

An extension point may be extended by more than one component. In that case order of components application is determined by `plugins` config order. Each following component is applied to all previously composed components at the extension point.

* **customScripts** (optional) `function[]` - allows to add any scripts on the report html-page. Script will be executed immediately on page render. It can be helpful for adding some metrics or own extra functionality.
Expand Down
4 changes: 4 additions & 0 deletions lib/constants/extension-points.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'use strict';

export const RESULT = 'result';
export const MENU_BAR = 'menu-bar';
12 changes: 10 additions & 2 deletions lib/static/components/controls/menu-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import {connect} from 'react-redux';
import PropTypes from 'prop-types';
import {Dropdown} from 'semantic-ui-react';
import {isEmpty} from 'lodash';
import ExtensionPoint from '../extension-point';
import plugins from '../../modules/plugins';
import {MENU_BAR} from '../../../constants/extension-points';

class MenuBar extends Component {
static propTypes = {extraItems: PropTypes.object.isRequired};
Expand All @@ -20,15 +23,20 @@ class MenuBar extends Component {
render() {
const {extraItems} = this.props;

if (isEmpty(extraItems)) {
const hasMenuBarPlugins = plugins.getLoadedConfigs()
.some(e => e.point === MENU_BAR);

if (isEmpty(extraItems) && !hasMenuBarPlugins) {
return null;
}

return (
<div className="menu-bar">
<Dropdown item icon="bars" simple direction="left">
<Dropdown.Menu>
{this._getItems(extraItems)}
<ExtensionPoint name={MENU_BAR}>
{this._getItems(extraItems)}
</ExtensionPoint>
</Dropdown.Menu>
</Dropdown>
</div>
Expand Down
3 changes: 2 additions & 1 deletion lib/static/components/section/body/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ControlButton from '../../controls/control-button';
import Result from './result';
import * as actions from '../../../modules/actions';
import ExtensionPoint from '../../extension-point';
import {RESULT} from '../../../../constants/extension-points';

class Body extends Component {
static propTypes = {
Expand Down Expand Up @@ -115,7 +116,7 @@ class Body extends Component {
{this._addRetrySwitcher()}
{this._addRetryButton()}
</div>
<ExtensionPoint name="result" resultId={activeResultId} testName={testName}>
<ExtensionPoint name={RESULT} resultId={activeResultId} testName={testName}>
<Result resultId={activeResultId} testName={testName} />
</ExtensionPoint>
</div>
Expand Down
12 changes: 8 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
"devDependencies": {
"@gemini-testing/react-lazily-render": "^1.2.1",
"@gemini-testing/react-lazyload": "^2.3.2",
"@scoped/html-reporter-redux-with-server-plugin": "file:test/func/html-reporter-plugins/redux-with-server",
"app-module-path": "^2.2.0",
"babel-core": "^6.26.0",
"babel-eslint": "^8.0.1",
Expand Down Expand Up @@ -110,7 +109,9 @@
"hermione-global-hook": "^1.0.1",
"hermione-headless-chrome": "0.0.2",
"html-react-parser": "^0.4.0",
"html-reporter-redux-with-server-plugin": "file:test/func/html-reporter-plugins/redux-with-server",
"html-reporter-basic-plugin": "file:test/func/html-reporter-plugins/basic",
"html-reporter-menu-bar-plugin": "file:test/func/html-reporter-plugins/menu-bar",
"html-reporter-redux-plugin": "file:test/func/html-reporter-plugins/redux",
"html-reporter-test-server": "file:test/func/hermione-plugins/html-reporter-test-server",
"html-reporter-tester": "file:test/func/hermione-plugins/html-reporter-tester",
Expand Down
8 changes: 7 additions & 1 deletion test/func/fixtures/.hermione.fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ module.exports = {
position: 'after'
},
{
name: '@scoped/html-reporter-redux-with-server-plugin',
name: 'html-reporter-redux-with-server-plugin',
component: 'ColorBorder',
point: 'result',
position: 'after'
Expand All @@ -81,6 +81,12 @@ module.exports = {
name: 'html-reporter-redux-plugin',
component: 'ColorBorder',
position: 'before'
},
{
name: 'html-reporter-menu-bar-plugin',
component: 'MenuBarItem',
position: 'after',
point: 'menu-bar'
}
]
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.menu-item__link.menu-bar-item {
color: red;
}
20 changes: 20 additions & 0 deletions test/func/html-reporter-plugins/menu-bar/lib/menu-bar-item.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import './menu-bar-item.css';

export default ['react', 'semantic-ui-react', function(React, {Dropdown}, {pluginName}) {
class MenuBarItem extends React.Component {
// allow the component to be placed only on "menu-bar" extension point
static point = 'menu-bar';

render() {
return (
<Dropdown.Item>
<a className="menu-item__link menu-bar-item" href="#">{pluginName}</a>
</Dropdown.Item>
);
}
}

return {
MenuBarItem
};
}];
7 changes: 7 additions & 0 deletions test/func/html-reporter-plugins/menu-bar/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "html-reporter-menu-bar-plugin",
"version": "0.1.0",
"scripts": {
"build": "webpack --config webpack.config.js"
}
}
1 change: 1 addition & 0 deletions test/func/html-reporter-plugins/menu-bar/plugin.js

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions test/func/html-reporter-plugins/menu-bar/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const webpack = require('webpack');

module.exports = {
entry: {
plugin: './lib/menu-bar-item.jsx'
},
module: {
rules: [
{
test: /\.css$/,
use: [
'style-loader',
'css-loader'
]
},
{
test: /\.jsx$/,
use: 'babel-loader',
exclude: /node_modules/
}
]
},
output: {
filename: '[name].js',
path: __dirname,
library: '__hermione_html_reporter_register_plugin__',
libraryTarget: 'jsonp'
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
uglifyOptions: {
compress: {
warnings: true,
'drop_console': true,
unsafe: true
}
}
})
]
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@scoped/html-reporter-redux-with-server-plugin",
"name": "html-reporter-redux-with-server-plugin",
"version": "0.1.0",
"scripts": {
"build": "webpack --config webpack.config.js"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions test/func/plugins/tests-menu-bar-plugin.hermione.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const {mkNestedSelector} = require('../utils');

describe('Test menu bar plugin', function() {
const selector = '.main-menu .menu-bar';

it('should show menu bar with plugins applied', async function() {
return this.browser
.waitForVisible(selector)
.assertView('menu bar plugins', selector);
});

it('should show menu bar item on click', async function() {
const menuSelector = mkNestedSelector(selector, '.menu');

return this.browser
.waitForVisible(selector)
.click(selector)
.waitForVisible(menuSelector)
.assertView('menu bar plugins clicked', [selector, menuSelector]);
});
});

0 comments on commit 6115ada

Please sign in to comment.