-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/current team project validation (#1456)
* feat(currentTeamProjectValidation): Initial commit * feat(currentTeamProjectValidation): Moved logic outside of separate component into TeamProjectHeader, should decrease total requests needed * feat(currentTeamProjectValidation): refactored code so when in edit mode with an invalid teamProject application does not display the expired name * feat(currentTeamProjectValidation): began refactoring failed test * feat(currentTeamProjectValidation): Updated TeamProjectModel.test.jsx to pass all unit tests * feat(dataDownloadListActions): Removed dead code: InvalidTeamProjectMessage * feat(dataDownloadListActions): fixed lint issues * feat(currentTeamProjectValidation): updated unit tests to pass * feat(currentTeamProjectValidation): Updated story book stories * feat(currentTeamProjectValidation): removed duplicate function call * feat(currentTeamProjectValidation): Wrote unit test for IsCurrentTeamProjectValid * feat(currentTeamProjectValidation): updated function name for clarity * feat(currentTeamProjectValidation): removed console log and linted code * feat(currentTeamProjectValidation): Formatted code for clarity * feat(currentTeamProjectValidation): ran linter * feat(currentTeamProjectValidation): refactored IsCurrentTeamProjectValid.test.js to use existing test data * feat(currentTeamProjectValidation): removed unneeded localStorage set call * feat(currentTeamProjectValidation): ran linter * feat(currentTeamProjectValidation): cleaned up code for clarity
- Loading branch information
1 parent
d770619
commit cdd74d2
Showing
10 changed files
with
254 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/Analysis/SharedUtils/TeamProject/TeamProjectHeader/IsCurrentTeamProjectValid.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const IsCurrentTeamProjectValid = (data) => { | ||
if (!data.teams) { | ||
return false; | ||
} | ||
let currentTeamProjectIsValid = false; | ||
const currentTeamProject = localStorage.getItem('teamProject'); | ||
data.teams.forEach((team) => { | ||
if (team.teamName === currentTeamProject) { | ||
currentTeamProjectIsValid = true; | ||
} | ||
}); | ||
return currentTeamProjectIsValid; | ||
}; | ||
|
||
export default IsCurrentTeamProjectValid; |
38 changes: 38 additions & 0 deletions
38
src/Analysis/SharedUtils/TeamProject/TeamProjectHeader/IsCurrentTeamProjectValid.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import IsCurrentTeamProjectValid from './IsCurrentTeamProjectValid'; | ||
import TeamProjectTestData from '../TestData/TeamProjectTestData'; | ||
|
||
const localStorageMock = { | ||
getItem: jest.fn(), | ||
setItem: jest.fn(), | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
Object.defineProperty(window, 'localStorage', { | ||
value: localStorageMock, | ||
writable: true, | ||
}); | ||
}); | ||
|
||
describe('IsCurrentTeamProjectValid', () => { | ||
it('should return false if data doesn\'t contain teams', () => { | ||
const result = IsCurrentTeamProjectValid({ notTeams: [] }); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
it('should return false if current team project is not valid', () => { | ||
localStorageMock.getItem.mockReturnValue('InvalidTeamName'); | ||
const result = IsCurrentTeamProjectValid(TeamProjectTestData.data); | ||
expect(result).toBe(false); | ||
expect(localStorageMock.getItem).toHaveBeenCalledWith('teamProject'); | ||
}); | ||
|
||
it('should return true if current team project is valid', () => { | ||
localStorageMock.getItem.mockReturnValue( | ||
TeamProjectTestData.data.teams[0].teamName, | ||
); | ||
const result = IsCurrentTeamProjectValid(TeamProjectTestData.data); | ||
expect(result).toBe(true); | ||
expect(localStorageMock.getItem).toHaveBeenCalledWith('teamProject'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.