Skip to content

Commit

Permalink
feat(currentTeamProjectValidation): updated function name for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
jarvisraymond-uchicago committed Nov 21, 2023
1 parent 2c15c18 commit 5a97796
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const IsCurrentTeamProjectValid = (data) => {
if (!data || !data.teams) {
if (!data.teams) {
return false;
}
let currentTeamProjectIsValid = false;
const currentTeamProject = localStorage.getItem('teamProject');
console.log(`localStorage.getItem('teamProject')`, currentTeamProject);
console.log("localStorage.getItem('teamProject')", currentTeamProject);
data.teams.forEach((team) => {
if (team.teamName === currentTeamProject) {
currentTeamProjectIsValid = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,12 @@ const sampleData = {
};

describe('IsCurrentTeamProjectValid', () => {
it(`should return false if data doesn't contain teams`, () => {
it("should return false if data doesn't contain teams", () => {
// Call the function with sample data
const result = IsCurrentTeamProjectValid({ notTeams: [] });
// Expect the result to be false
expect(result).toBe(false);
});
it(`should return false if data is falsy`, () => {
// Call the function with sample data
const result = IsCurrentTeamProjectValid(null);
// Expect the result to be false
expect(result).toBe(false);
});

it('should return false if current team project is not valid', () => {
// Mock localStorage.getItem to return an invalid team project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ const TeamProjectHeader = ({ isEditable }) => {
const [isModalOpen, setIsModalOpen] = useState(false);
const [bannerText, setBannerText] = useState('- -');
const [selectedTeamProject, setSelectedTeamProject] = useState(
localStorage.getItem('teamProject'),
localStorage.getItem('teamProject')
);
const showModal = () => {
setIsModalOpen(true);
};
const history = useHistory();

const rerouteToAppSelection = () => {
const rerouteToAppSelectionIfNeeded = () => {
if (!isEditable && !localStorage.getItem('teamProject')) {
// non-editable view should redirect to app selection if user doesn't have a storedTeamProject
history.push('/analysis');
Expand All @@ -31,15 +31,15 @@ const TeamProjectHeader = ({ isEditable }) => {
const { data, status } = useQuery(
'teamprojects',
fetchArboristTeamProjectRoles,
queryConfig,
queryConfig
);

let currentTeamProjectIsValid = false;
if (data) {
currentTeamProjectIsValid = IsCurrentTeamProjectValid(data);
if (!currentTeamProjectIsValid) {
localStorage.removeItem('teamProject');
rerouteToAppSelection();
rerouteToAppSelectionIfNeeded();
}
}

Expand All @@ -51,7 +51,7 @@ const TeamProjectHeader = ({ isEditable }) => {
setSelectedTeamProject(null);
showModal();
}
rerouteToAppSelection();
rerouteToAppSelectionIfNeeded();
}, [history, isEditable, currentTeamProjectIsValid, data]);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,5 @@ test('renders TeamProjectHeader with team project name from localStorage', () =>
</QueryClientProvider>
);

// You can add more specific assertions based on your component's structure
expect(screen.getByText(new RegExp(testName, 'i'))).toBeInTheDocument();
});

0 comments on commit 5a97796

Please sign in to comment.