|
| 1 | +import React from 'react'; |
| 2 | +import {defaults} from 'lodash'; |
| 3 | +import proxyquire from 'proxyquire'; |
| 4 | +import {mkConnectedComponent} from 'test/unit/lib/static/components/utils'; |
| 5 | +import {mkBrowser, mkResult, mkStateTree} from 'test/unit/lib/static/state-utils'; |
| 6 | +import {SKIPPED} from 'lib/constants/test-statuses'; |
| 7 | +import actionNames from 'lib/static/modules/action-names'; |
| 8 | +import viewModes from 'lib/constants/view-modes'; |
| 9 | +import {EXPAND_ALL} from 'lib/constants/expand-modes'; |
| 10 | + |
| 11 | +describe('<BrowserTitle/>', () => { |
| 12 | + const sandbox = sinon.sandbox.create(); |
| 13 | + let BrowserTitle, actionsStub, queryParams; |
| 14 | + |
| 15 | + const mkBrowserTitleComponent = (props = {}, initialState = {}) => { |
| 16 | + props = defaults(props, { |
| 17 | + title: 'default_title', |
| 18 | + browserId: 'default_bro', |
| 19 | + browserName: 'default_name', |
| 20 | + lastResultId: 'default_res', |
| 21 | + handler: () => {} |
| 22 | + }); |
| 23 | + initialState = defaults(initialState, { |
| 24 | + tree: mkStateTree() |
| 25 | + }); |
| 26 | + |
| 27 | + return mkConnectedComponent(<BrowserTitle {...props} />, {initialState}); |
| 28 | + }; |
| 29 | + |
| 30 | + beforeEach(() => { |
| 31 | + actionsStub = { |
| 32 | + copyTestLink: sandbox.stub().returns({type: actionNames.COPY_TEST_LINK}) |
| 33 | + }; |
| 34 | + |
| 35 | + queryParams = { |
| 36 | + appendQuery: sandbox.stub().returns(null) |
| 37 | + }; |
| 38 | + |
| 39 | + BrowserTitle = proxyquire('lib/static/components/section/title/browser', { |
| 40 | + '../../../modules/actions': actionsStub, |
| 41 | + '../../../modules/query-params': queryParams |
| 42 | + }).default; |
| 43 | + }); |
| 44 | + |
| 45 | + describe('<ClipboardButton/>', () => { |
| 46 | + it('should call action "onCopyTestLink" on click', () => { |
| 47 | + const browsersById = mkBrowser({id: 'yabro', name: 'yabro', resultIds: ['default_res']}); |
| 48 | + const resultsById = mkResult({id: 'default_res', status: SKIPPED, skipReason: 'some-reason'}); |
| 49 | + const tree = mkStateTree({browsersById, resultsById}); |
| 50 | + |
| 51 | + const component = mkBrowserTitleComponent({browserId: 'yabro'}, {tree}); |
| 52 | + component.find('ClipboardButton').simulate('click'); |
| 53 | + |
| 54 | + assert.calledOnce(actionsStub.copyTestLink); |
| 55 | + assert.calledWithExactly(actionsStub.copyTestLink); |
| 56 | + }); |
| 57 | + |
| 58 | + it('should call "appendQuery" with correct arguments', () => { |
| 59 | + const browsersById = mkBrowser({id: 'yabro', name: 'yabro', parentId: 'test'}); |
| 60 | + const resultsById = mkResult({id: 'default_res', status: SKIPPED, skipReason: 'some-reason'}); |
| 61 | + const tree = mkStateTree({browsersById, resultsById}); |
| 62 | + |
| 63 | + const component = mkBrowserTitleComponent({browserId: 'yabro', browserName: 'yabro'}, {tree}); |
| 64 | + |
| 65 | + // call prop to simulate click due to multiple requires in ClipboardButton |
| 66 | + component.find('ClipboardButton').prop('option-text')(); |
| 67 | + |
| 68 | + assert.calledOnce(queryParams.appendQuery); |
| 69 | + assert.calledWithExactly(queryParams.appendQuery, 'about:blank', { |
| 70 | + browser: 'yabro', |
| 71 | + testNameFilter: 'test', |
| 72 | + strictMatchFilter: true, |
| 73 | + retryIndex: 0, |
| 74 | + viewModes: viewModes.ALL, |
| 75 | + expand: EXPAND_ALL, |
| 76 | + groupByError: false |
| 77 | + }); |
| 78 | + }); |
| 79 | + }); |
| 80 | +}); |
| 81 | + |
0 commit comments