html-reporter 9.7.5 → 9.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +4 -681
  3. package/docs/en/html-reporter-api.md +198 -0
  4. package/docs/en/html-reporter-commands.md +96 -0
  5. package/docs/en/html-reporter-custom-gui.md +99 -0
  6. package/docs/en/html-reporter-events.md +125 -0
  7. package/docs/en/html-reporter-plugins.md +265 -0
  8. package/docs/en/html-reporter-setup.md +378 -0
  9. package/docs/en/html-reporter.md +8 -0
  10. package/docs/ru/html-reporter-api.md +198 -0
  11. package/docs/ru/html-reporter-commands.md +96 -0
  12. package/docs/ru/html-reporter-custom-gui.md +99 -0
  13. package/docs/ru/html-reporter-events.md +125 -0
  14. package/docs/ru/html-reporter-plugins.md +265 -0
  15. package/docs/ru/html-reporter-setup.md +378 -0
  16. package/docs/ru/html-reporter.md +8 -0
  17. package/lib/common-utils.js +6 -0
  18. package/lib/constants/database.js +32 -13
  19. package/lib/gui/tool-runner/index.js +11 -4
  20. package/lib/history-utils.js +32 -14
  21. package/lib/report-builder/static.js +9 -4
  22. package/lib/sqlite-adapter.js +40 -0
  23. package/lib/static/components/header/summary/dbBtn.js +36 -0
  24. package/lib/static/components/header/summary/dbSummary.js +3 -22
  25. package/lib/static/components/icons/view-in-browser/index.js +2 -8
  26. package/lib/static/components/modals/screenshot-accepter/header.js +8 -1
  27. package/lib/static/components/modals/screenshot-accepter/index.js +56 -29
  28. package/lib/static/components/modals/screenshot-accepter/style.css +11 -0
  29. package/lib/static/components/progress-bar/index.js +13 -0
  30. package/lib/static/components/progress-bar/index.styl +24 -0
  31. package/lib/static/components/section/body/history/index.js +29 -0
  32. package/lib/static/components/section/body/history/index.styl +4 -0
  33. package/lib/static/components/section/body/meta-info/content.js +24 -9
  34. package/lib/static/components/section/body/result.js +2 -0
  35. package/lib/static/gui.html +13 -1
  36. package/lib/static/gui.min.css +691 -1
  37. package/lib/static/gui.min.js +47 -61
  38. package/lib/static/index.html +13 -1
  39. package/lib/static/modules/action-names.js +2 -0
  40. package/lib/static/modules/actions.js +13 -0
  41. package/lib/static/modules/middlewares/metrika.js +4 -2
  42. package/lib/static/modules/reducers/grouped-tests/index.js +2 -1
  43. package/lib/static/modules/reducers/tree/index.js +2 -1
  44. package/lib/static/modules/reducers/tree/nodes/results.js +1 -5
  45. package/lib/static/modules/reducers/view.js +34 -61
  46. package/lib/static/report.min.css +691 -1
  47. package/lib/static/report.min.js +47 -61
  48. package/lib/static/styles.css +16 -0
  49. package/lib/test-adapter.js +62 -19
  50. package/lib/tests-tree-builder/static.js +1 -0
  51. package/package.json +1 -1
@@ -1,25 +1,44 @@
1
1
  'use strict';
2
2
 
3
3
  const DB_TYPES = {int: 'INT', text: 'TEXT'};
4
+ const DB_COLUMNS = {
5
+ SUITE_PATH: 'suitePath',
6
+ SUITE_NAME: 'suiteName',
7
+ NAME: 'name',
8
+ SUITE_URL: 'suiteUrl',
9
+ META_INFO: 'metaInfo',
10
+ HISTORY: 'history',
11
+ DESCRIPTION: 'description',
12
+ ERROR: 'error',
13
+ SKIP_REASON: 'skipReason',
14
+ IMAGES_INFO: 'imagesInfo',
15
+ SCREENSHOT: 'screenshot',
16
+ MULTIPLE_TABS: 'multipleTabs',
17
+ STATUS: 'status',
18
+ TIMESTAMP: 'timestamp'
19
+ };
20
+
4
21
  const SUITES_TABLE_COLUMNS = [
5
- {name: 'suitePath', type: DB_TYPES.text},
6
- {name: 'suiteName', type: DB_TYPES.text},
7
- {name: 'name', type: DB_TYPES.text},
8
- {name: 'suiteUrl', type: DB_TYPES.text},
9
- {name: 'metaInfo', type: DB_TYPES.text},
10
- {name: 'description', type: DB_TYPES.text},
11
- {name: 'error', type: DB_TYPES.text},
12
- {name: 'skipReason', type: DB_TYPES.text},
13
- {name: 'imagesInfo', type: DB_TYPES.text},
14
- {name: 'screenshot', type: DB_TYPES.int}, //boolean - 0 or 1
15
- {name: 'multipleTabs', type: DB_TYPES.int}, //boolean - 0 or 1
16
- {name: 'status', type: DB_TYPES.text},
17
- {name: 'timestamp', type: DB_TYPES.int}
22
+ {name: DB_COLUMNS.SUITE_PATH, type: DB_TYPES.text},
23
+ {name: DB_COLUMNS.SUITE_NAME, type: DB_TYPES.text},
24
+ {name: DB_COLUMNS.NAME, type: DB_TYPES.text},
25
+ {name: DB_COLUMNS.SUITE_URL, type: DB_TYPES.text},
26
+ {name: DB_COLUMNS.META_INFO, type: DB_TYPES.text},
27
+ {name: DB_COLUMNS.HISTORY, type: DB_TYPES.text},
28
+ {name: DB_COLUMNS.DESCRIPTION, type: DB_TYPES.text},
29
+ {name: DB_COLUMNS.ERROR, type: DB_TYPES.text},
30
+ {name: DB_COLUMNS.SKIP_REASON, type: DB_TYPES.text},
31
+ {name: DB_COLUMNS.IMAGES_INFO, type: DB_TYPES.text},
32
+ {name: DB_COLUMNS.SCREENSHOT, type: DB_TYPES.int}, //boolean - 0 or 1
33
+ {name: DB_COLUMNS.MULTIPLE_TABS, type: DB_TYPES.int}, //boolean - 0 or 1
34
+ {name: DB_COLUMNS.STATUS, type: DB_TYPES.text},
35
+ {name: DB_COLUMNS.TIMESTAMP, type: DB_TYPES.int}
18
36
  ];
19
37
 
20
38
  module.exports = {
21
39
  DB_MAX_AVAILABLE_PAGE_SIZE: 65536, // helps to speed up queries
22
40
  DB_SUITES_TABLE_NAME: 'suites',
41
+ DB_COLUMNS,
23
42
  SUITES_TABLE_COLUMNS,
24
43
  LOCAL_DATABASE_NAME: 'sqlite.db',
25
44
  DATABASE_URLS_JSON_NAME: 'databaseUrls.json',
@@ -170,7 +170,8 @@ module.exports = class ToolRunner {
170
170
  return;
171
171
  }
172
172
 
173
- const testId = formatId(test.id(), browserId);
173
+ // TODO: remove toString after publish major version
174
+ const testId = formatId(test.id.toString(), browserId);
174
175
  this._tests[testId] = _.extend(test, {browserId});
175
176
 
176
177
  test.pending
@@ -193,13 +194,13 @@ module.exports = class ToolRunner {
193
194
  const {browserId, attempt} = test;
194
195
  const fullTitle = mkFullTitle(test);
195
196
  const testId = formatId(getShortMD5(fullTitle), browserId);
196
- const testResult = this._tests[testId];
197
+ const rawTest = this._tests[testId];
197
198
  const {sessionId, url} = test.metaInfo;
198
199
  const assertViewResults = [];
199
200
 
200
201
  const imagesInfo = test.imagesInfo.map((imageInfo) => {
201
202
  const {stateName, actualImg} = imageInfo;
202
- const path = this._hermione.config.browsers[browserId].getScreenshotPath(testResult, stateName);
203
+ const path = this._hermione.config.browsers[browserId].getScreenshotPath(rawTest, stateName);
203
204
  const refImg = {path, size: actualImg.size};
204
205
 
205
206
  assertViewResults.push({stateName, refImg, currImg: actualImg});
@@ -207,7 +208,13 @@ module.exports = class ToolRunner {
207
208
  return _.extend(imageInfo, {expectedImg: refImg});
208
209
  });
209
210
 
210
- return _.merge({}, testResult, {assertViewResults, imagesInfo, sessionId, attempt, origAttempt: attempt, meta: {url}, updated: true});
211
+ const res = _.merge({}, rawTest, {assertViewResults, imagesInfo, sessionId, attempt, origAttempt: attempt, meta: {url}, updated: true});
212
+
213
+ // _.merge can't fully clone test object since hermione@7+
214
+ // TODO: use separate object to represent test results. Do not extend test object with test results
215
+ return rawTest && rawTest.clone
216
+ ? Object.assign(rawTest.clone(), res)
217
+ : res;
211
218
  }
212
219
 
213
220
  _emitUpdateReference({refImg}, state) {
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const {last, isUndefined} = require('lodash');
3
+ const {isEmpty} = require('lodash');
4
4
 
5
5
  const formatDuration = (d) => `<- ${d}ms`;
6
6
 
@@ -8,25 +8,43 @@ const wrapArg = (arg) => `"${arg}"`;
8
8
 
9
9
  const getCommand = ({
10
10
  n: name,
11
- a: args = [],
12
- d: duration}
13
- ) => `${name}(${args.map(wrapArg).join(', ')}) ${formatDuration(duration)}`;
11
+ a: args = []
12
+ }) => `${name}(${args.map(wrapArg).join(', ')})`;
13
+
14
+ const traverseNodes = (nodes, traverseCb, depth = 0) => {
15
+ nodes.forEach(node => {
16
+ const shouldTraverseChildren = traverseCb(node, depth);
17
+
18
+ if (shouldTraverseChildren) {
19
+ traverseNodes(node.c, traverseCb, depth + 1);
20
+ }
21
+ });
22
+ };
14
23
 
15
24
  const getCommandsHistory = (history) => {
16
- if (isUndefined(history)) {
25
+ if (isEmpty(history)) {
17
26
  return;
18
27
  }
19
28
 
20
29
  try {
21
- const formatedCommands = history
22
- .map(getCommand)
23
- .map((s) => `\t${s}\n`);
24
- const lastCommandChildren = last(history).c;
25
- const formatedChildren = lastCommandChildren
26
- .map((cmd) => `${getCommand(cmd)}`)
27
- .map((s) => `\t\t${s}\n`);
28
-
29
- return [...formatedCommands, ...formatedChildren];
30
+ const formatedHistory = [];
31
+
32
+ const traverseCb = (node, depth) => {
33
+ const offset = '\t'.repeat(depth);
34
+ const isGroup = Boolean(node.g);
35
+ const duration = node.d;
36
+ const isFailed = Boolean(node.f);
37
+ const title = isGroup ? node.n : getCommand(node);
38
+ const formatedDuration = formatDuration(duration);
39
+
40
+ formatedHistory.push(`${offset}${title} ${formatedDuration}\n`);
41
+
42
+ return isFailed;
43
+ };
44
+
45
+ traverseNodes(history, traverseCb);
46
+
47
+ return formatedHistory;
30
48
  } catch (e) {
31
49
  return `failed to get command history: ${e.message}`;
32
50
  }
@@ -38,7 +38,11 @@ module.exports = class StaticReportBuilder {
38
38
 
39
39
  return result instanceof TestAdapter
40
40
  ? result
41
- : TestAdapter.create(result, this._hermione, this._pluginConfig, status);
41
+ : TestAdapter.create(result, {
42
+ hermione: this._hermione,
43
+ sqliteAdapter: this._sqliteAdapter,
44
+ status
45
+ });
42
46
  }
43
47
 
44
48
  async saveStaticFiles() {
@@ -111,7 +115,8 @@ module.exports = class StaticReportBuilder {
111
115
 
112
116
  _createTestResult(result, props) {
113
117
  const {
114
- browserId, suite, sessionId, description, imagesInfo, screenshot, multipleTabs, errorDetails
118
+ browserId, suite, sessionId, description, history,
119
+ imagesInfo, screenshot, multipleTabs, errorDetails
115
120
  } = result;
116
121
 
117
122
  const {baseHost, saveErrorDetails} = this._pluginConfig;
@@ -119,8 +124,8 @@ module.exports = class StaticReportBuilder {
119
124
  const metaInfo = _.merge(_.cloneDeep(result.meta), {url: suite.fullUrl, file: suite.file, sessionId});
120
125
 
121
126
  const testResult = Object.assign({
122
- suiteUrl, name: browserId, metaInfo, description, imagesInfo,
123
- screenshot: Boolean(screenshot), multipleTabs
127
+ suiteUrl, name: browserId, metaInfo, description, history,
128
+ imagesInfo, screenshot: Boolean(screenshot), multipleTabs
124
129
  }, props);
125
130
 
126
131
  if (saveErrorDetails && errorDetails) {
@@ -6,6 +6,7 @@ const Database = require('better-sqlite3');
6
6
  const NestedError = require('nested-error-stacks');
7
7
  const debug = require('debug')('html-reporter:sqlite-adapter');
8
8
 
9
+ const {getShortMD5} = require('./gui/tool-runner/utils.js');
9
10
  const {createTablesQuery} = require('./db-utils/server');
10
11
  const {DB_SUITES_TABLE_NAME, SUITES_TABLE_COLUMNS, LOCAL_DATABASE_NAME, DATABASE_URLS_JSON_NAME} = require('./constants/database');
11
12
 
@@ -19,6 +20,7 @@ module.exports = class SqliteAdapter {
19
20
  this._reportPath = reportPath;
20
21
  this._reuse = reuse;
21
22
  this._db = null;
23
+ this._queryCache = new Map();
22
24
  }
23
25
 
24
26
  async init() {
@@ -53,6 +55,42 @@ module.exports = class SqliteAdapter {
53
55
  return this._db.close();
54
56
  }
55
57
 
58
+ /**
59
+ * Query database
60
+ * @param {Object} queryParams
61
+ * @param {string} queryParams.select - `SELECT ${select}`
62
+ * @param {string} queryParams.where - `WHERE ${where}`
63
+ * @param {string} queryParams.orderBy - `ORDER BY ${orderBy}`
64
+ * @param {boolean} queryParams.orderDescending - ASCending / DESCending
65
+ * @param {boolean} queryParams.noCache - disables caching for equal queries
66
+ * @param {...string} queryArgs
67
+ */
68
+ query({select, where, orderBy, orderDescending, noCache = false} = {}, ...queryArgs) {
69
+ const cacheKey = !noCache && getShortMD5(`${select}#${where}#${orderBy}${orderDescending}${queryArgs.join('#')}`);
70
+
71
+ if (!noCache && this._queryCache.has(cacheKey)) {
72
+ return this._queryCache.get(cacheKey);
73
+ }
74
+
75
+ let query = `SELECT ${select || '*'} FROM ${DB_SUITES_TABLE_NAME}`;
76
+
77
+ if (where) {
78
+ query += ` WHERE ${where}`;
79
+ }
80
+
81
+ if (orderBy) {
82
+ query += ` ORDER BY ${orderBy} ${orderDescending ? 'DESC' : 'ASC'}`;
83
+ }
84
+
85
+ const result = this._db.prepare(query).get(...queryArgs);
86
+
87
+ if (!noCache) {
88
+ this._queryCache.set(cacheKey, result);
89
+ }
90
+
91
+ return result;
92
+ }
93
+
56
94
  write(testResult) {
57
95
  const testResultObj = this._parseTestResult(testResult);
58
96
  const values = this._createValuesArray(testResultObj);
@@ -66,6 +104,7 @@ module.exports = class SqliteAdapter {
66
104
  name,
67
105
  suiteUrl,
68
106
  metaInfo,
107
+ history,
69
108
  description,
70
109
  error,
71
110
  skipReason,
@@ -82,6 +121,7 @@ module.exports = class SqliteAdapter {
82
121
  name,
83
122
  suiteUrl,
84
123
  metaInfo,
124
+ history,
85
125
  description,
86
126
  error,
87
127
  skipReason,
@@ -0,0 +1,36 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import {Ref, Button} from 'semantic-ui-react';
4
+ import classNames from 'classnames';
5
+
6
+ const DbBtn = ({fetchDbDetails}, ref) => {
7
+ const successFetchDbDetails = fetchDbDetails.filter(d => d.success);
8
+ const isFailed = successFetchDbDetails.length !== fetchDbDetails.length;
9
+ const value = `${successFetchDbDetails.length}/${fetchDbDetails.length}`;
10
+ const content = `Databases loaded: ${value}`;
11
+ const className = classNames(
12
+ 'db-info',
13
+ {'db-info_failed': isFailed}
14
+ );
15
+
16
+ return (
17
+ <Ref innerRef={ref}>
18
+ <Button
19
+ content={content}
20
+ icon="angle down"
21
+ className={className}
22
+ basic
23
+ />
24
+ </Ref>
25
+ );
26
+ };
27
+
28
+ const ForwardedDbBtn = React.forwardRef(DbBtn);
29
+
30
+ ForwardedDbBtn.propTypes = {
31
+ fetchDbDetails: PropTypes.arrayOf(PropTypes.shape({
32
+ success: PropTypes.bool
33
+ })).isRequired
34
+ };
35
+
36
+ export default ForwardedDbBtn;
@@ -1,8 +1,8 @@
1
1
  import React, {Component} from 'react';
2
- import {Dropdown, Button, Ref} from 'semantic-ui-react';
2
+ import {Dropdown} from 'semantic-ui-react';
3
3
  import PropTypes from 'prop-types';
4
- import classNames from 'classnames';
5
4
 
5
+ import DbBtn from './dbBtn';
6
6
  import Popup from '../../popup';
7
7
 
8
8
  export default class DbSummaryKey extends Component {
@@ -28,9 +28,6 @@ export default class DbSummaryKey extends Component {
28
28
  return null;
29
29
  }
30
30
 
31
- const successFetchDbDetails = fetchDbDetails.filter(d => d.success);
32
- const isFailed = successFetchDbDetails.length !== fetchDbDetails.length;
33
- const value = `${successFetchDbDetails.length}/${fetchDbDetails.length}`;
34
31
  const additionalInfo = fetchDbDetails.map(({url, status, success}) => (
35
32
  <Dropdown.Item key={url} className="db-info__row">
36
33
  {' '}
@@ -38,28 +35,12 @@ export default class DbSummaryKey extends Component {
38
35
  <span className={success ? 'db-info__row_success' : 'db-info__row_fail'}>{' ' + status}</span>
39
36
  </Dropdown.Item>
40
37
  ));
41
- const title = `Databases loaded: ${value}`;
42
- const btnClassNames = classNames(
43
- 'db-info',
44
- {'db-info_failed': isFailed}
45
- );
46
-
47
- const DbBtn = React.forwardRef((props, ref) => (
48
- <Ref innerRef={ref}>
49
- <Button
50
- content={title}
51
- icon="angle down"
52
- className={btnClassNames}
53
- basic
54
- />
55
- </Ref>
56
- ));
57
38
 
58
39
  return (
59
40
  <Popup
60
41
  className="db-info__popup"
61
42
  action="hover"
62
- target={<DbBtn />}
43
+ target={<DbBtn fetchDbDetails={fetchDbDetails} />}
63
44
  >
64
45
  {additionalInfo}
65
46
  </Popup>
@@ -2,10 +2,10 @@ import React, {Component} from 'react';
2
2
  import {connect} from 'react-redux';
3
3
  import {bindActionCreators} from 'redux';
4
4
  import PropTypes from 'prop-types';
5
- import url from 'url';
6
5
  import classNames from 'classnames';
7
6
 
8
7
  import * as actions from '../../../modules/actions';
8
+ import {buildUrl} from '../../../../common-utils';
9
9
 
10
10
  import './index.styl';
11
11
 
@@ -24,12 +24,6 @@ class ViewInBrowser extends Component {
24
24
  this.props.actions.viewInBrowser();
25
25
  }
26
26
 
27
- _buildUrl(href, host) {
28
- return host
29
- ? url.format(Object.assign(url.parse(href), host))
30
- : href;
31
- }
32
-
33
27
  render() {
34
28
  const {suiteUrl, parsedHost, extendClassNames} = this.props;
35
29
  const className = classNames(
@@ -45,7 +39,7 @@ class ViewInBrowser extends Component {
45
39
  return (
46
40
  <a
47
41
  className={className}
48
- href={this._buildUrl(suiteUrl, parsedHost)}
42
+ href={buildUrl(suiteUrl, parsedHost)}
49
43
  onClick={this.onViewInBrowser}
50
44
  title="view in browser"
51
45
  target="_blank"
@@ -3,6 +3,7 @@ import {GlobalHotKeys} from 'react-hotkeys';
3
3
  import PropTypes from 'prop-types';
4
4
  import {uniqBy} from 'lodash';
5
5
 
6
+ import ProgressBar from '../../progress-bar';
6
7
  import Arrow from '../../icons/arrow';
7
8
  import ArrowsClose from '../../icons/arrows-close';
8
9
  import ControlButton from '../../controls/control-button';
@@ -18,6 +19,8 @@ export default class ScreenshotAccepterHeader extends Component {
18
19
  retryIndex: PropTypes.number,
19
20
  activeImageIndex: PropTypes.number,
20
21
  showMeta: PropTypes.bool.isRequired,
22
+ totalImages: PropTypes.number.isRequired,
23
+ acceptedImages: PropTypes.number.isRequired,
21
24
  onClose: PropTypes.func.isRequired,
22
25
  onRetryChange: PropTypes.func.isRequired,
23
26
  onActiveImageChange: PropTypes.func.isRequired,
@@ -94,7 +97,10 @@ export default class ScreenshotAccepterHeader extends Component {
94
97
  }
95
98
 
96
99
  render() {
97
- const {images, stateNameImageIds, retryIndex, showMeta, onClose, onRetryChange, onShowMeta} = this.props;
100
+ const {images, stateNameImageIds, retryIndex,
101
+ showMeta, onClose, onRetryChange, onShowMeta,
102
+ totalImages, acceptedImages
103
+ } = this.props;
98
104
  const resultIds = uniqBy(images, 'id').map((image) => image.parentId);
99
105
  const isArrowControlDisabed = stateNameImageIds.length <= 1;
100
106
 
@@ -152,6 +158,7 @@ export default class ScreenshotAccepterHeader extends Component {
152
158
  extendClassNames="screenshot-accepter__arrows-close-btn"
153
159
  handler={onClose}
154
160
  />
161
+ <ProgressBar done={acceptedImages} total={totalImages}/>
155
162
  </div>
156
163
  </header>
157
164
  </Fragment>
@@ -3,7 +3,7 @@ import ReactDOM from 'react-dom';
3
3
  import {connect} from 'react-redux';
4
4
  import {bindActionCreators} from 'redux';
5
5
  import PropTypes from 'prop-types';
6
- import {isEmpty, isNumber, findIndex} from 'lodash';
6
+ import {isEmpty, isNumber, size, findIndex} from 'lodash';
7
7
 
8
8
  import * as actions from '../../../modules/actions';
9
9
  import ScreenshotAccepterHeader from './header';
@@ -31,34 +31,19 @@ class ScreenshotAccepter extends Component {
31
31
  constructor(props) {
32
32
  super(props);
33
33
 
34
- const {image, activeImageIndex} = this.props;
35
- const images = this._getActiveImages(activeImageIndex);
34
+ const {image, activeImageIndex, stateNameImageIds, imagesByStateName} = this.props;
35
+ const images = this._getActiveImages(activeImageIndex, stateNameImageIds);
36
36
  const retryIndex = findIndex(images, {id: image.id});
37
37
 
38
+ this.delayedTestResults = [];
38
39
  this.state = {
40
+ stateNameImageIds,
39
41
  activeImageIndex,
40
42
  retryIndex,
41
43
  showMeta: false
42
44
  };
43
- }
44
-
45
- componentWillReceiveProps(nextProps) {
46
- if (nextProps.stateNameImageIds.length === this.props.stateNameImageIds.length) {
47
- return;
48
- }
49
45
 
50
- if (isEmpty(nextProps.stateNameImageIds)) {
51
- return this.setState({retryIndex: null, activeImageIndex: null});
52
- }
53
-
54
- if (this.state.activeImageIndex > nextProps.stateNameImageIds.length - 1) {
55
- const activeImageIndex = nextProps.stateNameImageIds.length - 1;
56
- const images = this._getActiveImages(activeImageIndex, nextProps);
57
- return this.setState({retryIndex: images.length - 1, activeImageIndex});
58
- }
59
-
60
- const images = this._getActiveImages(this.state.activeImageIndex, nextProps);
61
- this.setState({retryIndex: images.length - 1});
46
+ this.totalImagesCount = size(imagesByStateName);
62
47
  }
63
48
 
64
49
  componentDidUpdate() {
@@ -75,25 +60,65 @@ class ScreenshotAccepter extends Component {
75
60
  this.setState({retryIndex: images.length - 1, activeImageIndex});
76
61
  }
77
62
 
78
- onScreenshotAccept = (imageId) => {
79
- this.props.actions.acceptTest(imageId);
63
+ onScreenshotAccept = async (imageId) => {
64
+ const updatedData = await this.props.actions.screenshotAccepterAccept(imageId);
65
+
66
+ if (updatedData === null) {
67
+ return;
68
+ }
69
+
70
+ this.delayedTestResults = this.delayedTestResults.concat(updatedData);
71
+
72
+ const stateNameIds = this.state.stateNameImageIds.filter(stateNameImageId => {
73
+ const currImages = this.props.imagesByStateName[stateNameImageId];
74
+
75
+ return !currImages.some(img => img.id === imageId);
76
+ });
77
+
78
+ if (isEmpty(stateNameIds)) {
79
+ return this.setState({
80
+ activeImageIndex: null,
81
+ stateNameImageIds: stateNameIds,
82
+ retryIndex: null
83
+ });
84
+ }
85
+
86
+ const activeImageIndex = Math.min(this.state.activeImageIndex, stateNameIds.length - 1);
87
+ const images = this._getActiveImages(activeImageIndex, stateNameIds);
88
+
89
+ this.setState({
90
+ activeImageIndex,
91
+ stateNameImageIds: stateNameIds,
92
+ retryIndex: images.length - 1
93
+ });
80
94
  }
81
95
 
82
96
  onShowMeta = () => {
83
97
  this.setState({showMeta: !this.state.showMeta});
84
98
  };
85
99
 
86
- _getActiveImages(activeImageIndex = this.state.activeImageIndex, props = this.props) {
87
- const {imagesByStateName, stateNameImageIds} = props;
100
+ onClose = () => {
101
+ if (!isEmpty(this.delayedTestResults)) {
102
+ this.props.actions.applyDelayedTestResults(this.delayedTestResults);
103
+ }
104
+
105
+ this.props.onClose();
106
+ }
88
107
 
89
- return isNumber(activeImageIndex) ? imagesByStateName[stateNameImageIds[activeImageIndex]] : [];
108
+ _getActiveImages(
109
+ activeImageIndex = this.state.activeImageIndex,
110
+ stateNameImageIds = this.state.stateNameImageIds
111
+ ) {
112
+ return isNumber(activeImageIndex)
113
+ ? this.props.imagesByStateName[stateNameImageIds[activeImageIndex]]
114
+ : [];
90
115
  }
91
116
 
92
117
  render() {
93
- const {stateNameImageIds, onClose} = this.props;
94
- const {retryIndex, activeImageIndex, showMeta} = this.state;
118
+ const {retryIndex, stateNameImageIds, activeImageIndex, showMeta} = this.state;
95
119
  const images = this._getActiveImages();
96
120
  const currImage = isNumber(retryIndex) ? images[retryIndex] : null;
121
+ const acceptedImagesCount = this.totalImagesCount - stateNameImageIds.length;
97
122
 
98
123
  return (
99
124
  <Fragment>
@@ -103,7 +128,9 @@ class ScreenshotAccepter extends Component {
103
128
  retryIndex={retryIndex}
104
129
  activeImageIndex={activeImageIndex}
105
130
  showMeta={showMeta}
106
- onClose={onClose}
131
+ onClose={this.onClose}
132
+ totalImages={this.totalImagesCount}
133
+ acceptedImages={acceptedImagesCount}
107
134
  onRetryChange={this.onRetryChange}
108
135
  onActiveImageChange={this.onActiveImageChange}
109
136
  onScreenshotAccept={this.onScreenshotAccept}
@@ -15,6 +15,17 @@
15
15
  background-color: #fff;
16
16
  }
17
17
 
18
+ .screenshot-accepter__controls.state-controls .progress-bar {
19
+ margin-left: auto;
20
+ margin-bottom: 20px;
21
+ }
22
+
23
+ .screenshot-accepter__controls.state-controls .progress-bar::after {
24
+ content: "Accepted: " attr(data-content);
25
+ font-size: 13px;
26
+ line-height: 18px;
27
+ }
28
+
18
29
  .state-controls.screenshot-accepter__controls {
19
30
  display: flex;
20
31
  flex-wrap: wrap;
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+
3
+ import './index.styl';
4
+
5
+ export default ({done, total}) => {
6
+ const percent = (done / total).toFixed(2) * 100;
7
+
8
+ return (
9
+ <span className="progress-bar" data-content={`${done}/${total}`}>
10
+ <span className="progress-bar__container" style={{width: `${percent}%`}}/>
11
+ </span>
12
+ );
13
+ };
@@ -0,0 +1,24 @@
1
+ .progress-bar {
2
+ position: relative;
3
+ display: flex;
4
+ outline: 1px solid #ccc;
5
+ border-radius: 5px;
6
+
7
+ &__container {
8
+ position: absolute;
9
+ height: 100%;
10
+ z-index: -1;
11
+ background-color: #fc0;
12
+ transition: width .25s ease-in-out,
13
+ margin-right .25s ease-in-out;
14
+ }
15
+
16
+ &::after {
17
+ box-sizing: border-box;
18
+ width: 100%;
19
+ padding-left: 10px;
20
+ padding-right: 10px;
21
+ text-align: center;
22
+ align-self: center;
23
+ }
24
+ }
@@ -0,0 +1,29 @@
1
+ import React from 'react';
2
+ import {connect} from 'react-redux';
3
+ import PropTypes from 'prop-types';
4
+ import {isEmpty} from 'lodash';
5
+ import Details from '../../../details';
6
+
7
+ import './index.styl';
8
+
9
+ const History = ({history}) => (
10
+ isEmpty(history)
11
+ ? null
12
+ : <Details
13
+ title='History'
14
+ content={history}
15
+ extendClassNames='details_type_text history'
16
+ />
17
+ );
18
+
19
+ History.propTypes = {
20
+ resultId: PropTypes.string.isRequired,
21
+ // from store
22
+ history: PropTypes.arrayOf(PropTypes.string).isRequired
23
+ };
24
+
25
+ export default connect(({tree}, {resultId}) => {
26
+ const {history = []} = tree.results.byId[resultId];
27
+
28
+ return {history};
29
+ })(History);
@@ -0,0 +1,4 @@
1
+ .history {
2
+ white-space: pre-wrap;
3
+ word-wrap: break-word;
4
+ }