-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: implement a content display area and associated buttons (resolves #2) #4
Changes from 24 commits
4a15121
71498eb
ef00b17
a78a44c
834fa54
2f415ea
c848240
704bc14
0dbbab5
28c3577
011502c
08c1c71
47bb906
df7cb68
b5ddde5
2f86063
c94e4aa
f079472
77e4709
f9f2921
a48c887
d9835ea
bbe43d3
bd77ddd
5ad860d
241b738
07aed46
e56aba6
4fbcf01
16c2c36
f14cbaa
1f73831
a1badc7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
"node_modules/" | ||
], | ||
"rules": { | ||
"@typescript-eslint/no-explicit-any": ["off"], | ||
"indent": [ | ||
"error", | ||
2 | ||
|
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright 2024 Inclusive Design Research Centre, OCAD University | ||
* All rights reserved. | ||
* | ||
* Licensed under the New BSD license. You may not use this file except in | ||
* compliance with this License. | ||
* | ||
* You may obtain a copy of the License at | ||
* https://github.com/inclusive-design/adaptive-palette/blob/main/LICENSE | ||
*/ | ||
|
||
import { render, screen } from "@testing-library/preact"; | ||
import "@testing-library/jest-dom"; | ||
import { html } from "htm/preact"; | ||
|
||
import { initAdaptivePaletteGlobals } from "./GlobalData"; | ||
import { CommandClearEncoding } from "./CommandClearEncoding"; | ||
|
||
describe("CommandClearEncoding render tests", () => { | ||
|
||
const TEST_CELL_ID = "command-del-last-encoding"; | ||
const testCell = { | ||
options: { | ||
"label": "Clear", | ||
"bciAvId": 13665, | ||
"rowStart": 2, | ||
"rowSpan": 1, | ||
"columnStart": 14, | ||
"columnSpan": 1 | ||
} | ||
}; | ||
|
||
beforeAll(async () => { | ||
await initAdaptivePaletteGlobals(); | ||
}); | ||
|
||
test("CommandClearEncoding rendering", async () => { | ||
|
||
render(html` | ||
<${CommandClearEncoding} | ||
id="${TEST_CELL_ID}" | ||
options=${testCell.options} | ||
/>` | ||
); | ||
|
||
// Check the rendered cell | ||
const button = await screen.findByRole("button", {name: testCell.options.label}); | ||
|
||
// Check that the CommandClearEncoding/button is rendered and has the correct | ||
// attributes and text. | ||
expect(button).toBeVisible(); | ||
expect(button).toBeValid(); | ||
expect(button.id).toBe(TEST_CELL_ID); | ||
expect(button.getAttribute("class")).toBe("btn-command"); | ||
expect(button.textContent).toBe(testCell.options.label); | ||
|
||
// Check the grid cell styles. | ||
expect(button.style["grid-column"]).toBe("14 / span 1"); | ||
expect(button.style["grid-row"]).toBe("2 / span 1"); | ||
|
||
// Check disabled state (should be enabled) | ||
expect(button.getAttribute("disabled")).toBe(null); | ||
}); | ||
|
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2023-2024 Inclusive Design Research Centre, OCAD University | ||
* All rights reserved. | ||
* | ||
* Licensed under the New BSD license. You may not use this file except in | ||
* compliance with this License. | ||
* | ||
* You may obtain a copy of the License at | ||
* https://github.com/inclusive-design/adaptive-palette/blob/main/LICENSE | ||
*/ | ||
|
||
import { html } from "htm/preact"; | ||
import { BlissSymbol } from "./BlissSymbol"; | ||
import { usePaletteState } from "./GlobalData"; | ||
import { BlissCellType } from "./index.d"; | ||
import { getGridStyle } from "./GlobalUtils"; | ||
|
||
type CommandClearEncodingProps = { | ||
id: string, | ||
options: BlissCellType | ||
} | ||
|
||
export function CommandClearEncoding (props: CommandClearEncodingProps) { | ||
const { id, options } = props; | ||
const { label, bciAvId, columnStart, columnSpan, rowStart, rowSpan } = options; | ||
|
||
// Using separate lines to get "fullEncoding" & "setFullEncoding" rather than using one single line: | ||
// { fullEncoding, setFullEncoding } = usePaletteState(); | ||
// is to accommodate the component unit test in which the parent palette component is not tested. The | ||
// palette state is defined in the palette context. | ||
const paletteState = usePaletteState(); | ||
const setFullEncoding = paletteState?.setFullEncoding; | ||
|
||
const gridStyles = getGridStyle(columnStart, columnSpan, rowStart, rowSpan); | ||
|
||
const cellClicked = () => { | ||
setFullEncoding([]); | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should speak "clear". |
||
|
||
return html` | ||
<button id="${id}" class="btn-command" style="${gridStyles}" onClick=${cellClicked}> | ||
<${BlissSymbol} bciAvId=${bciAvId} label=${label}/> | ||
</button> | ||
`; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright 2024 Inclusive Design Research Centre, OCAD University | ||
* All rights reserved. | ||
* | ||
* Licensed under the New BSD license. You may not use this file except in | ||
* compliance with this License. | ||
* | ||
* You may obtain a copy of the License at | ||
* https://github.com/inclusive-design/adaptive-palette/blob/main/LICENSE | ||
*/ | ||
|
||
import { render, screen } from "@testing-library/preact"; | ||
import "@testing-library/jest-dom"; | ||
import { html } from "htm/preact"; | ||
|
||
import { initAdaptivePaletteGlobals } from "./GlobalData"; | ||
import { CommandDelLastEncoding } from "./CommandDelLastEncoding"; | ||
|
||
describe("CommandDelLastEncoding render tests", () => { | ||
|
||
const TEST_CELL_ID = "command-del-last-encoding"; | ||
const testCell = { | ||
options: { | ||
"label": "Delete", | ||
"bciAvId": 12613, | ||
"rowStart": 2, | ||
"rowSpan": 1, | ||
"columnStart": 13, | ||
"columnSpan": 1 | ||
} | ||
}; | ||
|
||
beforeAll(async () => { | ||
await initAdaptivePaletteGlobals(); | ||
}); | ||
|
||
test("CommandDelLastEncoding rendering", async () => { | ||
|
||
render(html` | ||
<${CommandDelLastEncoding} | ||
id="${TEST_CELL_ID}" | ||
options=${testCell.options} | ||
/>` | ||
); | ||
|
||
// Check the rendered cell | ||
const button = await screen.findByRole("button", {name: testCell.options.label}); | ||
|
||
// Check that the CommandDelLastEncoding/button is rendered and has the correct | ||
// attributes and text. | ||
expect(button).toBeVisible(); | ||
expect(button).toBeValid(); | ||
expect(button.id).toBe(TEST_CELL_ID); | ||
expect(button.getAttribute("class")).toBe("btn-command"); | ||
expect(button.textContent).toBe(testCell.options.label); | ||
|
||
// Check the grid cell styles. | ||
expect(button.style["grid-column"]).toBe("13 / span 1"); | ||
expect(button.style["grid-row"]).toBe("2 / span 1"); | ||
|
||
// Check disabled state (should be enabled) | ||
expect(button.getAttribute("disabled")).toBe(null); | ||
}); | ||
|
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2023-2024 Inclusive Design Research Centre, OCAD University | ||
* All rights reserved. | ||
* | ||
* Licensed under the New BSD license. You may not use this file except in | ||
* compliance with this License. | ||
* | ||
* You may obtain a copy of the License at | ||
* https://github.com/inclusive-design/adaptive-palette/blob/main/LICENSE | ||
*/ | ||
|
||
import { html } from "htm/preact"; | ||
import { BlissSymbol } from "./BlissSymbol"; | ||
import { usePaletteState } from "./GlobalData"; | ||
import { BlissCellType } from "./index.d"; | ||
import { getGridStyle } from "./GlobalUtils"; | ||
|
||
type CommandDelLastEncodingProps = { | ||
id: string, | ||
options: BlissCellType | ||
} | ||
|
||
export function CommandDelLastEncoding (props: CommandDelLastEncodingProps) { | ||
const { id, options } = props; | ||
const { label, bciAvId, columnStart, columnSpan, rowStart, rowSpan } = options; | ||
|
||
// Using separate lines to get "fullEncoding" & "setFullEncoding" rather than using one single line: | ||
// { fullEncoding, setFullEncoding } = usePaletteState(); | ||
// is to accommodate the component unit test in which the parent palette component is not tested. The | ||
// palette state is defined in the palette context. | ||
const paletteState = usePaletteState(); | ||
const fullEncoding = paletteState?.fullEncoding; | ||
const setFullEncoding = paletteState?.setFullEncoding; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment no longer applies -- there are no separate lines. Did you find a way around having to use separate lines? |
||
const gridStyles = getGridStyle(columnStart, columnSpan, rowStart, rowSpan); | ||
|
||
const cellClicked = () => { | ||
const newEncoding = [...fullEncoding]; | ||
newEncoding.pop(); | ||
setFullEncoding(newEncoding); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above with |
||
}; | ||
|
||
return html` | ||
<button id="${id}" class="btn-command" style="${gridStyles}" onClick=${cellClicked}> | ||
<${BlissSymbol} bciAvId=${bciAvId} label=${label}/> | ||
</button> | ||
`; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2023 Inclusive Design Research Centre, OCAD University | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Copyright 2023-2024". Also:
How's that for picky? ;-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Being picky in code review is a valuable trait. 👍 |
||
* All rights reserved. | ||
* | ||
* Licensed under the New BSD license. You may not use this file except in | ||
* compliance with this License. | ||
* | ||
* You may obtain a copy of the License at | ||
* https://github.com/inclusive-design/adaptive-palette/blob/main/LICENSE | ||
*/ | ||
|
||
.bmwEncodingArea { | ||
align-items: center; | ||
background-color: #fff; | ||
border: 3px solid #ccc; | ||
color: #000; | ||
display: flex; | ||
overflow: auto; /* Add scrollbar when content overflows */ | ||
|
||
&:hover { | ||
background-color: limegreen; | ||
color: white; | ||
} | ||
|
||
.blissSymbol { | ||
margin: 0 0.5rem; | ||
text-align: center; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2023-2024 Inclusive Design Research Centre, OCAD University | ||
* All rights reserved. | ||
* | ||
* Licensed under the New BSD license. You may not use this file except in | ||
* compliance with this License. | ||
* | ||
* You may obtain a copy of the License at | ||
* https://github.com/inclusive-design/adaptive-palette/blob/main/LICENSE | ||
*/ | ||
|
||
import { render, screen } from "@testing-library/preact"; | ||
import "@testing-library/jest-dom"; | ||
import { html } from "htm/preact"; | ||
import { ContentBmwEncoding } from "./ContentBmwEncoding"; | ||
import { initAdaptivePaletteGlobals } from "./GlobalData"; | ||
|
||
test("The BMW Encoding content area is rendered correctly", async () => { | ||
await initAdaptivePaletteGlobals(); | ||
|
||
const cellId = "uuid-of-bmw-encoding-area"; | ||
const cellOptions = { | ||
columnStart: 1, | ||
columnSpan: 5, | ||
rowStart: 2, | ||
rowSpan: 3 | ||
}; | ||
|
||
render(html` | ||
<${ContentBmwEncoding} | ||
id="${cellId}" | ||
options=${cellOptions} | ||
/>` | ||
); | ||
|
||
// Test the content area is rendered properly | ||
const encodingAreaByLabel = await screen.findByLabelText("BMW Encoding Area"); | ||
expect(encodingAreaByLabel.id).toBe(cellId); | ||
expect(encodingAreaByLabel.style["grid-column"]).toBe("1 / span 5"); | ||
expect(encodingAreaByLabel.style["grid-row"]).toBe("2 / span 3"); | ||
|
||
// The aria role is defined | ||
const encodingAreaByRole = await screen.findByRole("region"); | ||
expect(encodingAreaByRole).toBeVisible(); | ||
expect(encodingAreaByRole).toBeValid(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The display area should have a label, and a test that it's properly set. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line 37-40 in this test finds the display area by "aria-label", which is to test the area has a properly named label. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, I missed that. |
||
|
||
// Nothing is rendered in the content area | ||
expect(encodingAreaByLabel.childNodes.length).toBe(0); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the rationale that if an explicit
any
is required, then that's allowed? That the developer would need to consciously and judiciously add theany
declaration, knowing there was no way around it? I had to do it once in the case ofBlissSymbol.ts
. In that case I disabled the check for explicitany
but just for that one line. Are there are a lot of places where explicitany
is used?Also, why is it not just "off"? Why the array?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, @klown. Allowing the use of "any" type across the project is dangerous. It's better to do it case by case as what you did with
BlissSymbol.ts
. I will remove it. I used "any" when working on this PR but removed them at the end. This line is no longer needed.