Ver código fonte

SONAR-21692 Fix test warnings in ComponentContainer

tags/10.5.0.89998
Viktor Vorona 3 meses atrás
pai
commit
c3503992fb

+ 27
- 27
server/sonar-web/src/main/js/app/components/__tests__/ComponentContainer-test.tsx Ver arquivo

}); });


describe('getTasksForComponent', () => { describe('getTasksForComponent', () => {
beforeEach(() => {
jest.useFakeTimers();
});

afterEach(() => {
jest.runOnlyPendingTimers();
jest.useRealTimers();
});

it('reload component after task progress finished', async () => { it('reload component after task progress finished', async () => {
jest jest
.mocked(getTasksForComponent) .mocked(getTasksForComponent)


renderComponentContainer(); renderComponentContainer();


jest.useFakeTimers();

// First round, there's something in the queue, and component navigation was // First round, there's something in the queue, and component navigation was
// not called again (it's called once at mount, hence the 1 times assertion // not called again (it's called once at mount, hence the 1 times assertion
// here). // here).
await waitFor(() => expect(getTasksForComponent).toHaveBeenCalledTimes(1)); await waitFor(() => expect(getTasksForComponent).toHaveBeenCalledTimes(1));


jest.runOnlyPendingTimers(); jest.runOnlyPendingTimers();
jest.useRealTimers();


// Second round, the queue is now empty, hence we assume the previous task // Second round, the queue is now empty, hence we assume the previous task
// was done. We immediately load the component again. // was done. We immediately load the component again.
expect(getTasksForComponent).toHaveBeenCalledTimes(3); expect(getTasksForComponent).toHaveBeenCalledTimes(3);


// Make sure the timeout was cleared. It should not be called again. // Make sure the timeout was cleared. It should not be called again.
jest.useFakeTimers();
jest.runAllTimers(); jest.runAllTimers();


// The number of calls haven't changed. // The number of calls haven't changed.
expect(getComponentNavigation).toHaveBeenCalledTimes(2); expect(getComponentNavigation).toHaveBeenCalledTimes(2);
}); });
expect(getTasksForComponent).toHaveBeenCalledTimes(3); expect(getTasksForComponent).toHaveBeenCalledTimes(3);

jest.useRealTimers();
}); });


it('reloads component after task progress finished, and moves straight to current', async () => { it('reloads component after task progress finished, and moves straight to current', async () => {


renderComponentContainer(); renderComponentContainer();


jest.useFakeTimers();

// First round, nothing in the queue, and component navigation was not called // First round, nothing in the queue, and component navigation was not called
// again (it's called once at mount, hence the 1 times assertion here). // again (it's called once at mount, hence the 1 times assertion here).
await waitFor(() => { await waitFor(() => {
await waitFor(() => expect(getTasksForComponent).toHaveBeenCalledTimes(1)); await waitFor(() => expect(getTasksForComponent).toHaveBeenCalledTimes(1));


jest.runOnlyPendingTimers(); jest.runOnlyPendingTimers();
jest.useRealTimers();


// Second round, nothing in the queue, BUT a success task is current. This // Second round, nothing in the queue, BUT a success task is current. This
// means the queue was processed too quick for us to see, and we didn't see // means the queue was processed too quick for us to see, and we didn't see


renderComponentContainer(); renderComponentContainer();


jest.useFakeTimers();

// First round, a pending task in the queue. This should trigger a reload of the // First round, a pending task in the queue. This should trigger a reload of the
// status endpoint. // status endpoint.
await waitFor(() => expect(getTasksForComponent).toHaveBeenCalledTimes(1)); await waitFor(() => expect(getTasksForComponent).toHaveBeenCalledTimes(1));


jest.runOnlyPendingTimers(); jest.runOnlyPendingTimers();
jest.useRealTimers();


// Second round, nothing in the queue, and a success task is current. This // Second round, nothing in the queue, and a success task is current. This
// implies the current task was updated, and previously we displayed some information // implies the current task was updated, and previously we displayed some information
}); });


describe('tutorials', () => { describe('tutorials', () => {
beforeEach(() => {
jest.useFakeTimers({ advanceTimers: true });
});
afterEach(() => {
jest.runOnlyPendingTimers();
jest.useRealTimers();
});

it('should redirect to project main branch dashboard from tutorials when receiving new related scan report', async () => { it('should redirect to project main branch dashboard from tutorials when receiving new related scan report', async () => {
const componentKey = 'foo-component'; const componentKey = 'foo-component';
jest.mocked(getComponentData).mockResolvedValue({ jest.mocked(getComponentData).mockResolvedValue({
'/', '/',
); );


jest.useFakeTimers();

await waitFor(() => expect(getTasksForComponent).toHaveBeenCalledTimes(1)); await waitFor(() => expect(getTasksForComponent).toHaveBeenCalledTimes(1));
expect(mockedReplace).not.toHaveBeenCalled();


jest.runOnlyPendingTimers(); jest.runOnlyPendingTimers();
jest.useRealTimers();


expect(mockedReplace).not.toHaveBeenCalled();
await waitFor(() => expect(getTasksForComponent).toHaveBeenCalledTimes(2)); await waitFor(() => expect(getTasksForComponent).toHaveBeenCalledTimes(2));
await waitFor(() => expect(mockedReplace).toHaveBeenCalledWith(getProjectUrl(componentKey)));
expect(mockedReplace).toHaveBeenCalledWith(getProjectUrl(componentKey));
}); });


it('should redirect to project branch dashboard from tutorials when receiving new related scan report', async () => { it('should redirect to project branch dashboard from tutorials when receiving new related scan report', async () => {
'/', '/',
); );


jest.useFakeTimers();

await waitFor(() => expect(getTasksForComponent).toHaveBeenCalledTimes(1)); await waitFor(() => expect(getTasksForComponent).toHaveBeenCalledTimes(1));
expect(mockedReplace).not.toHaveBeenCalled();


jest.runOnlyPendingTimers(); jest.runOnlyPendingTimers();
jest.useRealTimers();


expect(mockedReplace).not.toHaveBeenCalled();
await waitFor(() => expect(getTasksForComponent).toHaveBeenCalledTimes(2)); await waitFor(() => expect(getTasksForComponent).toHaveBeenCalledTimes(2));
await waitFor(() =>
expect(mockedReplace).toHaveBeenCalledWith(getProjectUrl(componentKey, branchName)),
);
expect(mockedReplace).toHaveBeenCalledWith(getProjectUrl(componentKey, branchName));
}); });


it('should redirect to project pull request dashboard from tutorials when receiving new related scan report', async () => { it('should redirect to project pull request dashboard from tutorials when receiving new related scan report', async () => {
'/', '/',
); );


jest.useFakeTimers();

await waitFor(() => expect(getTasksForComponent).toHaveBeenCalledTimes(1)); await waitFor(() => expect(getTasksForComponent).toHaveBeenCalledTimes(1));
expect(mockedReplace).not.toHaveBeenCalled();


jest.runOnlyPendingTimers(); jest.runOnlyPendingTimers();
jest.useRealTimers();


expect(mockedReplace).not.toHaveBeenCalled();
await waitFor(() => expect(getTasksForComponent).toHaveBeenCalledTimes(2)); await waitFor(() => expect(getTasksForComponent).toHaveBeenCalledTimes(2));
await waitFor(() =>
expect(mockedReplace).toHaveBeenCalledWith(getPullRequestUrl(componentKey, pullRequestKey)),
);
expect(mockedReplace).toHaveBeenCalledWith(getPullRequestUrl(componentKey, pullRequestKey));
}); });
}); });



Carregando…
Cancelar
Salvar