Skip to content

Commit

Permalink
Fix wide/narrow screen size change, add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
davidje13 committed Sep 1, 2024
1 parent b45ef73 commit 88a6203
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
27 changes: 24 additions & 3 deletions frontend/src/components/retro-formats/mood/MoodRetro.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { render } from 'flexible-testing-library-react';
import { act, render, role } from 'flexible-testing-library-react';

import { MoodRetro } from './MoodRetro';

const nop = () => undefined;

describe('MoodRetro', () => {
it('renders without error', () => {
render(
it('can switch between wide and narrow view', () => {
const { getAllBy } = render(
<MoodRetro
retroOptions={{}}
retroItems={[]}
Expand All @@ -16,5 +16,26 @@ describe('MoodRetro', () => {
dispatch={nop}
/>,
);

expect(
getAllBy(role('textbox')).map((i) => i.getAttribute('placeholder')),
).toEqual([
'I\u2019m glad that\u2026',
'I\u2019m wondering about\u2026',
'It wasn\u2019t so great that\u2026',
'Add an action item',
]);

const originalWidth = window.innerWidth;
window.innerWidth = 200;
try {
act(() => window.dispatchEvent(new UIEvent('resize')));

expect(
getAllBy(role('textbox')).map((i) => i.getAttribute('placeholder')),
).toEqual(['I\u2019m glad that\u2026']);
} finally {
window.innerWidth = originalWidth;
}
});
});
4 changes: 3 additions & 1 deletion frontend/src/components/retro-formats/mood/MoodRetro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ export const MoodRetro = ({
!singleColumn || OPTIONS.enableMobileFacilitation.read(retroOptions);

const useAction = useActionFactory(dispatch);
const useFacilitatorAction = canFacilitate ? useAction : () => undefined;
const useFacilitatorAction = useActionFactory(
canFacilitate ? dispatch : undefined,
);

const handleAddItem = useAction(addRetroItem);
const handleAddActionItem = useAction(addRetroActionItem);
Expand Down

0 comments on commit 88a6203

Please sign in to comment.