Skip to content

Commit

Permalink
Merge branch 'development' into anne_wbs_task_spacing_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Annezhang673 authored Nov 8, 2024
2 parents 7c50471 + 04a835a commit 660fae0
Show file tree
Hide file tree
Showing 133 changed files with 13,477 additions and 4,828 deletions.
Binary file added ..env.un~
Binary file not shown.
Empty file added .env~
Empty file.
2 changes: 0 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ src/components/AutoReload/**
src/components/Badge/**
src/components/common/**
src/components/Header/**
src/components/MonthlyEffort/**
src/components/ProfileLinks/**
src/components/Projects/**
src/components/Reports/**
src/components/SetupProfile/**
Expand Down
3 changes: 0 additions & 3 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ src/components/AutoReload/**
src/components/Header/**
src/components/Inventory/**
src/components/Memberships/**
src/components/MonthlyEffort/**
src/components/NewProfileLink/**
src/components/ProfileLinks/**
src/components/Projects/**
src/components/Reports/**
src/components/SetupProfile/**
Expand Down
23 changes: 23 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
// other settings
// formatting using eslint
// let editor format using prettier for all other files
"editor.formatOnSave": true,
// disable editor formatting, so eslint can handle it
"[javascript]": {
"editor.formatOnSave": true
},
//"eslint.enable": true,
// available through eslint plugin in vscode
"eslint.alwaysShowStatus": true,
"editor.tabSize": 2,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
"files.exclude": {
"**/.classpath": true,
"**/.project": true,
"**/.settings": true,
"**/.factorypath": true
}
}
5 changes: 4 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ module.exports = {
// An array of file extensions your modules use
moduleFileExtensions: ['js', 'json', 'jsx'],

// Bundle mapper for d3 import
// Bundle mapper for d3 import and other custom mocks
moduleNameMapper: {
d3: '<rootDir>/node_modules/d3/dist/d3.min.js',
'react-leaflet': '<rootDir>/src/_tests_/__mocks__/react-leaflet.js',
'marker-cluster-group': '<rootDir>/src/_tests_/__mocks__/react-leaflet-cluster.js',
'\\.(css|less|scss|sass)$': 'identity-obj-proxy', // <-- Added to mock CSS/SCSS files
},

// The paths to modules that run some code to configure or set up the testing environment before each test
Expand All @@ -38,6 +39,8 @@ module.exports = {

// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
transformIgnorePatterns: ['/node_modules/(?!d3|d3-array|internmap|delaunator|robust-predicates)'],

// Include snapshot serializers
snapshotSerializers: ['enzyme-to-json/serializer'],

// Indicates whether each individual test should be reported during the run
Expand Down
9,818 changes: 8,356 additions & 1,462 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"@fortawesome/free-regular-svg-icons": "^5.12.1",
"@fortawesome/free-solid-svg-icons": "^5.15.4",
"@fortawesome/react-fontawesome": "^0.1.19",
"@reduxjs/toolkit": "^2.2.7",
"@sentry/browser": "^4.6.6",
"@tinymce/tinymce-react": "^3.14.0",
"axios": "^0.21.2",
Expand All @@ -26,7 +27,6 @@
"history": "^4.10.1",
"html-react-parser": "^1.4.14",
"html-to-pdfmake": "^2.0.6",
"jest": "26.6.0",
"joi": "^14.0.6",
"jwt-decode": "^2.2.0",
"leaflet": "^1.9.4",
Expand Down Expand Up @@ -54,7 +54,7 @@
"react-redux": "^7.2.0",
"react-router-dom": "^5.2.0",
"react-router-hash-link": "^2.3.1",
"react-scripts": "^4.0.1",
"react-scripts": "^4.0.3",
"react-select": "^5.7.2",
"react-sticky": "^6.0.3",
"react-table": "^6.10.0",
Expand Down Expand Up @@ -96,8 +96,8 @@
"devDependencies": {
"@babel/helper-validator-identifier": "^7.12.11",
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"@testing-library/jest-dom": "^5.11.3",
"@testing-library/react": "^10.4.3",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^10.4.9",
"@testing-library/user-event": "^12.0.14",
"babel-eslint": "^10.1.0",
"cross-env": "^5.2.1",
Expand All @@ -112,14 +112,16 @@
"eslint-plugin-react": "^7.29.4",
"eslint-plugin-react-hooks": "^4.3.0",
"eslint-plugin-testing-library": "^3.6.0",
"husky": "^8.0.0",
"identity-obj-proxy": "^3.0.0",
"jest": "^26.6.0",
"jest-environment-jsdom-sixteen": "^1.0.3",
"msw": "^0.19.5",
"node-fetch": "^3.1.1",
"node-sass": "^8.0.0",
"prettier": "^1.19.1",
"redux-mock-store": "^1.5.4",
"husky": "^8.0.0",
"sinon": "^7.3.2",
"surge": "^0.21.6",
"jest-environment-jsdom-sixteen": "^1.0.3",
"node-fetch": "^3.1.1"
"surge": "^0.21.6"
}
}
75 changes: 75 additions & 0 deletions src/__tests__/CountdownTimer.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import React from 'react';
import moment from 'moment';
import { render, screen, waitFor } from '@testing-library/react';
import { unmountComponentAtNode } from "react-dom";
import '@testing-library/jest-dom/extend-expect';

import CountdownTimer from 'components/WeeklySummary/CountdownTimer';

let container = null;
beforeEach(() => {
// setup a DOM element as a render target
container = document.createElement("div");
document.body.appendChild(container);
});

afterEach(() => {
// cleanup on exiting
unmountComponentAtNode(container);
container.remove();
container = null;
});

describe('Time Countdown Timer Test', () => {
it('displays "Time\'s Up" message when timer finished 1 second ago', async () => {
// Set the time to 1 second ago.
const tickTest = moment().subtract(1, 'seconds');
render(<CountdownTimer date={tickTest} />, container);

await waitFor(() => screen.getByText("Time's up!"));

expect(screen.getByText("Time's up!")).toBeInTheDocument();
});
});

describe('Time Countdown Timer Test', () => {
it('displays "Time\'s Up" message when timer finished at the same time', async () => {
// Set the time to the current time.
const tickTest = moment().subtract(0, 'seconds');
render(<CountdownTimer date={tickTest} />, container);

await waitFor(() => screen.getByText("Time's up!"));
expect(screen.getByText("Time's up!")).toBeInTheDocument();
});
});

describe('Time Countdown Timer Test', () => {
it('displays "Time\'s Up" message when timer finished 999 seconds ago', async () => {
// Set the time to 999 seconds ago.
const tickTest = moment().subtract(999, 'seconds');
render(<CountdownTimer date={tickTest} />, container);

await waitFor(() => screen.getByText("Time's up!"));
expect(screen.getByText("Time's up!")).toBeInTheDocument();
});
});

describe('Time Countdown Timer Test', () => {
it('displays "Sec" when timer is not finished', () => {
// Set the time to 999 seconds later.
const tickTest = moment().subtract(-999, 'seconds');
render(<CountdownTimer date={tickTest} />, container);

expect(screen.getByText("Sec")).toBeInTheDocument();
});
});

describe('Time Countdown Timer Test', () => {
it('displays "Time\'s Up" message when timer will be finished 1 second later', () => {
// Set the time to the 1 second later.
const tickTest = moment().subtract(-1, 'seconds');
render(<CountdownTimer date={tickTest} />, container);

expect(screen.getByText("Sec")).toBeInTheDocument();
});
});
72 changes: 29 additions & 43 deletions src/actions/badgeManagement.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import axios from 'axios';
import moment from 'moment';
import { formatDate } from 'utils/formatDate';
import {
GET_ALL_BADGE_DATA,
ADD_SELECT_BADGE,
Expand All @@ -12,10 +14,9 @@ import {
GET_USER_ID,
GET_BADGE_COUNT,
RESET_BADGE_COUNT,
SET_ACTIVE_TAB,
} from '../constants/badge';
import { ENDPOINTS } from '../utils/URL';
import moment from 'moment';
import { formatDate } from 'utils/formatDate';

const getAllBadges = allBadges => ({
type: GET_ALL_BADGE_DATA,
Expand Down Expand Up @@ -62,7 +63,7 @@ export const resetBadgeCount = userId => async dispatch => {
});
}
} catch (error) {
console.error("Failed to reset badge count", error);
console.error('Failed to reset badge count', error);
}
};

Expand Down Expand Up @@ -110,6 +111,10 @@ export const getMessage = (message, color) => ({
message,
color,
});
export const setActiveTab = tab => ({
type: SET_ACTIVE_TAB,
payload: tab,
});

export const gotCloseAlert = () => ({ type: CLOSE_ALERT });

Expand Down Expand Up @@ -255,51 +260,33 @@ export const assignBadgesByUserID = (userId, selectedBadges) => {

// Return updated badgeCollection
export const returnUpdatedBadgesCollection = (badgeCollection, selectedBadgesId) => {
let newBadgeCollection = Array.from(badgeCollection);

// object to track updated or newly added badges to prevent duplicates
let updatedOrAddedBadges = {};
const personalMaxBadge = '666b78265bca0bcb94080605'; // backend id for Personal Max badge
const badgeMap = new Map(badgeCollection?.map(badge => [badge.badge, badge]));

const currentTs = Date.now();
const currentDate = formatDate();
selectedBadgesId.forEach(originalBadgeId => {
let badgeId = originalBadgeId;
// Remove "assign-badge-" from badgeId
if (badgeId.includes('assign-badge-')) badgeId = badgeId.replace('assign-badge-', '');

if (!updatedOrAddedBadges[badgeId]) {
let included = false;
let currentTs = Date.now();
let currentDate = formatDate();

newBadgeCollection.forEach(badgeObj => {
if (badgeId === badgeObj.badge) {
if (!included) {
// Only update the first instance
// Increment count only for the first instance found
badgeObj.count = badgeObj.count ? badgeObj.count + 1 : 1;
badgeObj.lastModified = currentTs;
badgeObj.earnedDate.push(currentDate);
included = true;
}
// Note this badge ID as updated so it's not added again
updatedOrAddedBadges[badgeId] = true;
}
});

// Add the new badge record to badgeCollection if not included already
if (!included) {
newBadgeCollection.push({
badge: badgeId,
count: 1,
lastModified: currentTs,
earnedDate: [currentDate],
});
// Note this badge ID as added
updatedOrAddedBadges[badgeId] = true;
const badgeId = originalBadgeId.replace('assign-badge-', '');
if (badgeMap.has(badgeId)) {
// Update the existing badge record
if (badgeId != personalMaxBadge) {
const badge = badgeMap.get(badgeId);
badge.count = (badge.count || 0) + 1;
badge.lastModified = currentTs;
badge.earnedDate.push(currentDate);
}
} else {
// Add the new badge record
badgeMap.set(badgeId, {
badge: badgeId,
count: 1,
lastModified: currentTs,
earnedDate: [currentDate],
});
}
});

return newBadgeCollection;
return Array.from(badgeMap.values());
};

// Make API call to update badgeCollection
Expand All @@ -326,7 +313,6 @@ export const sendUpdatedBadgeCollectionReq = async (
dispatch(closeAlert());
}, 6000);
}
return;
};

export const changeBadgesByUserID = (userId, badgeCollection) => {
Expand Down
59 changes: 59 additions & 0 deletions src/actions/userManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import {
RECEIVE_ALL_USER_PROFILES,
USER_PROFILE_UPDATE,
USER_PROFILE_DELETE,
FETCH_USER_PROFILE_BASIC_INFO,
RECEIVE_USER_PROFILE_BASIC_INFO,
FETCH_USER_PROFILE_BASIC_INFO_ERROR,
ENABLE_USER_PROFILE_EDIT,
DISABLE_USER_PROFILE_EDIT,
CHANGE_USER_PROFILE_PAGE,
Expand Down Expand Up @@ -216,6 +219,62 @@ export const updateUserFinalDayStatusIsSet = (user, status, finalDayDate, isSet)
};
};

/**
* fetching all user profiles basic info
*/
export const getUserProfileBasicInfo = () => {
// API request to fetch basic user profile information
const userProfileBasicInfoPromise = axios.get(ENDPOINTS.USER_PROFILE_BASIC_INFO);

return async dispatch => {
// Dispatch action indicating the start of the fetch process
await dispatch(userProfilesBasicInfoFetchStartAction());

return userProfileBasicInfoPromise
.then(res => {
// Dispatch action with the fetched basic profile data
dispatch(userProfilesBasicInfoFetchCompleteACtion(res.data));
return res.data; // Return the fetched data
})
.catch(err => {
// Dispatch error action if the fetch fails
dispatch(userProfilesBasicInfoFetchErrorAction());
});
};
};


/**
* Set a flag that starts fetching user profile basic info
*/
export const userProfilesBasicInfoFetchStartAction = () => {
return {
type: FETCH_USER_PROFILE_BASIC_INFO,
};
};

/**
* Fetching user profile basic info
* @param payload : projects []
*/
export const userProfilesBasicInfoFetchCompleteACtion = payload => {
return {
type: RECEIVE_USER_PROFILE_BASIC_INFO,
payload,
};
};

/**
* Error when fetching the user profils basic info
* @param payload : error status code
*/
export const userProfilesBasicInfoFetchErrorAction = payload => {
return {
type: FETCH_USER_PROFILE_BASIC_INFO_ERROR,
payload,
};
};

export const enableEditUserInfo=(value)=>(dispatch,getState)=>{
dispatch({type:ENABLE_USER_PROFILE_EDIT,payload:value});
}
Expand Down
Loading

0 comments on commit 660fae0

Please sign in to comment.