Skip to content

Commit 077f7e2

Browse files
harikakondurclaude
andcommitted
test(link-checker): add tests for no-match visibility reload guard and cursor pagination [ES-524]
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent b947251 commit 077f7e2

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

apps/link-checker/__tests__/locations/Page.spec.tsx

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,80 @@ describe('Page component', () => {
374374
expect(reload).not.toHaveBeenCalled();
375375
});
376376

377+
it('does not reload when getForOrganization returns no match for the current space/environment', async () => {
378+
const reload = vi.fn();
379+
Object.defineProperty(window, 'location', {
380+
value: { reload },
381+
configurable: true,
382+
writable: true,
383+
});
384+
385+
mockSdk.cma.appInstallation = {
386+
getForOrganization: vi.fn().mockResolvedValue({
387+
items: [
388+
{
389+
sys: {
390+
space: { sys: { id: 'other-space' } },
391+
environment: { sys: { id: 'other-env' } },
392+
},
393+
parameters: { selectedContentTypeIds: ['article'] },
394+
},
395+
],
396+
}),
397+
};
398+
399+
render(<Page />);
400+
401+
triggerVisibilityChange('hidden');
402+
triggerVisibilityChange('visible');
403+
404+
await waitFor(() => {
405+
expect(mockSdk.cma.appInstallation.getForOrganization).toHaveBeenCalled();
406+
});
407+
expect(reload).not.toHaveBeenCalled();
408+
});
409+
410+
it('uses cursor pagination and passes sys.id[gt] on subsequent entry fetches', async () => {
411+
const batch1 = Array.from({ length: 100 }, (_, i) => ({
412+
sys: { id: `entry-batch1-${i}`, contentType: { sys: { id: 'article' } } },
413+
fields: {
414+
title: { 'en-US': `Entry ${i}` },
415+
body: { 'en-US': `https://example.com/link-${i}` },
416+
},
417+
}));
418+
const batch2 = [
419+
{
420+
sys: { id: 'entry-batch2-0', contentType: { sys: { id: 'article' } } },
421+
fields: {
422+
title: { 'en-US': 'Last entry' },
423+
body: { 'en-US': 'https://example.com/last' },
424+
},
425+
},
426+
];
427+
428+
const getMany = vi
429+
.fn()
430+
.mockResolvedValueOnce({ items: batch1 })
431+
.mockResolvedValueOnce({ items: batch2 });
432+
433+
mockSdk.cma.entry = { getMany };
434+
435+
render(<Page />);
436+
fireEvent.click(screen.getByRole('button', { name: 'Find links' }));
437+
438+
await screen.findByText('https://example.com/last');
439+
440+
expect(getMany).toHaveBeenCalledTimes(2);
441+
expect(getMany).toHaveBeenNthCalledWith(
442+
2,
443+
expect.objectContaining({
444+
query: expect.objectContaining({
445+
'sys.id[gt]': 'entry-batch1-99',
446+
}),
447+
})
448+
);
449+
});
450+
377451
it('checks www URLs as absolute https URLs instead of resolving them against the current domain', async () => {
378452
const createWithResponse = vi.fn().mockResolvedValue({
379453
response: { body: JSON.stringify({ status: 200 }) },

0 commit comments

Comments
 (0)