Skip to content

Commit 4c1cff7

Browse files
authored
fix: account for polls with no options in PollHeader text (#2713)
do not show any string in PollHeader if there are no options.
1 parent 4bf7c5b commit 4c1cff7

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
@@ -27,12 +27,13 @@ export const PollHeader = () => {
2727

2828
const selectionInstructions = useMemo(() => {
2929
if (is_closed) return t<string>('Vote ended');
30-
if (enforce_unique_vote) return t<string>('Select one');
30+
if (enforce_unique_vote || options.length === 1) return t<string>('Select one');
3131
if (max_votes_allowed)
3232
return t<string>('Select up to {{count}}', {
3333
count: max_votes_allowed > options.length ? options.length : max_votes_allowed,
3434
});
35-
return t<string>('Select one or more');
35+
if (options.length > 1) return t<string>('Select one or more');
36+
return '';
3637
}, [is_closed, enforce_unique_vote, max_votes_allowed, options.length, t]);
3738

3839
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)