}
getAvailableQualifiers () {
- return difference(
- this.props.topQualifiers,
- this.props.permissionTemplate.defaultFor);
+ const topQualifiers = this.props.organization && !this.props.organization.isDefault ?
+ ['TRK'] :
+ this.props.topQualifiers;
+ return difference(topQualifiers, this.props.permissionTemplate.defaultFor);
}
renderDropdownIcon (icon) {
export default class Defaults extends React.Component {
static propTypes = {
+ organization: React.PropTypes.object,
permissionTemplate: PermissionTemplateType.isRequired
};
render () {
- const qualifiers = sortBy(this.props.permissionTemplate.defaultFor)
+ const qualifiersToDisplay = this.props.organization && !this.props.organization.isDefault ?
+ ['TRK'] :
+ this.props.permissionTemplate.defaultFor;
+
+ const qualifiers = sortBy(qualifiersToDisplay)
.map(qualifier => translate('qualifiers', qualifier))
.join(', ');
{t.defaultFor.length > 0 && (
<div className="spacer-top js-defaults">
- <Defaults permissionTemplate={this.props.permissionTemplate}/>
+ <Defaults
+ permissionTemplate={this.props.permissionTemplate}
+ organization={organization}/>
</div>
)}
const setDefault = renderActionsCell({ permissionTemplate }).find('.js-set-default');
expect(setDefault.length).toBe(0);
});
+
+it('should display all qualifiers for default organization', () => {
+ const organization = { isDefault: true };
+ const setDefault = renderActionsCell({ organization }).find('.js-set-default');
+ expect(setDefault.length).toBe(2);
+ expect(setDefault.at(0).prop('data-qualifier')).toBe('TRK');
+ expect(setDefault.at(1).prop('data-qualifier')).toBe('VW');
+});
+
+it('should display only projects for custom organization', () => {
+ const organization = { isDefault: false };
+ const setDefault = renderActionsCell({ organization }).find('.js-set-default');
+ expect(setDefault.length).toBe(1);
+ expect(setDefault.at(0).prop('data-qualifier')).toBe('TRK');
+});
it('should render one qualifier', () => {
const sample = { ...SAMPLE, defaultFor: ['DEV'] };
const output = shallow(<Defaults permissionTemplate={sample}/>);
- expect(output.text()).toContain('DEV');
+ expect(output).toMatchSnapshot();
});
it('should render several qualifiers', () => {
const sample = { ...SAMPLE, defaultFor: ['TRK', 'VW'] };
const output = shallow(<Defaults permissionTemplate={sample}/>);
- expect(output.text()).toContain('TRK');
+ expect(output).toMatchSnapshot();
+});
+
+it('should render several qualifiers for default organization', () => {
+ const sample = { ...SAMPLE, defaultFor: ['TRK', 'VW'] };
+ const organization = { isDefault: true };
+ const output = shallow(<Defaults permissionTemplate={sample} organization={organization}/>);
+ expect(output).toMatchSnapshot();
+});
+
+it('should render only projects for custom organization', () => {
+ const sample = { ...SAMPLE, defaultFor: ['TRK', 'VW'] };
+ const organization = { isDefault: false };
+ const output = shallow(<Defaults permissionTemplate={sample} organization={organization}/>);
+ expect(output).toMatchSnapshot();
});
--- /dev/null
+exports[`test should render one qualifier 1`] = `
+<div>
+ <span
+ className="badge spacer-right">
+ default
+ for
+ qualifiers.DEV
+ </span>
+</div>
+`;
+
+exports[`test should render only projects for custom organization 1`] = `
+<div>
+ <span
+ className="badge spacer-right">
+ default
+ for
+ qualifiers.TRK
+ </span>
+</div>
+`;
+
+exports[`test should render several qualifiers 1`] = `
+<div>
+ <span
+ className="badge spacer-right">
+ default
+ for
+ qualifiers.TRK, qualifiers.VW
+ </span>
+</div>
+`;
+
+exports[`test should render several qualifiers for default organization 1`] = `
+<div>
+ <span
+ className="badge spacer-right">
+ default
+ for
+ qualifiers.TRK, qualifiers.VW
+ </span>
+</div>
+`;