From fc7f757a0cbe650963b7711bb8baf4a800bc2034 Mon Sep 17 00:00:00 2001 From: Jarvis Raymond Date: Wed, 25 Oct 2023 11:55:15 -0500 Subject: [PATCH] feat(teamProjectsHeader): Added working storybook --- .../TeamProjectHeader.stories.jsx | 5 +- .../TeamProjectModal/TeamProjectModal.jsx | 123 ++++++++++-------- .../TeamProjectModal.stories.jsx | 92 +++++++++++++ .../TeamProjectModal.test.jsx | 6 +- 4 files changed, 166 insertions(+), 60 deletions(-) create mode 100644 src/Analysis/SharedUtils/TeamProject/TeamProjectModal/TeamProjectModal.stories.jsx diff --git a/src/Analysis/SharedUtils/TeamProject/TeamProjectHeader/TeamProjectHeader.stories.jsx b/src/Analysis/SharedUtils/TeamProject/TeamProjectHeader/TeamProjectHeader.stories.jsx index 3ef9c4b6eb..5af7f92c28 100644 --- a/src/Analysis/SharedUtils/TeamProject/TeamProjectHeader/TeamProjectHeader.stories.jsx +++ b/src/Analysis/SharedUtils/TeamProject/TeamProjectHeader/TeamProjectHeader.stories.jsx @@ -1,5 +1,6 @@ import React from 'react'; import TeamProjectHeader from './TeamProjectHeader'; +import { QueryClient, QueryClientProvider } from 'react-query'; export default { title: 'TESTS1/SharedUtils/TeamProjectHeader', @@ -8,7 +9,9 @@ export default { const Template = (args) => (
- + + + ,
); diff --git a/src/Analysis/SharedUtils/TeamProject/TeamProjectModal/TeamProjectModal.jsx b/src/Analysis/SharedUtils/TeamProject/TeamProjectModal/TeamProjectModal.jsx index b7d002a4e3..7da61b913c 100644 --- a/src/Analysis/SharedUtils/TeamProject/TeamProjectModal/TeamProjectModal.jsx +++ b/src/Analysis/SharedUtils/TeamProject/TeamProjectModal/TeamProjectModal.jsx @@ -3,6 +3,7 @@ import PropTypes from 'prop-types'; import { Button, Modal, Spin, Select } from 'antd'; import { useQuery } from 'react-query'; import queryConfig from '../../QueryConfig'; +import LoadingErrorMessage from '../../LoadingErrorMessage/LoadingErrorMessage'; import fetchArboristTeamProjectRoles from '../../teamProjectApi'; import './TeamProjectModal.css'; @@ -25,75 +26,85 @@ const TeamProjectModal = ({ isModalOpen, setIsModalOpen, setBannerText }) => { let modalContent = ( -
- Retrieving the list of team projects. -
- Please wait... -
+ +
+ Retrieving the list of team projects. +
+ Please wait... +
+
); if (status === 'error') { modalContent = ( - + + + ); } if (data) { - // check to make sure stored value is within returned team names - const isStoredTeamNameValid =()=> { - let valid = false - if(selectedTeamProject) { - data.teams.forEach(team => {if(team.teamName === selectedTeamProject) valid = true}); - } - return valid; - } - + console.log("data",data) modalContent = ( -
- Please select your team. -
- setSelectedTeamProject(e.value)} + placeholder='-select one of the team projects below-' + fieldNames={{ label: 'teamName', value: 'teamName' }} + options={data.teams} + dropdownStyle={{ width: '100%' }} + /> +
); } - return ( - - setIsModalOpen(false)} - closable={localStorage.getItem('teamProject')} - maskClosable={localStorage.getItem('teamProject')} - keyboard={localStorage.getItem('teamProject')} - footer={ - localStorage.getItem('teamProject') && [ - , - ] - } - > - {modalContent} - - ); + return <>{modalContent}; }; TeamProjectModal.propTypes = { diff --git a/src/Analysis/SharedUtils/TeamProject/TeamProjectModal/TeamProjectModal.stories.jsx b/src/Analysis/SharedUtils/TeamProject/TeamProjectModal/TeamProjectModal.stories.jsx new file mode 100644 index 0000000000..625676c4b2 --- /dev/null +++ b/src/Analysis/SharedUtils/TeamProject/TeamProjectModal/TeamProjectModal.stories.jsx @@ -0,0 +1,92 @@ +import React from 'react'; +import TeamProjectModal from './TeamProjectModal'; +import { QueryClient, QueryClientProvider } from 'react-query'; +import { rest } from 'msw'; + +export default { + title: 'TESTS1/SharedUtils/TeamProjectModal', + component: TeamProjectModal, +}; + +const mockedQueryClient = new QueryClient({ + defaultOptions: { + queries: { retry: false }, + }, +}); + +const Template = (args) => ( +
+ + + + , +
+); + +export const MockedFailureNoUserAccess = Template.bind({}); +MockedFailureNoUserAccess.args = { + isModalOpen: true, + setIsModalOpen: () => false, + setBannerText: () => 'new banner text ' + Math.random, +}; + +export const MockedSuccess = Template.bind({}); +MockedSuccess.args = { + isModalOpen: true, + setIsModalOpen: () => false, + setBannerText: () => 'new banner text ' + Math.random, +}; +/* +MockedSuccess.parameters = { + msw: { + handlers: [ + rest.get(`http://localhost/authz/mapping`, (req, res, ctx) => { + const { argowrapperpath } = req.params; + return res( + ctx.delay(3000), + ctx.json({ + "teams": [ + { "teamName": '/gwas_projects/project1' }, + { "teamName": '/gwas_projects/project2' }, + ], + }) + ); + }), + ], + }, +}; +*/ +MockedSuccess.parameters = { + msw: { + handlers: [ + rest.get( + 'http://:arboristapi/authz/mapping', + (req, res, ctx) => { + return res( + ctx.delay(1000), + ctx.json({ + "/gwas_projects/project11": [ + { + "service": "atlas-argo-wrapper-and-cohort-middleware", + "method": "access" + } + ], + "/gwas_projects/project22": [ + { + "service": "atlas-argo-wrapper-and-cohort-middleware", + "method": "access" + } + ], + "/somethingelse": [ + { + "service": "requestor", + "method": "create" + } + ], + }) + ); + } + ), + ], + }, +}; diff --git a/src/Analysis/SharedUtils/TeamProject/TeamProjectModal/TeamProjectModal.test.jsx b/src/Analysis/SharedUtils/TeamProject/TeamProjectModal/TeamProjectModal.test.jsx index 8ae85122ed..6abd962b6c 100644 --- a/src/Analysis/SharedUtils/TeamProject/TeamProjectModal/TeamProjectModal.test.jsx +++ b/src/Analysis/SharedUtils/TeamProject/TeamProjectModal/TeamProjectModal.test.jsx @@ -61,7 +61,7 @@ describe('TeamProjectModal', () => { // Mocking the success state useQuery.mockReturnValueOnce({ - data: { teams: [{ value: 'selectedValue', label: 'Selected Value' }] }, + data: { teams: [{ value: 'test string', label: 'test string' }] }, status: 'success', }); @@ -86,13 +86,13 @@ describe('TeamProjectModal', () => { expect(screen.getByText(/Submit/i)).toBeInTheDocument(); }); - test('sets text based on localstorage state, calls setBannerText and closes modal on submit button click', async () => { + test('sets defaultValue text based on localstorage state, calls setBannerText and closes modal on submit button click', async () => { // Mocking the local storage variable localStorage.setItem('teamProject', 'test string'); // Mocking the success state useQuery.mockReturnValueOnce({ - data: { teams: [{ value: 'selectedValue', label: 'Selected Value' }] }, + data: { teams: [{ value: 'test string', label: 'test string' }] }, status: 'success', });