Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/components/MatrixGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ function noteForColumnPlayback(cell: MatrixCell): string {

function handleClick(cell: MatrixCell) {
if (props.mode !== 'input') return
if (cell.isGiven) {
if (cell.note) playNote(noteForColumnPlayback(cell))
return
}
emit('cell-click', cell.row, cell.col)
if (cell.note) playNote(noteForColumnPlayback(cell))
}
Expand Down
4 changes: 3 additions & 1 deletion src/components/PlayingView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ const displayCells = computed<MatrixCell[][]>(() => {
const activeCellNote = computed<string | null>({
get() {
if (!activeCell.value || session.value.phase !== 'playing') return null
return session.value.answers[activeCell.value.row]?.[activeCell.value.col] ?? null
const { row, col } = activeCell.value
const cell = session.value.puzzle.cells[row]?.[col]
return cell?.isGiven ? cell.note : (session.value.answers[row]?.[col] ?? null)
},
set(note: string | null) {
if (!activeCell.value || note === null || session.value.phase !== 'playing') return
Expand Down
4 changes: 2 additions & 2 deletions src/components/__tests__/MatrixGrid.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ describe('MatrixGrid', () => {
expect(wrapper.emitted('cell-click')).toEqual([[2, 0]])
})

it('does not emit cell-click when a given cell is clicked', async () => {
it('emits cell-click with correct row/col when a given cell is clicked', async () => {
const wrapper = mount(MatrixGrid, {
props: { cells: makeCells(3), mode: 'input', showDegreeLabels: false },
})
// Cell at DOM index 2 is (2,2) — on the diagonal, given.
await wrapper.findAll('.matrix-cell')[2]!.trigger('click')
expect(wrapper.emitted('cell-click')).toBeUndefined()
expect(wrapper.emitted('cell-click')).toEqual([[2, 2]])
})

it('applies active class to the active cell', () => {
Expand Down
19 changes: 19 additions & 0 deletions src/components/__tests__/PlayingView.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,25 @@ describe('PlayingView', () => {
})
})

describe('piano keyboard', () => {
it('sets the active cell when a given cell is clicked', async () => {
startGame()
const wrapper = mountView()
const givenCell = wrapper.find('.matrix-cell.given')
await givenCell.trigger('click')
expect(wrapper.find('.matrix-cell.active').exists()).toBe(true)
})

it("highlights the given cell's note on the piano keyboard after clicking it", async () => {
startGame()
const wrapper = mountView()
const givenCell = wrapper.find('.matrix-cell.given')
const expectedNote = givenCell.text()
await givenCell.trigger('click')
expect(wrapper.findComponent({ name: 'PianoKeyboard' }).props('activeNote')).toBe(expectedNote)
})
})

describe('answer submission flow', () => {
it('stores the answer when NotePicker emits a note', async () => {
const game = startGame()
Expand Down