-
Secret Spreadsheet - How it works:
+
+ Secret Spreadsheet - How it works:
+

-
Cells of this spreadsheet have been intentionally hidden.
-
Input the hidden data correctly (capitalization matters!) to restore the spreadsheet.
-
diff --git a/src/components/player/question.js b/src/components/player/question.js
index 5389414..f5a50c1 100644
--- a/src/components/player/question.js
+++ b/src/components/player/question.js
@@ -1,17 +1,41 @@
-import React from 'react';
+import React, { useEffect, useRef } from 'react';
+
+const ariaWarningText = 'After closing this dialog focus will be automatically moved to the first empty cell in the spreadsheet.'
// the popup containing the question and description given by the widget creator
// at a minimum shows the question, description is optional
const Question = props => {
+ const questionEl = useRef(null)
+
+ // bit of a hack to make sure the question is given focus when it comes up
+ useEffect(() => {
+ if (questionEl.current) questionEl.current.focus()
+ }, [])
+
return (
-
{props.question}
+
+ {props.question}
+
- {props.description !== `` ?
{props.description}
:null}
+ {
+ props.description !== ``
+ ?
+
{props.description}
+ :
+ null
+ }
-
- Next
+
+ Next
diff --git a/src/components/player/question.test.js b/src/components/player/question.test.js
index 5050189..b21150f 100644
--- a/src/components/player/question.test.js
+++ b/src/components/player/question.test.js
@@ -1,35 +1,77 @@
+jest.mock('react', () => {
+ const ActualReact = jest.requireActual('react')
+ return {
+ ...ActualReact,
+ useRef: jest.fn()
+ }
+})
+
import React from 'react';
import Question from './question';
-import renderer from 'react-test-renderer';
+import { create, act } from 'react-test-renderer';
describe(`Question component`, () => {
beforeEach(() => {
jest.resetModules();
+ React.useRef.mockClear();
});
test(`Is rendered with question body`, () => {
+ const mockFocus = jest.fn();
+ React.useRef.mockReturnValue({
+ current: {
+ focus: mockFocus
+ }
+ });
+
const props = {
handleQuestionToggle: jest.fn(),
question: `Test entry question`,
description: `Test question body`
};
- const component = renderer.create(
);
+ let component
+ act(() => {
+ component = create(
, {
+ createNodeMock: () => ({
+ focus: mockFocus
+ })
+ });
+ })
const tree = component.toJSON();
expect(tree).toMatchSnapshot();
+
+ // bonus test - make sure the ref works and auto-focuses
+ expect(mockFocus).toHaveBeenCalled();
});
test(`Is rendered without question body`, () => {
+ const mockFocus = jest.fn();
+ React.useRef.mockReturnValue({
+ current: {
+ focus: mockFocus
+ }
+ });
+
const props = {
handleQuestionToggle: jest.fn(),
question: `Test entry question`,
description: ``
};
- const component = renderer.create(
);
+ // not sure if this is even possible, but...
+ // update the ref to null to make sure nothing calls 'focus'?
+ let component
+ act(() => {
+ component = create(
, {
+ createNodeMock: () => null
+ });
+ })
const tree = component.toJSON();
expect(tree).toMatchSnapshot();
+
+ expect(mockFocus).not.toHaveBeenCalled();
});
});
diff --git a/src/player.js b/src/player.js
index 805bd22..ae02628 100644
--- a/src/player.js
+++ b/src/player.js
@@ -22,6 +22,7 @@ class PlayerApp extends React.Component {
this.handlePopupToggle = this.handlePopupToggle.bind(this);
this.randomize = this.randomize.bind(this);
this.countBlanks = this.countBlanks.bind(this);
+ this.handleQuestionKeyUp = this.handleQuestionKeyUp.bind(this);
this.handleQuestionToggle = this.handleQuestionToggle.bind(this);
}
@@ -108,6 +109,11 @@ class PlayerApp extends React.Component {
}
}
+ // because the 'question' link isn't a button we have to handle space/enter presses on it ourselves
+ handleQuestionKeyUp(e) {
+ if (e.key === ' ' || e.key === 'Enter') this.handleQuestionToggle()
+ }
+
// decides if it should show the question popup or not
handleQuestionToggle() {
if (this.state.showQuestion) {
@@ -158,7 +164,18 @@ class PlayerApp extends React.Component {
{this.props.title}
- {this.state.popup ? null:
Help}
+ {
+ this.state.popup
+ ?
+ null
+ :
+
+
+ Help
+
+ }
@@ -174,7 +191,8 @@ class PlayerApp extends React.Component {
Input the missing data to complete the spreadsheet:
-