SONAR-13400 Portfolios page remains unavailable if indexation is completed with failures
}
handleNewStatus = (newIndexationStatus: IndexationStatus) => {
- if (newIndexationStatus.isCompleted) {
- IndexationNotificationHelper.stopPolling();
- }
-
if (this.mounted) {
this.setState({ status: newIndexationStatus });
}
this.stopPolling();
// eslint-disable-next-line promise/catch-or-return
- this.poll(onNewStatus).finally(() => {
- this.interval = setInterval(() => this.poll(onNewStatus), POLLING_INTERVAL_MS);
+ this.poll(onNewStatus).then(status => {
+ if (!status.isCompleted) {
+ this.interval = setInterval(() => this.poll(onNewStatus), POLLING_INTERVAL_MS);
+ }
});
}
const status = await getIndexationStatus();
onNewStatus(status);
+
+ if (status.isCompleted) {
+ this.stopPolling();
+ }
+
+ return status;
}
static markInProgressNotificationAsDisplayed() {
export class PageUnavailableDueToIndexation extends React.PureComponent<Props> {
componentDidUpdate() {
- if (this.props.indexationContext?.status.isCompleted) {
+ if (
+ this.props.indexationContext.status.isCompleted &&
+ !this.props.indexationContext.status.hasFailures
+ ) {
window.location.reload();
}
}
expect(wrapper.state().status).toEqual(expectedStatus);
});
-it('should update the state on new status & stop polling if indexation is complete', () => {
+it('should update the state on new status', () => {
const wrapper = mountRender();
const triggerNewStatus = (IndexationNotificationHelper.startPolling as jest.Mock).mock
triggerNewStatus(newStatus);
expect(wrapper.state().status).toEqual(newStatus);
- expect(IndexationNotificationHelper.stopPolling).toHaveBeenCalled();
});
it('should stop polling when component is destroyed', () => {
it('should properly start & stop polling for indexation status', async () => {
const onNewStatus = jest.fn();
const newStatus: IndexationStatus = {
- isCompleted: true,
+ isCompleted: false,
percentCompleted: 100,
hasFailures: false
};
expect(wrapper).toMatchSnapshot();
});
-it('should refresh the page once the indexation is complete', () => {
+it('should not refresh the page once the indexation is complete if there were failures', () => {
const reload = jest.fn();
delete window.location;
(window as any).location = { reload };
expect(reload).not.toHaveBeenCalled();
- wrapper.setProps({ indexationContext: { status: { isCompleted: true } } });
+ wrapper.setProps({
+ indexationContext: { status: { isCompleted: true, percentCompleted: 100, hasFailures: true } }
+ });
+ wrapper.update();
+
+ expect(reload).not.toHaveBeenCalled();
+});
+
+it('should refresh the page once the indexation is complete if there were NO failures', () => {
+ const reload = jest.fn();
+ delete window.location;
+ (window as any).location = { reload };
+
+ const wrapper = shallowRender();
+
+ expect(reload).not.toHaveBeenCalled();
+
+ wrapper.setProps({
+ indexationContext: { status: { isCompleted: true, percentCompleted: 100, hasFailures: false } }
+ });
wrapper.update();
expect(reload).toHaveBeenCalled();
});
function shallowRender(props?: PageUnavailableDueToIndexation['props']) {
- return shallow(
+ return shallow<PageUnavailableDueToIndexation>(
<PageUnavailableDueToIndexation
indexationContext={{
status: { isCompleted: false, percentCompleted: 23, hasFailures: false }
import { IndexationContextInterface } from '../../../types/indexation';
import withIndexationGuard from '../withIndexationGuard';
-it('should render correctly', () => {
- let wrapper = mountRender();
+it('should not render children because indexation is in progress', () => {
+ const wrapper = mountRender();
expect(wrapper.find(TestComponent).exists()).toBe(false);
+});
+
+it('should not render children because indexation has failures', () => {
+ const wrapper = mountRender({
+ status: { isCompleted: true, percentCompleted: 100, hasFailures: true }
+ });
+ expect(wrapper.find(TestComponent).exists()).toBe(false);
+});
- wrapper = mountRender({
+it('should render children because indexation is completed without failures', () => {
+ const wrapper = mountRender({
status: { isCompleted: true, percentCompleted: 100, hasFailures: false }
});
expect(wrapper.find(TestComponent).exists()).toBe(true);
return (
<IndexationContext.Consumer>
{context =>
- context?.status.isCompleted ? (
+ context?.status.isCompleted && !context?.status.hasFailures ? (
<WrappedComponent {...this.props} />
) : (
<PageUnavailableDueToIndexation pageContext={pageContext} />