From bb28f831f22cd7531dc4869d9faca52dddcf3971 Mon Sep 17 00:00:00 2001 From: Philippe Perrin Date: Mon, 1 Mar 2021 15:32:34 +0100 Subject: SONAR-14516 Remove hardcoded usage of 'master' from webapp --- .../js/apps/projectBaseline/components/App.tsx | 10 +- .../components/ProjectBaselineSelector.tsx | 4 +- .../components/__tests__/App-test.tsx | 11 +- .../__tests__/ProjectBaselineSelector-test.tsx | 3 +- .../__tests__/__snapshots__/App-test.tsx.snap | 181 ++++++++++++++++++++- 5 files changed, 201 insertions(+), 8 deletions(-) (limited to 'server') diff --git a/server/sonar-web/src/main/js/apps/projectBaseline/components/App.tsx b/server/sonar-web/src/main/js/apps/projectBaseline/components/App.tsx index 32a1c54100d..ed9efc5b521 100644 --- a/server/sonar-web/src/main/js/apps/projectBaseline/components/App.tsx +++ b/server/sonar-web/src/main/js/apps/projectBaseline/components/App.tsx @@ -34,6 +34,7 @@ import BranchList from './BranchList'; import ProjectBaselineSelector from './ProjectBaselineSelector'; interface Props { + branchLike: Branch; branchLikes: BranchLike[]; branchesEnabled?: boolean; canAdmin?: boolean; @@ -120,13 +121,15 @@ export default class App extends React.PureComponent { } fetchLeakPeriodSetting() { + const { branchLike, branchesEnabled, component } = this.props; + this.setState({ loading: true }); Promise.all([ getNewCodePeriod(), getNewCodePeriod({ - branch: !this.props.branchesEnabled ? 'master' : undefined, - project: this.props.component.key + branch: branchesEnabled ? undefined : branchLike.name, + project: component.key }) ]).then( ([generalSetting, setting]) => { @@ -226,7 +229,7 @@ export default class App extends React.PureComponent { }; render() { - const { branchesEnabled, canAdmin, component } = this.props; + const { branchesEnabled, canAdmin, component, branchLike } = this.props; const { analysis, branchList, @@ -256,6 +259,7 @@ export default class App extends React.PureComponent { {generalSetting && overrideGeneralSetting !== undefined && ( diff --git a/server/sonar-web/src/main/js/apps/projectBaseline/components/__tests__/App-test.tsx b/server/sonar-web/src/main/js/apps/projectBaseline/components/__tests__/App-test.tsx index f4c3fd6bc94..65cd8e22f08 100644 --- a/server/sonar-web/src/main/js/apps/projectBaseline/components/__tests__/App-test.tsx +++ b/server/sonar-web/src/main/js/apps/projectBaseline/components/__tests__/App-test.tsx @@ -35,8 +35,14 @@ jest.mock('../../../../api/newCodePeriod', () => ({ setNewCodePeriod: jest.fn().mockResolvedValue({}) })); -it('should render correctly', () => { - expect(shallowRender()).toMatchSnapshot(); +it('should render correctly', async () => { + let wrapper = shallowRender(); + await waitAndUpdate(wrapper); + expect(wrapper).toMatchSnapshot(); + + wrapper = shallowRender({ branchesEnabled: false }); + await waitAndUpdate(wrapper); + expect(wrapper).toMatchSnapshot('without branch support'); }); it('should initialize correctly', async () => { @@ -100,6 +106,7 @@ it('should handle errors gracefully', async () => { function shallowRender(props: Partial = {}) { return shallow( { @@ -105,6 +105,7 @@ it('should disable the save button when date is invalid', () => { function shallowRender(props: Partial = {}) { return shallow( - +
+

+ project_baseline.default_setting +

+ +
+ + + settings.state.saved + +
+
+
+

+ project_baseline.configure_branches +

+ +
+
+ + +`; + +exports[`should render correctly: without branch support 1`] = ` + + +
+ +
+ +
+ + + settings.state.saved + +
+
`; -- cgit v1.2.3