[JENKINS-36618] implement a unit test that exhibits the bug: this requires Enzyme.mount to expose a duplicate key error in React, and some correspond work to integrate jsdom and make ExtensionStore happy. next step, reduce boilerplate

This commit is contained in:
Cliff Meyers 2016-07-12 13:16:54 -04:00
parent 07c80ed822
commit 74bc89dfb0
5 changed files with 159 additions and 25 deletions

View File

@ -62,10 +62,12 @@ export default class Pipelines extends Component {
headers={headers}
>
{ pipelineRecords
.map(pipeline => <PipelineRowItem
key={pipeline.name} pipeline={pipeline}
showOrganization={!organization}
/>)
.map(pipeline => (
<PipelineRowItem
key={pipeline.name} pipeline={pipeline}
showOrganization={!organization}
/>
))
}
</Table>
</article>

View File

@ -0,0 +1,87 @@
/**
* Created by cmeyers on 7/12/16.
*/
export const pipelinesDupName = [
{
"_class": "io.jenkins.blueocean.service.embedded.rest.MultiBranchPipelineImpl",
"_links": {
"self": {
"_class": "io.jenkins.blueocean.rest.hal.Link",
"href": "/blue/rest/organizations/jenkins/pipelines/blueocean-pr-testing/"
},
"branches": {
"_class": "io.jenkins.blueocean.rest.hal.Link",
"href": "/blue/rest/organizations/jenkins/pipelines/blueocean-pr-testing/branches/"
},
"actions": {
"_class": "io.jenkins.blueocean.rest.hal.Link",
"href": "/blue/rest/organizations/jenkins/pipelines/blueocean-pr-testing/actions/"
},
"runs": {
"_class": "io.jenkins.blueocean.rest.hal.Link",
"href": "/blue/rest/organizations/jenkins/pipelines/blueocean-pr-testing/runs/"
},
"queue": {
"_class": "io.jenkins.blueocean.rest.hal.Link",
"href": "/blue/rest/organizations/jenkins/pipelines/blueocean-pr-testing/queue/"
}
},
"actions": [],
"displayName": "blueocean-pr-testing",
"fullName": "blueocean-pr-testing",
"name": "blueocean-pr-testing",
"organization": "jenkins",
"estimatedDurationInMillis": 1152,
"numberOfFolders": 0,
"numberOfPipelines": 8,
"weatherScore": 100,
"branchNames": ["develop", "master", "cliff-60s", "feature%2Fxxx", "feature%2Fcliff-2", "cliff-120s", "feature%2Fcliff-1", "feature%2Fyyy"],
"numberOfFailingBranches": 0,
"numberOfFailingPullRequests": 0,
"numberOfSuccessfulBranches": 8,
"numberOfSuccessfulPullRequests": 0,
"totalNumberOfBranches": 8,
"totalNumberOfPullRequests": 0
},
{
"_class": "io.jenkins.blueocean.service.embedded.rest.MultiBranchPipelineImpl",
"_links": {
"self": {
"_class": "io.jenkins.blueocean.rest.hal.Link",
"href": "/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/blueocean-pr-testing/"
},
"branches": {
"_class": "io.jenkins.blueocean.rest.hal.Link",
"href": "/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/blueocean-pr-testing/branches/"
},
"actions": {
"_class": "io.jenkins.blueocean.rest.hal.Link",
"href": "/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/blueocean-pr-testing/actions/"
},
"runs": {
"_class": "io.jenkins.blueocean.rest.hal.Link",
"href": "/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/blueocean-pr-testing/runs/"
},
"queue": {
"_class": "io.jenkins.blueocean.rest.hal.Link",
"href": "/blue/rest/organizations/jenkins/pipelines/folder1/pipelines/blueocean-pr-testing/queue/"
}
},
"actions": [],
"displayName": "blueocean-pr-testing",
"fullName": "folder1/blueocean-pr-testing",
"name": "blueocean-pr-testing",
"organization": "jenkins",
"estimatedDurationInMillis": 1206,
"numberOfFolders": 0,
"numberOfPipelines": 8,
"weatherScore": 100,
"branchNames": ["feature%2Fcliff-1", "develop", "feature%2Fyyy", "feature%2Fcliff-2", "feature%2Fxxx", "cliff-120s", "cliff-60s", "master"],
"numberOfFailingBranches": 0,
"numberOfFailingPullRequests": 0,
"numberOfSuccessfulBranches": 8,
"numberOfSuccessfulPullRequests": 0,
"totalNumberOfBranches": 8,
"totalNumberOfPullRequests": 0
}
];

View File

@ -1,43 +1,88 @@
var jsdom = require('jsdom').jsdom;
var exposedProperties = ['window', 'navigator', 'document'];
global.document = jsdom('');
global.window = document.defaultView;
Object.keys(document.defaultView).forEach((property) => {
if (typeof global[property] === 'undefined') {
exposedProperties.push(property);
global[property] = document.defaultView[property];
}
});
global.navigator = {
userAgent: 'node.js',
};
import React from 'react';
import { assert} from 'chai';
import { assert } from 'chai';
import { mount, render, shallow } from 'enzyme';
import sd from 'skin-deep';
import Immutable from 'immutable';
import { store as ExtensionStore } from '@jenkins-cd/js-extensions';
import Pipelines from '../../main/js/components/Pipelines.jsx';
import { pipelines } from './pipelines';
import { pipelines } from './data/pipelines/pipelinesSingle';
import { pipelinesDupName } from './data/pipelines/pipelinesTwoJobsSameName';
const
resultArrayHeaders = ['Name', 'Status', 'Branches', 'Pull Requests', '']
;
describe("pipelines", () => {
describe('Pipelines', () => {
let tree;
const pipelineList = Immutable.fromJS(pipelines);
const config = {
getRootURL: () => '/',
};
const params = {};
beforeEach(() => {
tree = sd.shallowRender(
() => React.createElement(Pipelines), // For some reason using a fn turns on context
{
pipelines: Immutable.fromJS(pipelines),
params,
describe('basic table rendering', () => {
beforeEach(() => {
tree = sd.shallowRender(
() => React.createElement(Pipelines), // For some reason using a fn turns on context
{
pipelines: pipelineList,
params,
config,
}
);
});
it('check header to be as expected', () => {
const header = tree.subTree('Table').getRenderOutput();
assert.equal(header.props.headers.length, resultArrayHeaders.length);
});
it('check rows number to be as expected', () => {
const row = tree.everySubTree('PipelineRowItem');
assert.equal(row.length, 2);
});
});
describe('duplicate job names', () => {
it('should render two rows when job names are duplicated across folders', () => {
const context = {
config,
}
);
});
params,
pipelines: pipelinesDupName,
};
it("renders pipelines - check header to be as expected", () => {
const header = tree.subTree('Table').getRenderOutput();
assert.equal(header.props.headers.length, resultArrayHeaders.length);
});
ExtensionStore.init({
extensionDataProvider: function () {},
});
it("renders pipelines - check rows number to be as expected", () => {
const row = tree.everySubTree('PipelineRowItem');
assert.equal(row.length, 2);
});
const wrapper = mount(
<Pipelines />,
{ context },
);
assert.equal(wrapper.find('PipelineRowItem').length, 2);
});
});
});

View File

@ -10,7 +10,7 @@ import {
pipelines as pipelinesSelector,
currentRuns as currentRunsSelector,
} from '../../main/js/redux';
import { pipelines } from './pipelines';
import { pipelines } from './data/pipelines/pipelinesSingle';
import { latestRuns } from './data/runs/latestRuns';
import job_crud_created_multibranch from './data/sse/job_crud_created_multibranch';
import fetchedBranches from './data/branches/latestBranches';