-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #606 from gadget-inc/alan/app-bridge-ssr-support
Accept location object when initialising GadgetProvider for SSR support
- Loading branch information
Showing
3 changed files
with
182 additions
and
20 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
packages/react-shopify-app-bridge/spec/Provider-windowless.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* @jest-environment node | ||
*/ | ||
import type { AnyClient } from "@gadgetinc/api-client-core"; | ||
import { GadgetConnection } from "@gadgetinc/api-client-core"; | ||
import "@testing-library/jest-dom"; | ||
import type { ReactNode } from "react"; | ||
import React from "react"; | ||
import ReactDOMServer from "react-dom/server"; | ||
import { AppType, Provider } from "../src/Provider.js"; | ||
|
||
describe("GadgetProvider in windowless environment", () => { | ||
let mockApiClient: AnyClient; | ||
const mockApiKey = "some-api-key"; | ||
|
||
beforeEach(() => { | ||
mockApiClient = { | ||
connection: new GadgetConnection({ | ||
endpoint: "https://test-app.gadget.app/endpoint", | ||
}), | ||
} as any; | ||
}); | ||
|
||
const render = (element: ReactNode) => { | ||
return ReactDOMServer.renderToString(element); | ||
}; | ||
|
||
// To make sure the test setup is running in a windowless environment | ||
it("should not include window object", () => { | ||
const result = render(<div>{typeof window}</div>); | ||
|
||
expect(result).toMatchInlineSnapshot(`"<div>undefined</div>"`); | ||
}); | ||
|
||
it("should render a standalone app type without throwing an error", () => { | ||
const result = render( | ||
<Provider | ||
api={mockApiClient} | ||
shopifyApiKey={mockApiKey} | ||
type={AppType.Standalone} | ||
location={{ | ||
pathname: "/", | ||
search: "", | ||
}} | ||
> | ||
<span>hello world</span> | ||
</Provider> | ||
); | ||
|
||
expect(result).toMatchInlineSnapshot(`"<span>hello world</span>"`); | ||
}); | ||
|
||
it("should render an embedded app type without throwing an error", () => { | ||
const result = render( | ||
<Provider | ||
api={mockApiClient} | ||
shopifyApiKey={mockApiKey} | ||
type={AppType.Embedded} | ||
location={{ | ||
pathname: "/", | ||
search: "", | ||
}} | ||
> | ||
<span>hello world</span> | ||
</Provider> | ||
); | ||
|
||
expect(result).toMatchInlineSnapshot(`"<span>hello world</span>"`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* @jest-environment node | ||
*/ | ||
import type { AnyClient } from "@gadgetinc/api-client-core"; | ||
import { GadgetConnection } from "@gadgetinc/api-client-core"; | ||
import "@testing-library/jest-dom"; | ||
import type { ReactNode } from "react"; | ||
import React from "react"; | ||
import ReactDOMServer from "react-dom/server"; | ||
import { Provider } from "../src/GadgetProvider.js"; | ||
|
||
describe("GadgetProvider in windowless environment", () => { | ||
let mockApiClient: AnyClient; | ||
beforeEach(() => { | ||
mockApiClient = { | ||
connection: new GadgetConnection({ | ||
endpoint: "https://whatever.gadget.app/endpoint", | ||
}), | ||
} as any; | ||
}); | ||
|
||
const render = (element: ReactNode) => { | ||
return ReactDOMServer.renderToString(element); | ||
}; | ||
|
||
// To make sure the test setup is running in a windowless environment | ||
it("should not include window object", () => { | ||
const result = render(<div>{typeof window}</div>); | ||
|
||
expect(result).toMatchInlineSnapshot(`"<div>undefined</div>"`); | ||
}); | ||
|
||
it("should render a gadget app type without throwing an error", () => { | ||
const result = render( | ||
<Provider api={mockApiClient}> | ||
<span>hello world</span> | ||
</Provider> | ||
); | ||
|
||
expect(result).toMatchInlineSnapshot(`"<span>hello world</span>"`); | ||
}); | ||
}); |