Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨(website) add disabled button create ressource form #2175

Merged
merged 1 commit into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ Versioning](https://semver.org/spec/v2.0.0.html).
- Make video dashboard visible by default, and collapsed when using the
Moodle atto plugin
- Update live_session api to use mixin to prevent url crafting
- standalone website:
- put the creating ressource form submit button disabled when the
form is invalid (#2175)

### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,14 @@ describe('<ClassRoomCreateForm />', () => {

const button = screen.getByRole('button', { name: /Add Classroom/i });

expect(button).toBeDisabled();

fireEvent.change(screen.getByRole('textbox', { name: /title/i }), {
target: { value: 'my title' },
});

expect(button).toBeDisabled();

userEvent.click(
await screen.findByRole('button', {
name: 'Choose the playlist.; Selected: some-playlist-id',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ const ClassroomCreateForm = () => {
label={intl.formatMessage(messages.submitLabel)}
onClickCancel={() => history.push(classroomPath)}
isSubmitting={isCreating}
isDisabled={!classroom.title || !classroom.playlist}
/>
</Form>
</Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,16 @@ describe('<LiveCreateForm />', () => {

deferredPlaylists.resolve(playlistsResponse);

const button = screen.getByRole('button', { name: /Add Webinar/i });

expect(button).toBeDisabled();

fireEvent.change(screen.getByRole('textbox', { name: /title/i }), {
target: { value: 'my title' },
});

expect(button).toBeDisabled();

userEvent.click(
await screen.findByRole('button', {
name: 'Choose the playlist.; Selected: some-playlist-id',
Expand All @@ -81,11 +87,7 @@ describe('<LiveCreateForm />', () => {
}),
).toBeInTheDocument();

await waitFor(() =>
expect(
screen.getByRole('button', { name: /Add Webinar/i }),
).not.toBeDisabled(),
);
expect(button).not.toBeDisabled();
});

test('fields are posted correctly', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ const LiveCreateForm = () => {
history.push(livePath);
}}
isSubmitting={isCreating || isUpdatingToLive}
isDisabled={!live.title || !live.playlist}
/>
</Form>
</Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ describe('<PlaylistForm />', () => {
expect(screen.getByLabelText('Organization*required')).toBeInTheDocument();
expect(screen.getByLabelText('Name*required')).toBeInTheDocument();

expect(screen.getByRole('button', { name: 'Save' })).toBeInTheDocument();
const submitButton = screen.getByRole('button', { name: 'Save' });
expect(submitButton).toBeInTheDocument();
expect(submitButton).toBeDisabled();
expect(screen.getByRole('button', { name: 'Edit' })).toBeInTheDocument();
});

it('selects the first oranization if any', async () => {
it('selects the first organization if any', async () => {
fetchMock.mock('/api/organizations/?limit=20&offset=0', {
count: 2,
results: [
Expand Down Expand Up @@ -144,6 +146,8 @@ describe('<PlaylistForm />', () => {
expect(fetchMock.calls()[0][0]).toEqual(
'/api/organizations/?limit=20&offset=0',
);

expect(screen.queryByRole('button', { name: 'Save' })).not.toBeDisabled();
});

it('loads organizations until it find the initial one', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ export const PlaylistForm = ({
: undefined
}
isSubmitting={isSubmitting}
isDisabled={!formValues.name || !formValues.organizationId}
/>
{actions}
</Form>
Expand Down