Skip to content

Commit

Permalink
Results list block | Removed code causing SSR to be null (#1994)
Browse files Browse the repository at this point in the history
* Removed code causing SSR to be null.

* added logic to default results list server side. Fixed tests.
  • Loading branch information
vgalatro authored Mar 13, 2024
1 parent 7173e24 commit 8792858
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 36 deletions.
4 changes: 0 additions & 4 deletions blocks/results-list-block/features/results-list/default.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ const ResultsList = ({ customFields }) => {
const configuredSize =
parseInt(contentConfigValues?.size, 10) || parseInt(contentConfigValues?.feedSize, 10) || 10;

if (isServerSideLazy) {
// On Server
return null;
}
return (
<LazyLoad enabled={lazyLoad && !isAdmin}>
<HeadingSection>
Expand Down
14 changes: 7 additions & 7 deletions blocks/results-list-block/features/results-list/default.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe("Results List", () => {
};

const { unmount } = render(<ResultsList customFields={customFields} />);
expect(screen.queryByText("Results")).toBeInTheDocument();
expect(screen.getByText("Results")).toBeInTheDocument();
unmount();
});

Expand All @@ -80,7 +80,7 @@ describe("Results List", () => {
};

const { unmount } = render(<ResultsList customFields={customFields} />);
expect(screen.queryByText("Results")).toBeInTheDocument();
expect(screen.getByText("Results")).toBeInTheDocument();
unmount();
});
});
Expand Down Expand Up @@ -132,7 +132,7 @@ describe("configured values", () => {
};

const { unmount } = render(<ResultsList customFields={customFields} />);
expect(screen.queryByText(/"configuredOffset":0/i)).toBeInTheDocument();
expect(screen.getByText(/"configuredOffset":0/i)).toBeInTheDocument();
unmount();
});
it("should default size to 10 if not configured", () => {
Expand All @@ -145,7 +145,7 @@ describe("configured values", () => {
};

const { unmount } = render(<ResultsList customFields={customFields} />);
expect(screen.queryByText(/"configuredSize":10/i)).toBeInTheDocument();
expect(screen.getByText(/"configuredSize":10/i)).toBeInTheDocument();
unmount();
});
});
Expand All @@ -161,7 +161,7 @@ describe("isServerSideLazy flag", () => {
};

const { unmount } = render(<ResultsList customFields={customFields} />);
expect(screen.queryByText(/"isServerSideLazy":false/i)).toBeInTheDocument();
expect(screen.getByText(/"isServerSideLazy":false/i)).toBeInTheDocument();
unmount();
});
it("should be false if isAdmin is true", () => {
Expand All @@ -181,7 +181,7 @@ describe("isServerSideLazy flag", () => {
};

const { unmount } = render(<ResultsList customFields={customFields} />);
expect(screen.queryByText(/"isServerSideLazy":false/i)).toBeInTheDocument();
expect(screen.getByText(/"isServerSideLazy":false/i)).toBeInTheDocument();
unmount();
});
it("should be true if isServerSide is true, admin is false, and lazyload is false", () => {
Expand All @@ -201,7 +201,7 @@ describe("isServerSideLazy flag", () => {
};

const { unmount } = render(<ResultsList customFields={customFields} />);
expect(screen.queryByText(/"isServerSideLazy":true/i)).toBeInTheDocument();
expect(screen.getByText(/"isServerSideLazy":true/i)).toBeInTheDocument();
unmount();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const Results = ({
}`,
});

const [resultList, alterResultList] = useReducer(reduceResultList, { content_elements: [] });
const [resultList, alterResultList] = useReducer(reduceResultList, { content_elements: requestedResultList?.content_elements || [] });

useEffect(() => {
if (requestedResultList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,7 @@ describe("seeMore", () => {
it("should trigger a state update", () => {
useContent
.mockReset()
.mockReturnValueOnce({})
.mockReturnValueOnce(mockContent[0])
.mockReturnValueOnce({})
.mockReturnValueOnce(mockContent[1]);

const { unmount } = render(
Expand All @@ -168,7 +166,7 @@ describe("seeMore", () => {
});

it("should not show for the last items", () => {
useContent.mockReset().mockReturnValueOnce({}).mockReturnValueOnce(mockLastItemContent[0]);
useContent.mockReset().mockReturnValueOnce(mockLastItemContent[0]);

const { unmount } = render(
<Results
Expand All @@ -191,7 +189,7 @@ describe("seeMore", () => {

describe("focus", () => {
it("should not be set on the very first item on the page", () => {
useContent.mockReset().mockReturnValueOnce({}).mockReturnValueOnce(mockContent[0]);
useContent.mockReset().mockReturnValueOnce(mockContent[0]);

const { unmount } = render(
<Results
Expand All @@ -212,9 +210,7 @@ describe("focus", () => {
it("should be set on the first new item added", () => {
useContent
.mockReset()
.mockReturnValueOnce({})
.mockReturnValueOnce(mockContent[0])
.mockReturnValueOnce({})
.mockReturnValueOnce(mockContent[1]);

const { unmount } = render(
Expand All @@ -237,9 +233,7 @@ describe("focus", () => {
it("should not set focus if there is no link", () => {
useContent
.mockReset()
.mockReturnValueOnce({})
.mockReturnValueOnce(mockContent[0])
.mockReturnValueOnce({})
.mockReturnValueOnce(mockContent[1]);

const { unmount } = render(
Expand All @@ -264,9 +258,7 @@ describe("story-feed-query service", () => {
it("should call useContent with appropriate query parameters", () => {
useContent
.mockReset()
.mockReturnValueOnce({})
.mockReturnValueOnce(mockContent[0])
.mockReturnValueOnce({})
.mockReturnValueOnce(mockContent[1]);

const { unmount } = render(
Expand Down Expand Up @@ -313,9 +305,7 @@ describe("content-api-collections service", () => {
it("should call useContent with appropriate query parameters", () => {
useContent
.mockReset()
.mockReturnValueOnce({})
.mockReturnValueOnce(mockContent[0])
.mockReturnValueOnce({})
.mockReturnValueOnce(mockContent[1]);

const { unmount } = render(
Expand Down Expand Up @@ -364,9 +354,7 @@ describe("story-feed-author service", () => {
it("should call useContent with appropriate query parameters", () => {
useContent
.mockReset()
.mockReturnValueOnce({})
.mockReturnValueOnce(mockContent[0])
.mockReturnValueOnce({})
.mockReturnValueOnce(mockContent[1]);

const { unmount } = render(
Expand Down Expand Up @@ -413,9 +401,7 @@ describe("story-feed-sections service", () => {
it("should call useContent with appropriate query parameters", () => {
useContent
.mockReset()
.mockReturnValueOnce({})
.mockReturnValueOnce(mockContent[0])
.mockReturnValueOnce({})
.mockReturnValueOnce(mockContent[1]);

const { unmount } = render(
Expand Down Expand Up @@ -506,9 +492,7 @@ describe("unknown service", () => {
it("should call useContent with appropriate query parameters", () => {
useContent
.mockReset()
.mockReturnValueOnce({})
.mockReturnValueOnce(mockContent[0])
.mockReturnValueOnce({})
.mockReturnValueOnce(mockContent[1]);

const { unmount } = render(
Expand Down Expand Up @@ -548,10 +532,8 @@ describe("lazy flags", () => {
it("should return nothing if isServerSideLazy is true", () => {
useContent
.mockReset()
.mockReturnValueOnce({})
.mockReturnValueOnce(mockContent[0])
.mockReturnValueOnce({})
.mockReturnValueOnce(mockContent[1]);
.mockReturnValueOnce(null)
.mockReturnValueOnce(null);

const { unmount } = render(
<Results
Expand Down Expand Up @@ -580,9 +562,7 @@ describe("fallback image", () => {
it("should return even if the fallback image is not a /resource/ path", () => {
useContent
.mockReset()
.mockReturnValueOnce({})
.mockReturnValueOnce(mockContent[0])
.mockReturnValueOnce({})
.mockReturnValueOnce(mockContent[1]);

const { unmount } = render(
Expand Down

0 comments on commit 8792858

Please sign in to comment.