Skip to content

Commit

Permalink
PLT-9600 #comment test:refactor for cleaner code
Browse files Browse the repository at this point in the history
  • Loading branch information
KJES4 committed Mar 27, 2024
1 parent 9d88cfc commit 42fe189
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 46 deletions.
68 changes: 23 additions & 45 deletions src/pages/session/components/AppBar.test.tsx
Expand Up @@ -3,6 +3,8 @@ import { screen } from '@testing-library/react';
import '@testing-library/jest-dom';

import { renderWithProviders } from 'utils/test-utils';
import {walletConnectionInitialState } from '../../../store/slices/walletConnection.slice';
import {profileInitialState} from '../../../store/slices/profile.slice';
import AppBar from './AppBar';

jest.mock('minidenticons', () => ({
Expand All @@ -11,53 +13,29 @@ jest.mock('minidenticons', () => ({

describe('App bar > logged in state', () => {
test('should render wallet address when logged in', async () => {
const preloadedState = {
walletConnection: {
wallet: null,
walletName: null,
walletAddress: 'addr...1234',
stakeAddress: null,
activeWallets: ['lace', 'nami', 'yoroi'],
errorMessage: null,
errorRetry: false,
loading: false,
listeningWalletChanges: false,
resetWalletChanges: false,
},

renderWithProviders(<AppBar />, { preloadedState:
{walletConnection: {
...walletConnectionInitialState,
walletAddress: 'addr...1234',
},
profile: {
...profileInitialState,
profile: {
profile: {
address: 'addr1234',
email: 'email@gmail.com',
fullName: 'name',
companyName: 'company',
contactEmail: 'contactemail@gmail.com',
linkedin: null,
twitter: null,
website: null,
role: null,
dapp: null,
},
errorMessage: null,
loading: false,
success: true,
selectedUser: null,
allUsers: null,
loadingDetails: false,
detailsSuccess: false,
detailsError: null,
userSubscription: null,
loadingSubDetails: false,
subDetailsSuccess: false,
subDetailsError: null,
updateSuccess: false,
loadingHistory: false,
runHistory: [],
impersonate: false,
retainId: null
address: 'addr1234',
email: '',
fullName: '',
companyName: '',
contactEmail: '',
linkedin: null,
twitter: null,
website: null,
role: null,
dapp: null,
}
};

renderWithProviders(<AppBar />, { preloadedState });
}
}
});

const walletAddress = await screen.findByText('addr...1234');

Expand Down
16 changes: 15 additions & 1 deletion src/store/slices/profile.slice.ts
Expand Up @@ -106,7 +106,18 @@ export interface IUpdateProfile {
}

const initialState: ProfileState = {
profile: null,
profile: {
address: '',
email: '',
fullName: '',
companyName: '',
contactEmail: '',
linkedin: null,
twitter: null,
website: null,
role: null,
dapp: null,
},
errorMessage: null,
loading: false,
success: false,
Expand All @@ -126,6 +137,9 @@ const initialState: ProfileState = {
retainId: null
};

// Add this export to your profileSlice file
export { initialState as profileInitialState };

export const fetchProfile = createAsyncThunk('fetchProfile', async (payload, thunkApi) => {
try {
const {impersonate, retainId} = (thunkApi.getState() as RootState).profile;
Expand Down
4 changes: 4 additions & 0 deletions src/store/slices/walletConnection.slice.ts
Expand Up @@ -38,6 +38,10 @@ const initialState: WalletConnectionState = {
resetWalletChanges: false,
};

// Add this export to your walletConnectionSlice file
export { initialState as walletConnectionInitialState };


const CardanoNS = window.cardano;

type StakeAddressHex = string;
Expand Down

0 comments on commit 42fe189

Please sign in to comment.