Skip to content

Commit

Permalink
Add test to ensure iTwins favorites are not refetched on component re…
Browse files Browse the repository at this point in the history
…render
  • Loading branch information
arome committed Dec 9, 2024
1 parent fb2272a commit e1a46c3
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,43 @@ describe("ITwinGrid", () => {
expect(wrapper.getByRole("table")).toBeDefined();
expect(wrapper.getAllByRole("row").length).toEqual(3); // First row is header
});

it("should not refetch iTwins favorites when component rerenders", async () => {
// Arrange
const fetchMore = jest.fn();
jest.spyOn(useITwinData, "useITwinData").mockReturnValue({
iTwins: [],
status: DataStatus.Complete,
fetchMore,
});
// Act
const signal = new AbortController().signal;
const wrapper = render(
<ITwinGrid
accessToken="accessToken"

Check failure

Code scanning / CodeQL

Hard-coded credentials Critical

The hard-coded value "accessToken" is used as
authorization header
.
The hard-coded value "accessToken" is used as
authorization header
.
The hard-coded value "accessToken" is used as
authorization header
.
The hard-coded value "accessToken" is used as
authorization header
.
apiOverrides={{ serverEnvironmentPrefix: "qa" }}
viewMode="cells"
/>
);
wrapper.rerender(
<ITwinGrid
accessToken="accessToken"

Check failure

Code scanning / CodeQL

Hard-coded credentials Critical

The hard-coded value "accessToken" is used as
authorization header
.
The hard-coded value "accessToken" is used as
authorization header
.
The hard-coded value "accessToken" is used as
authorization header
.
The hard-coded value "accessToken" is used as
authorization header
.
apiOverrides={{ serverEnvironmentPrefix: "qa" }}
viewMode="tile"
/>
);

expect(fetch).toHaveBeenCalledTimes(1);
expect(fetch).toHaveBeenCalledWith(
"https://qa-api.bentley.com/itwins/favorites?subClass=Project",
{
headers: {
Accept: "application/vnd.bentley.itwin-platform.v1+json",
"Cache-Control": "",
authorization: "accessToken",

Check failure

Code scanning / CodeQL

Hard-coded credentials Critical

The hard-coded value "accessToken" is used as
authorization header
.
},
signal: signal,
}
);
});
});

0 comments on commit e1a46c3

Please sign in to comment.