fix: infinite loading bug

Signed-off-by: Raul Kele <raulkeleblk@gmail.com>
This commit is contained in:
Raul Kele 2023-01-31 16:02:06 +02:00
parent 23416883c7
commit 514475a33f
5 changed files with 27 additions and 10 deletions

View File

@ -101,4 +101,11 @@ describe('Dependencies tab', () => {
render(<RouterDependsWrapper />);
await waitFor(() => expect(error).toBeCalledTimes(1));
});
it('should stop loading if the api response contains an error', async () => {
jest.spyOn(api, 'get').mockResolvedValue({ status: 500, data: { errors: ['test error'] } });
jest.spyOn(console, 'error').mockImplementation(() => {});
render(<RouterDependsWrapper />);
expect(await screen.findByText(/Nothing found/i)).toBeInTheDocument();
});
});

View File

@ -101,4 +101,11 @@ describe('Dependents tab', () => {
render(<RouterDependsWrapper />);
await waitFor(() => expect(error).toBeCalledTimes(1));
});
it('should stop loading if the api response contains an error', async () => {
jest.spyOn(api, 'get').mockResolvedValue({ status: 500, data: { errors: ['test error'] } });
jest.spyOn(console, 'error').mockImplementation(() => {});
render(<RouterDependsWrapper />);
expect(await screen.findByText(/Nothing found/i)).toBeInTheDocument();
});
});

View File

@ -230,8 +230,9 @@ afterEach(() => {
describe('Tags details', () => {
it('should show tabs and allow nagivation between them', async () => {
jest.spyOn(api, 'get').mockResolvedValue({ status: 200, data: { data: mockImage } });
jest.spyOn(api, 'get').mockResolvedValueOnce({ status: 200, data: { data: mockImage } });
render(<TagDetailsThemeWrapper />);
jest.spyOn(api, 'get').mockResolvedValue({ status: 500, data: { data: { errors: ['test error'] } } });
const dependenciesTab = await screen.findByTestId('dependencies-tab');
fireEvent.click(dependenciesTab);
expect(await screen.findByTestId('depends-on-container')).toBeInTheDocument();

View File

@ -89,7 +89,6 @@ function DependsOn(props) {
)
.then((response) => {
if (response.data && response.data.data) {
if (!isEmpty(response.data.data.BaseImageList?.Results)) {
let imagesData = response.data.data.BaseImageList?.Results?.map((img) => mapToImage(img));
const newImageList = [...images, ...imagesData];
setImages(newImageList);
@ -97,7 +96,8 @@ function DependsOn(props) {
response.data.data.BaseImageList.Page?.ItemCount < EXPLORE_PAGE_SIZE ||
newImageList.length >= response.data.data.BaseImageList?.Page?.TotalCount
);
}
} else if (response.data.errors) {
setIsEndOfList(true);
}
setIsLoading(false);
})

View File

@ -96,6 +96,8 @@ function IsDependentOn(props) {
response.data.data.DerivedImageList?.Page?.ItemCount < EXPLORE_PAGE_SIZE ||
newImageList.length >= response.data.data.DerivedImageList?.Page?.TotalCount
);
} else if (response.data.errors) {
setIsEndOfList(true);
}
setIsLoading(false);
})