Skip to content

Commit

Permalink
fix dashboard test
Browse files Browse the repository at this point in the history
  • Loading branch information
KamogeloMoeketse committed Jul 9, 2024
1 parent 91d4aae commit c7b05cb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
25 changes: 14 additions & 11 deletions frontend/occupi-mobile4/screens/Dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { widthPercentageToDP as wp, heightPercentageToDP as hp } from 'react-nat
// import { number } from 'zod';

const getRandomNumber = () => {
return Math.floor(Math.random() * 20)+300;
return Math.floor(Math.random() * 20) + 300;
};

const Dashboard = () => {
Expand All @@ -46,12 +46,15 @@ const Dashboard = () => {
useEffect(() => {
const getUserDetails = async () => {
let result = await SecureStore.getItemAsync('UserData');
let jsonresult = JSON.parse(result);
setName(String(jsonresult?.data?.details?.name)); // console.log(JSON.parse(result).data.details.name);
console.log(result);
if (result !== undefined) {
let jsonresult = JSON.parse(result);
setName(String(jsonresult?.data?.details?.name));
}
};
getUserDetails();
}, []);

const checkIn = () => {
if (checkedIn === false) {
setCheckedIn(true);
Expand Down Expand Up @@ -79,7 +82,7 @@ const Dashboard = () => {
async function saveUserEmail(value) {
await SecureStore.setItemAsync('email', value);
}


saveUserEmail('[email protected]');

Expand Down Expand Up @@ -112,7 +115,7 @@ const Dashboard = () => {
<Card flexDirection="row" justifyContent="center" alignItems="center" variant="elevated" mt="$4" style={{ width: wp('43%'), height: hp('12%') }} backgroundColor={cardBackgroundColor} borderRadius={10} >
<Text color={textColor} fontSize={40}>{numbers[0]}</Text>
<View flexDirection="column">
<View flexDirection="row" alignItems="center"><FontAwesome6 name="arrow-trend-up" size={24} color="yellowgreen" /><Text color="yellowgreen"> {numbers[0]/10+5}%</Text></View>
<View flexDirection="row" alignItems="center"><FontAwesome6 name="arrow-trend-up" size={24} color="yellowgreen" /><Text color="yellowgreen"> {numbers[0] / 10 + 5}%</Text></View>
</View>
</Card>
<Card size="lg" variant="elevated" mt="$4" style={{ width: wp('43%'), height: hp('12%') }} backgroundColor={cardBackgroundColor} borderRadius={10} />
Expand All @@ -137,10 +140,10 @@ const Dashboard = () => {
<View>
<Text color={textColor}>Occupancy levels</Text>
<LineChart
withInnerLines={true}
withOuterLines={false}
withVerticalLines={false}
// fromZero={true}
withInnerLines={true}
withOuterLines={false}
withVerticalLines={false}
// fromZero={true}
data={{
labels: ["08:00", "09:00", "10:00", "11:00", "12:00", "13:00"],
datasets: [
Expand All @@ -165,7 +168,7 @@ const Dashboard = () => {
}
]
}}
width={Dimensions.get("window").width -30} // from react-native
width={Dimensions.get("window").width - 30} // from react-native
height={220}
// yAxisLabel=""
// yAxisSuffix="k"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ jest.mock('@gluestack-ui/themed', () => ({
}),
}));

jest.mock('expo-secure-store', () => ({
getItemAsync: jest.fn(),
setItemAsync: jest.fn(),
}));

const renderWithProvider = (component) => {
return render(
<StyledProvider theme={Theme}>
Expand All @@ -26,9 +31,24 @@ describe('Dashboard component', () => {
// expect(tree).toMatchSnapshot();
// });

const mockedData = {
data: {
details: {
name: 'John Doe',
contactNo: '1234567890',
pronouns: 'He/Him',
dob: '1990-01-01T00:00:00Z', // Make sure the format matches your component's expectations
},
email: '[email protected]',
occupiId: 'EMP12345',
},
};

// Mock SecureStore getItemAsync to resolve with the mocked data
require('expo-secure-store').getItemAsync.mockResolvedValueOnce(JSON.stringify(mockedData));

it('renders text correctly', () => {
const { getByText } = renderWithProvider(<Dashboard />);
expect(getByText('Hi Sabrina 👋')).toBeTruthy();
expect(getByText('Welcome to Occupi')).toBeTruthy();
});

Expand Down

0 comments on commit c7b05cb

Please sign in to comment.