Skip to content

Commit

Permalink
fix(appengine): fix rendering of StageArtifactSelector when artifacts…
Browse files Browse the repository at this point in the history
… are created (#8516)

* fix for GAE artifacts

* WIP tests

* fixeded testssed

* fix(appengine): fix rendering of StageArtifactSelector when artifacts are created

* fix(appengine): fix rendering of StageArtifactSelector when artifacts are created

* fix(appengine): included support for expected artifact within deploy stage

Co-authored-by: Dan Peach <daniel.peach@armory.io>
Co-authored-by: Kevin Woo <kevinawoo@gmail.com>
  • Loading branch information
3 people committed Aug 28, 2020
1 parent fbe0e54 commit 1a20a4a
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 10 deletions.
@@ -1,18 +1,25 @@
import React from 'react';
import classNames from 'classnames';

import { IArtifact, IExpectedArtifact, IPipeline, IStage, StageArtifactSelectorDelegate } from '@spinnaker/core';
import {
IArtifact,
IExpectedArtifact,
IPipeline,
IStage,
StageArtifactSelector,
IArtifactAccountPair,
} from '@spinnaker/core';

interface IConfigFileArtifactListProps {
configArtifacts: any[];
configArtifacts: IArtifactAccountPair[];
pipeline: IPipeline;
stage: IStage;
updateConfigArtifacts: (configArtifacts: any[]) => void;
}

export const ConfigFileArtifactList = (props: IConfigFileArtifactListProps) => {
const addConfigArtifact = () => {
props.updateConfigArtifacts(props.configArtifacts.concat([{}]));
props.updateConfigArtifacts(props.configArtifacts.concat([{ id: '', account: '' }]));
};

const deleteConfigArtifact = (index: number) => {
Expand Down Expand Up @@ -48,12 +55,10 @@ export const ConfigFileArtifactList = (props: IConfigFileArtifactListProps) => {
})}
>
<div className="col-md-9">
<StageArtifactSelectorDelegate
<StageArtifactSelector
artifact={a.artifact}
excludedArtifactTypePatterns={[]}
expectedArtifactId={a.id}
fieldColumns={7}
label={''}
expectedArtifactId={a.artifact == null ? a.id : null}
onArtifactEdited={(artifact: IArtifact) => {
onExpectedArtifactEdited(artifact, i);
}}
Expand Down
@@ -0,0 +1,96 @@
import React from 'react';
import { mock } from 'angular';
import { mount } from 'enzyme';

import { API, IArtifactAccount, IArtifactAccountPair, StageArtifactSelector } from '@spinnaker/core';
import { mockDeployStage, mockPipeline } from '@spinnaker/mocks';
import { ConfigFileArtifactList } from './ConfigFileArtifactList';

describe('<ConfigFileArtifactList/>', () => {
let $http: ng.IHttpBackendService;
beforeEach(
mock.inject(function($httpBackend: ng.IHttpBackendService) {
$http = $httpBackend;
}),
);

it('renders empty children when null/empty artifacts are passed in', () => {
const configArtifacts: IArtifactAccountPair[] = [];
const wrapper = mount(
<ConfigFileArtifactList
configArtifacts={configArtifacts}
pipeline={mockPipeline}
stage={mockDeployStage}
updateConfigArtifacts={() => {}}
/>,
);
expect(wrapper.find(StageArtifactSelector).length).toBe(0);
});

it('renders 2 children of StageArtifactSelector when 2 artifacts are passed in', () => {
const body: IArtifactAccount[] = [
{
name: 'http-acc',
types: ['http'],
},
];
$http.expectGET(`${API.baseUrl}/artifacts/credentials`).respond(200, body);

const configArtifacts = [
{
account: 'http-acc',
id: '123abc',
artifact: {
id: '123abc',
},
},
{
account: 'http-acc',
id: '1234abcd',
artifact: {
id: '1234abcd',
},
},
];

const wrapper = mount(
<ConfigFileArtifactList
configArtifacts={configArtifacts}
pipeline={mockPipeline}
stage={mockDeployStage}
updateConfigArtifacts={() => {}}
/>,
);
expect(wrapper.find(StageArtifactSelector).length).toBe(2);
$http.flush();
});

fit('renders 1 children of StageArtifactSelector when 1 expectedArtifacts are passed in', () => {
const body: IArtifactAccount[] = [
{
name: 'http-acc',
types: ['http'],
},
];
$http.expectGET(`${API.baseUrl}/artifacts/credentials`).respond(200, body);

// artifact intentionally left null indicating an expected artifact
const configArtifacts = [
{
account: 'http-acc',
id: '123abc',
},
];

const wrapper = mount(
<ConfigFileArtifactList
configArtifacts={configArtifacts}
pipeline={mockPipeline}
stage={mockDeployStage}
updateConfigArtifacts={() => {}}
/>,
);
expect(wrapper.find(StageArtifactSelector).length).toBe(1);
$http.flush();
});
});
Expand Up @@ -7,6 +7,7 @@ import {
NgAppengineConfigArtifactDelegate,
IArtifactAccount,
IArtifactAccountPair,
IArtifact,
} from '@spinnaker/core';

import './serverGroupWizard.less';
Expand All @@ -23,11 +24,13 @@ class ConfigArtifact implements IArtifactAccountPair {
public delegate: NgAppengineConfigArtifactDelegate;
public id: string;
public account: string;
public artifact?: IArtifact;

constructor($scope: IScope, artifact = { id: '', account: '' }) {
constructor($scope: IScope, pair: IArtifactAccountPair = { id: '', account: '' }) {
const unserializable = { configurable: false, enumerable: false, writable: false };
this.id = artifact.id;
this.account = artifact.account;
this.id = pair?.id;
this.account = pair.account || pair?.artifact?.artifactAccount;
this.artifact = pair?.artifact;
Object.defineProperty(this, '$scope', { ...unserializable, value: $scope });
const delegate = new NgAppengineConfigArtifactDelegate(this);
const controller = new ExpectedArtifactSelectorViewController(delegate);
Expand Down

0 comments on commit 1a20a4a

Please sign in to comment.