Skip to content

Commit 5258afd

Browse files
committed
fix: account for polls with no options in PollHeader text
1 parent 2d299ae commit 5258afd

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/components/Poll/PollHeader.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ export const PollHeader = <
3636

3737
const selectionInstructions = useMemo(() => {
3838
if (is_closed) return t<string>('Vote ended');
39-
if (enforce_unique_vote) return t<string>('Select one');
39+
if (enforce_unique_vote || options.length === 1) return t<string>('Select one');
4040
if (max_votes_allowed)
4141
return t<string>('Select up to {{count}}', {
4242
count: max_votes_allowed > options.length ? options.length : max_votes_allowed,
4343
});
44-
return t<string>('Select one or more');
44+
if (options.length > 1) return t<string>('Select one or more');
45+
return '';
4546
}, [is_closed, enforce_unique_vote, max_votes_allowed, options.length, t]);
4647

4748
if (!name) return;

src/components/Poll/__tests__/PollHeader.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,34 @@ describe('PollHeader', () => {
7272
expect(nameDiv).toHaveTextContent(pollData.name);
7373
expect(subtitleDiv).toHaveTextContent('Select one or more');
7474
});
75+
76+
it('should render Select one header if only one option is available', () => {
77+
const pollData = generatePoll({
78+
max_votes_allowed: undefined,
79+
options: [
80+
{
81+
id: '85610252-7d50-429c-8183-51a7eba46246',
82+
text: 'A',
83+
},
84+
],
85+
});
86+
const { container } = renderComponent({
87+
poll: new Poll({ client: {}, poll: pollData }),
88+
});
89+
const nameDiv = container.querySelector(TITLE_SELECTOR);
90+
const subtitleDiv = container.querySelector(SUBTITLE_SELECTOR);
91+
expect(nameDiv).toHaveTextContent(pollData.name);
92+
expect(subtitleDiv).toHaveTextContent('Select one');
93+
});
94+
95+
it('should render no header text if no options available', () => {
96+
const pollData = generatePoll({ max_votes_allowed: undefined, options: [] });
97+
const { container } = renderComponent({
98+
poll: new Poll({ client: {}, poll: pollData }),
99+
});
100+
const nameDiv = container.querySelector(TITLE_SELECTOR);
101+
const subtitleDiv = container.querySelector(SUBTITLE_SELECTOR);
102+
expect(nameDiv).toHaveTextContent(pollData.name);
103+
expect(subtitleDiv).toHaveTextContent('');
104+
});
75105
});

0 commit comments

Comments
 (0)