});
describe('getTasksForComponent', () => {
- beforeEach(() => {
- jest.useFakeTimers();
- });
-
- afterEach(() => {
- jest.runOnlyPendingTimers();
- jest.useRealTimers();
- });
-
it('reload component after task progress finished', async () => {
jest
.mocked(getTasksForComponent)
renderComponentContainer();
+ jest.useFakeTimers();
+
// 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
// here).
await waitFor(() => expect(getTasksForComponent).toHaveBeenCalledTimes(1));
jest.runOnlyPendingTimers();
+ jest.useRealTimers();
// Second round, the queue is now empty, hence we assume the previous task
// was done. We immediately load the component again.
expect(getTasksForComponent).toHaveBeenCalledTimes(3);
// Make sure the timeout was cleared. It should not be called again.
+ jest.useFakeTimers();
jest.runAllTimers();
// The number of calls haven't changed.
expect(getComponentNavigation).toHaveBeenCalledTimes(2);
});
expect(getTasksForComponent).toHaveBeenCalledTimes(3);
+
+ jest.useRealTimers();
});
it('reloads component after task progress finished, and moves straight to current', async () => {
renderComponentContainer();
+ jest.useFakeTimers();
+
// 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).
await waitFor(() => {
await waitFor(() => expect(getTasksForComponent).toHaveBeenCalledTimes(1));
jest.runOnlyPendingTimers();
+ jest.useRealTimers();
// 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
renderComponentContainer();
+ jest.useFakeTimers();
+
// First round, a pending task in the queue. This should trigger a reload of the
// status endpoint.
await waitFor(() => expect(getTasksForComponent).toHaveBeenCalledTimes(1));
jest.runOnlyPendingTimers();
+ jest.useRealTimers();
// 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
});
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 () => {
const componentKey = 'foo-component';
jest.mocked(getComponentData).mockResolvedValue({
'/',
);
+ jest.useFakeTimers();
+
await waitFor(() => expect(getTasksForComponent).toHaveBeenCalledTimes(1));
+ expect(mockedReplace).not.toHaveBeenCalled();
jest.runOnlyPendingTimers();
+ jest.useRealTimers();
- expect(mockedReplace).not.toHaveBeenCalled();
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 () => {
'/',
);
+ jest.useFakeTimers();
+
await waitFor(() => expect(getTasksForComponent).toHaveBeenCalledTimes(1));
+ expect(mockedReplace).not.toHaveBeenCalled();
jest.runOnlyPendingTimers();
+ jest.useRealTimers();
- expect(mockedReplace).not.toHaveBeenCalled();
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 () => {
'/',
);
+ jest.useFakeTimers();
+
await waitFor(() => expect(getTasksForComponent).toHaveBeenCalledTimes(1));
+ expect(mockedReplace).not.toHaveBeenCalled();
jest.runOnlyPendingTimers();
+ jest.useRealTimers();
- expect(mockedReplace).not.toHaveBeenCalled();
await waitFor(() => expect(getTasksForComponent).toHaveBeenCalledTimes(2));
- await waitFor(() =>
- expect(mockedReplace).toHaveBeenCalledWith(getPullRequestUrl(componentKey, pullRequestKey)),
- );
+ expect(mockedReplace).toHaveBeenCalledWith(getPullRequestUrl(componentKey, pullRequestKey));
});
});