((resolve) => {
+ resolvePromise = resolve;
+ });
+
+ mockFetchContributors.mockReturnValue(promise);
+
+ // Simulated component container that handles loading state
+ const LoadingContainer = ({ isPending }: { isPending: boolean }) => {
+ if (isPending) {
+ return Loading the collective...
;
+ }
+ return ;
+ };
+
+ const { rerender } = render();
+ expect(screen.getByRole('status')).toHaveTextContent('Loading the collective...');
+
+ resolvePromise([]);
+ await promise;
+
+ rerender();
+ expect(screen.queryByRole('status')).not.toBeInTheDocument();
+ expect(screen.getByRole('textbox')).toBeInTheDocument();
+ });
+
+ // --- Test Case 3 ---
+ it('asserts local cache layers are queried before triggering database retrievals', async () => {
+ const cachedData: Contributor[] = [
+ {
+ id: 2,
+ login: 'cached-contributor',
+ avatar_url: 'https://example.com/cached.png',
+ contributions: 10,
+ html_url: 'https://github.com/cached',
+ },
+ ];
+ mockCache.get.mockReturnValue(cachedData);
+
+ const getContributorsData = async () => {
+ const cacheVal = mockCache.get('contributors_search_cache');
+ if (cacheVal) return cacheVal;
+ return mockFetchContributors();
+ };
+
+ const result = await getContributorsData();
+
+ expect(mockCache.get).toHaveBeenCalledWith('contributors_search_cache');
+ expect(mockFetchContributors).not.toHaveBeenCalled();
+ expect(result).toEqual(cachedData);
+
+ render();
+ expect(screen.getByText('cached-contributor')).toBeInTheDocument();
+ });
+
+ // --- Test Case 4 ---
+ it('verifies correct fallback procedures during fake endpoint timeout blocks', async () => {
+ mockFetchContributors.mockRejectedValue(new Error('Gateway Timeout'));
+
+ const getContributorsWithFallback = async () => {
+ try {
+ return await mockFetchContributors();
+ } catch {
+ return [];
+ }
+ };
+
+ const data = await getContributorsWithFallback();
+ expect(data).toEqual([]);
+
+ render();
+ // "No architects found" should render because data is empty and we filter it
+ expect(screen.getByText('No architects found')).toBeInTheDocument();
+ });
+
+ // --- Test Case 5 ---
+ it('asserts complete cache sync is written on success callbacks', async () => {
+ const freshData: Contributor[] = [
+ {
+ id: 3,
+ login: 'fresh-contributor',
+ avatar_url: 'https://example.com/fresh.png',
+ contributions: 15,
+ html_url: 'https://github.com/fresh',
+ },
+ ];
+ mockFetchContributors.mockResolvedValue(freshData);
+
+ const syncAndFetch = async () => {
+ const data = await mockFetchContributors();
+ mockCache.set('contributors_search_cache', data);
+ return data;
+ };
+
+ const result = await syncAndFetch();
+ expect(mockCache.set).toHaveBeenCalledWith('contributors_search_cache', freshData);
+
+ render();
+ expect(screen.getByText('fresh-contributor')).toBeInTheDocument();
+ });
+});