-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 13683-update-subform-tablecolumns-config-to-…
…comply-with-ux-design
- Loading branch information
Showing
11 changed files
with
236 additions
and
18 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
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
10 changes: 10 additions & 0 deletions
10
...etForSubform/EditLayoutSet/CreateNewSubformLayoutSet/CreateNewSubformLayoutSet.module.css
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,10 @@ | ||
.savelayoutSetButton { | ||
display: flex; | ||
align-self: flex-start; | ||
border: 2px solid var(--success-color); | ||
color: var(--success-color); | ||
} | ||
|
||
.headerIcon { | ||
font-size: large; | ||
} |
67 changes: 67 additions & 0 deletions
67
...tSetForSubform/EditLayoutSet/CreateNewSubformLayoutSet/CreateNewSubformLayoutSet.test.tsx
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,67 @@ | ||
import React from 'react'; | ||
import { renderWithProviders } from '../../../../../../testing/mocks'; | ||
import { CreateNewSubformLayoutSet } from './CreateNewSubformLayoutSet'; | ||
import type { ComponentType } from 'app-shared/types/ComponentType'; | ||
import { textMock } from '@studio/testing/mocks/i18nMock'; | ||
import { screen, waitFor } from '@testing-library/react'; | ||
import { createQueryClientMock } from 'app-shared/mocks/queryClientMock'; | ||
import { app, org } from '@studio/testing/testids'; | ||
import { QueryKey } from 'app-shared/types/QueryKey'; | ||
import { layoutSets } from 'app-shared/mocks/mocks'; | ||
import type { LayoutSets } from 'app-shared/types/api/LayoutSetsResponse'; | ||
import userEvent from '@testing-library/user-event'; | ||
import type { FormComponent } from '../../../../../../types/FormComponent'; | ||
import { AppContext } from '../../../../../../AppContext'; | ||
import { appContextMock } from '../../../../../../testing/appContextMock'; | ||
|
||
const onSubFormCreatedMock = jest.fn(); | ||
|
||
describe('CreateNewSubformLayoutSet ', () => { | ||
afterEach(jest.clearAllMocks); | ||
|
||
it('displays the card with label and input field', () => { | ||
renderCreateNewSubformLayoutSet(); | ||
const card = screen.getByRole('textbox', { | ||
name: textMock('ux_editor.component_properties.subform.created_layout_set_name'), | ||
}); | ||
|
||
expect(card).toBeInTheDocument(); | ||
}); | ||
|
||
it('displays the input field', () => { | ||
renderCreateNewSubformLayoutSet(); | ||
const input = screen.getByRole('textbox'); | ||
expect(input).toBeInTheDocument(); | ||
}); | ||
|
||
it('displays the save button', () => { | ||
renderCreateNewSubformLayoutSet(); | ||
const saveButton = screen.getByRole('button', { name: textMock('general.close') }); | ||
expect(saveButton).toBeInTheDocument(); | ||
}); | ||
|
||
it('calls onSubFormCreated when save button is clicked', async () => { | ||
const user = userEvent.setup(); | ||
renderCreateNewSubformLayoutSet(); | ||
const input = screen.getByRole('textbox'); | ||
await user.type(input, 'NewSubForm'); | ||
const saveButton = screen.getByRole('button', { name: textMock('general.close') }); | ||
await user.click(saveButton); | ||
await waitFor(() => expect(onSubFormCreatedMock).toHaveBeenCalledTimes(1)); | ||
expect(onSubFormCreatedMock).toHaveBeenCalledWith('NewSubForm'); | ||
}); | ||
}); | ||
|
||
const renderCreateNewSubformLayoutSet = ( | ||
layoutSetsMock: LayoutSets = layoutSets, | ||
componentProps: Partial<FormComponent<ComponentType.Subform>> = {}, | ||
) => { | ||
const queryClient = createQueryClientMock(); | ||
queryClient.setQueryData([QueryKey.LayoutSets, org, app], layoutSetsMock); | ||
return renderWithProviders( | ||
<AppContext.Provider value={{ ...appContextMock }}> | ||
<CreateNewSubformLayoutSet onSubFormCreated={onSubFormCreatedMock} {...componentProps} /> | ||
</AppContext.Provider>, | ||
{ queryClient }, | ||
); | ||
}; |
61 changes: 61 additions & 0 deletions
61
...LayoutSetForSubform/EditLayoutSet/CreateNewSubformLayoutSet/CreateNewSubformLayoutSet.tsx
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,61 @@ | ||
import React, { useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { StudioButton, StudioCard, StudioTextfield } from '@studio/components'; | ||
import { ClipboardIcon, CheckmarkIcon } from '@studio/icons'; | ||
import { useAddLayoutSetMutation } from 'app-development/hooks/mutations/useAddLayoutSetMutation'; | ||
import { useStudioEnvironmentParams } from 'app-shared/hooks/useStudioEnvironmentParams'; | ||
import classes from './CreateNewSubformLayoutSet.module.css'; | ||
|
||
type CreateNewSubformLayoutSetProps = { | ||
onSubFormCreated: (layoutSetName: string) => void; | ||
}; | ||
|
||
export const CreateNewSubformLayoutSet = ({ | ||
onSubFormCreated, | ||
}: CreateNewSubformLayoutSetProps): React.ReactElement => { | ||
const { t } = useTranslation(); | ||
const [newSubForm, setNewSubForm] = useState(''); | ||
const { org, app } = useStudioEnvironmentParams(); | ||
const { mutate: addLayoutSet } = useAddLayoutSetMutation(org, app); | ||
|
||
const createNewSubform = () => { | ||
if (!newSubForm) return; | ||
addLayoutSet({ | ||
layoutSetIdToUpdate: newSubForm, | ||
layoutSetConfig: { | ||
id: newSubForm, | ||
type: 'subform', | ||
}, | ||
}); | ||
onSubFormCreated(newSubForm); | ||
setNewSubForm(''); | ||
}; | ||
|
||
function handleChange(e: React.ChangeEvent<HTMLInputElement>) { | ||
setNewSubForm(e.target.value); | ||
} | ||
|
||
return ( | ||
<StudioCard> | ||
<StudioCard.Content> | ||
<StudioCard.Header> | ||
<ClipboardIcon className={classes.headerIcon} /> | ||
</StudioCard.Header> | ||
<StudioTextfield | ||
label={t('ux_editor.component_properties.subform.created_layout_set_name')} | ||
value={newSubForm} | ||
size='sm' | ||
onChange={handleChange} | ||
/> | ||
<StudioButton | ||
className={classes.savelayoutSetButton} | ||
icon={<CheckmarkIcon />} | ||
onClick={createNewSubform} | ||
title={t('general.close')} | ||
variant='tertiary' | ||
color='success' | ||
/> | ||
</StudioCard.Content> | ||
</StudioCard> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
...PropertiesHeader/EditLayoutSetForSubform/EditLayoutSet/CreateNewSubformLayoutSet/index.ts
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 @@ | ||
export { CreateNewSubformLayoutSet } from './CreateNewSubformLayoutSet'; |
4 changes: 4 additions & 0 deletions
4
...roperties/PropertiesHeader/EditLayoutSetForSubform/EditLayoutSet/EditLayoutSet.module.css
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,4 @@ | ||
.button { | ||
padding-left: 0; | ||
border-radius: var(--fds-sizing-1); | ||
} |
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