Skip to content

Commit

Permalink
Test and fix for confusing publish error w/ empty clue
Browse files Browse the repository at this point in the history
  • Loading branch information
mdirolf committed May 6, 2024
1 parent 0ca43b3 commit 3f564b9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
13 changes: 13 additions & 0 deletions app/__tests__/builderReducer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,16 @@ test('missing refs', () => {
]
`);
});

test('basic publish errors', () => {
const state = getState(['a', 'b', 'c', ' ', ' ', ' ', 'd', 'e', 'f'], {
abc: 'test with good enum (3)',
def: 'test with bad enum (5)',
});
expect(builderReducer(state, publish).publishErrors).toMatchInlineSnapshot(`
[
"All squares in the grid must be filled in",
"Puzzle must have a title set",
]
`);
});
6 changes: 3 additions & 3 deletions app/lib/gridBase.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Direction, PosAndDir, Position } from './types';
import { BLOCK, Direction, EMPTY, PosAndDir, Position } from './types';

export interface EntryBase {
index: number;
Expand Down Expand Up @@ -264,15 +264,15 @@ export function entriesFromCells(
if (cellVal === undefined || entry === undefined) {
throw new Error('cellid oob');
}
if (cellVal === '.') {
if (cellVal === BLOCK) {
break;
}
entry[dir] = {
entryIndex: entries.length,
wordIndex: entryPattern.length,
cellIndex: wordlen,
};
if (cellVal === ' ') {
if (cellVal === EMPTY || cellVal === '') {
isComplete = false;
}
entryCells.push({ row: yt, col: xt });
Expand Down
1 change: 1 addition & 0 deletions app/reducers/builderReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,7 @@ function _builderReducer(
const missingClues = Object.entries(
state.grid.entries
.map((e) => e.completedWord ?? '')
.filter((e) => e)
.reduce((counts: Record<string, number>, entry) => {
counts[entry] = (counts[entry] ?? 0) + 1;
return counts;
Expand Down

0 comments on commit 3f564b9

Please sign in to comment.