Skip to content

Commit

Permalink
Fixes AppProxyForm test
Browse files Browse the repository at this point in the history
  • Loading branch information
sle-c committed Jan 8, 2025
1 parent 5ea7d0d commit a47415e
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 77 deletions.
1 change: 1 addition & 0 deletions packages/apps/shopify-app-remix/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"@types/jsonwebtoken": "^9.0.7",
"@types/react": "^18.3.12",
"@types/semver": "^7.5.8",
"cross-fetch": "^4.1.0",
"jest-fetch-mock": "^3.0.3",
"jsonwebtoken": "^9.0.2"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {mount} from '@shopify/react-testing';
import {createRemixStub} from '@remix-run/testing';
import {createMemoryRouter, RouterProvider} from 'react-router-dom';
import 'cross-fetch/polyfill';

import '../../../__tests__/test-helper';

Expand All @@ -19,16 +20,18 @@ describe('<AppProxyForm />', () => {

it('adds a trailing slash if one is missing', () => {
// WHEN
function MyComponent() {
return (
<AppProxyProvider appUrl="http://my-app.example.io">
<AppProxyForm action="/my-action">Hello world</AppProxyForm>
</AppProxyProvider>
);
}

const RemixStub = createRemixStub([{path: '/', Component: MyComponent}]);
const component = mount(<RemixStub />);
const router = createMemoryRouter([
{
path: '/',
element: (
<AppProxyProvider appUrl="http://my-app.example.io">
<AppProxyForm action="/my-action">Hello world</AppProxyForm>
</AppProxyProvider>
),
},
]);

const component = mount(<RouterProvider router={router} />);

// THEN
expect(component).toContainReactComponent('form', {action: '/my-action/'});
Expand All @@ -37,16 +40,18 @@ describe('<AppProxyForm />', () => {

it("doesn't alter the action if it has a trailing slash", () => {
// WHEN
function MyComponent() {
return (
<AppProxyProvider appUrl="http://my-app.example.io">
<AppProxyForm action="/my-action/">Hello world</AppProxyForm>
</AppProxyProvider>
);
}

const RemixStub = createRemixStub([{path: '/', Component: MyComponent}]);
const component = mount(<RemixStub />);
const router = createMemoryRouter([
{
path: '/',
element: (
<AppProxyProvider appUrl="http://my-app.example.io">
<AppProxyForm action="/my-action/">Hello world</AppProxyForm>
</AppProxyProvider>
),
},
]);

const component = mount(<RouterProvider router={router} />);

// THEN
expect(component).toContainReactComponent('form', {action: '/my-action/'});
Expand Down
Loading

0 comments on commit a47415e

Please sign in to comment.