Skip to content

Commit

Permalink
refactor: Disable templates dropdown when templates array is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
adiabramovitch authored and amirfefer committed Jul 18, 2023
1 parent 70febe7 commit d107e40
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/Components/TemplateSelect/TemplateSelect.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import TemplateSelect from '.';
import userEvent from '@testing-library/user-event';
import { render, screen } from '../../mocks/utils';
import { templates } from '../../mocks/fixtures/templates.fixtures';
import { provisioningUrl } from '../../API/helpers';

describe('TemplateSelect', () => {
test('get all templates options', async () => {
Expand All @@ -23,4 +24,20 @@ describe('TemplateSelect', () => {
const placeholder = await screen.findByText('Select templates');
expect(placeholder).toBeInTheDocument();
});

test('when templates array is empty it should be disabled', async () => {
const { server, rest } = window.msw;
const chosenSource = '1';
server.use(
rest.get(provisioningUrl(`sources/${chosenSource}/launch_templates`), (req, res, ctx) => {
return res(ctx.status(200), ctx.json([]));
})
);
render(<TemplateSelect />, { provider: 'aws', contextValues: { chosenSource: chosenSource } });
const selectDropdown = await screen.findByText('No template found');
await userEvent.click(selectDropdown);

const placeholder = await screen.findByText('No template found');
expect(placeholder).toBeInTheDocument();
});
});
3 changes: 2 additions & 1 deletion src/Components/TemplateSelect/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ const TemplatesSelect = () => {
onToggle={(openState) => setIsOpen(openState)}
selections={chosenTemplateName}
onSelect={onSelect}
placeholderText="Select templates"
placeholderText={templates?.length === 0 ? 'No template found' : 'Select templates'}
aria-label="Select templates"
clearSelectionsAriaLabel="clear template selection"
onClear={onClear}
isDisabled={templates?.length === 0}
>
{templates && selectItemsMapper()}
</Select>
Expand Down

0 comments on commit d107e40

Please sign in to comment.