Skip to content

Commit

Permalink
test: covering both cases of sdk url known and unknown
Browse files Browse the repository at this point in the history
  • Loading branch information
EtherWizard33 committed Jan 20, 2025
1 parent bae60d1 commit c9bb996
Showing 1 changed file with 57 additions and 20 deletions.
77 changes: 57 additions & 20 deletions app/components/Views/AccountConnect/AccountConnect.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ jest.mock('../../../core/Engine', () => ({
},
}));

// Mock SDKConnect
jest.mock('../../../core/SDKConnect/SDKConnect', () => ({
getInstance: () => ({
getConnection: () => undefined,
}),
}));

// Mock the isUUID function
jest.mock('../../../core/SDKConnect/utils/isUUID', () => ({
isUUID: () => false,
}));

const mockInitialState: DeepPartial<RootState> = {
settings: {},
engine: {
Expand Down Expand Up @@ -86,34 +98,59 @@ describe('AccountConnect', () => {
expect(toJSON()).toMatchSnapshot();
});

describe('Renders PermissionsSummary when expected', () => {
const mockConnectProps = {
route: {
params: {
hostInfo: {
metadata: {
id: 'mockId',
origin: 'mockOrigin',
},
permissions: {
eth_accounts: {
parentCapability: 'eth_accounts',
describe('Renders different screens based on SDK URL status', () => {
it('should render SingleConnect screen when isSdkUrlUnknown is true', () => {
const mockPropsForUnknownUrl = {
route: {
params: {
hostInfo: {
metadata: {
id: 'mockId',
// Using an invalid/unknown format for origin
origin: '',
},
permissions: {
eth_accounts: {
parentCapability: 'eth_accounts',
},
},
},
permissionRequestId: 'test',
},
permissionRequestId: 'test',
},
},
};
};

const { getByTestId } = renderWithProvider(
<AccountConnect {...mockPropsForUnknownUrl} />,
{ state: mockInitialState },
);

expect(getByTestId('connect-account-modal')).toBeDefined();
});

it('should render PermissionsSummary screen when isSdkUrlUnknown is false', () => {
// Mock the isUUID function to return false to ensure isSdkUrlUnknown stays false
jest.mock('../../../core/SDKConnect/utils/isUUID', () => ({
isUUID: () => false,
}));
const mockPropsForKnownUrl = {
route: {
params: {
hostInfo: {
metadata: {
id: 'mockId',
// Using a valid URL format
origin: 'https://example.com',
},
permissions: {
eth_accounts: {
parentCapability: 'eth_accounts',
},
},
},
permissionRequestId: 'test',
},
},
};

const { getByTestId } = renderWithProvider(
<AccountConnect {...mockConnectProps} />,
<AccountConnect {...mockPropsForKnownUrl} />,
{ state: mockInitialState },
);

Expand Down

0 comments on commit c9bb996

Please sign in to comment.