Skip to content
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

Merged
merged 33 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4a15121
feat: initial implementation of BMW encoding area
cindyli Oct 13, 2023
71498eb
Merge remote-tracking branch 'joseph/feat/create-palette-from-json' i…
cindyli Oct 13, 2023
ef00b17
feat: add the global message handler
cindyli Oct 14, 2023
a78a44c
fix: linted
cindyli Oct 14, 2023
834fa54
doc: improve code comments
cindyli Oct 14, 2023
2f415ea
doc: add code comments for GlobalMessageHandler
cindyli Oct 16, 2023
c848240
fix: add tests for ContentBmwEncoding and GlobalMessageHandler compon…
cindyli Oct 16, 2023
704bc14
Merge branch 'feat/add-cellType-registry' into feat/create-bmw-encoding
cindyli Oct 23, 2023
0dbbab5
fix: merge missing files in the previous commit
cindyli Oct 23, 2023
28c3577
fix: display proper BlissSymbol in encoding area
cindyli Oct 23, 2023
011502c
Merge remote-tracking branch 'joseph/feat/create-palette-from-json' i…
cindyli Oct 23, 2023
08c1c71
fix: adjust style
cindyli Oct 24, 2023
47bb906
Merge remote-tracking branch 'joseph/feat/create-palette-from-json' i…
cindyli Oct 24, 2023
df7cb68
Merge remote-tracking branch 'joseph/feat/create-palette-from-json' i…
cindyli Nov 2, 2023
b5ddde5
fix: improve css for Bliss symbols and fix tests
cindyli Nov 21, 2023
2f86063
Merge remote-tracking branch 'joseph/feat/create-palette-from-json' i…
cindyli Nov 21, 2023
c94e4aa
test: add tests for showing Bliss symbols in the content area
cindyli Nov 21, 2023
f079472
fix: add the type check for addBmwCode payload
cindyli Nov 22, 2023
77e4709
Merge branch 'main' into feat/create-bmw-encoding
cindyli Dec 20, 2023
f9f2921
feat: use preact context to coordinate the addition/removal/clearing …
cindyli Jan 3, 2024
a48c887
feat: add unit tests and integration tests
cindyli Jan 4, 2024
d9835ea
fix: improve styling
cindyli Jan 5, 2024
bbe43d3
fix: code clean up
cindyli Jan 5, 2024
bd77ddd
feat: announce the label of the selected Bliss symbol
cindyli Jan 10, 2024
5ad860d
fix: address review comments
cindyli Jan 23, 2024
241b738
fix: improve css of the grid palette
cindyli Jan 29, 2024
07aed46
fix: the width of the display area no longer changes when appending s…
cindyli Jan 29, 2024
e56aba6
fix: fix the palette test
cindyli Jan 29, 2024
4fbcf01
fix: the display area now has role="textbox"
cindyli Jan 29, 2024
16c2c36
fix: fix the test for ContentBmwEncoding
cindyli Jan 29, 2024
f14cbaa
fix: address more review comments
cindyli Jan 29, 2024
1f73831
fix: improve function comments and copyright messages
cindyli Jan 31, 2024
a1badc7
fix: improve a code comment
cindyli Feb 1, 2024
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
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"node_modules/"
],
"rules": {
"@typescript-eslint/no-explicit-any": ["off"],
Copy link
Contributor

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 the any declaration, knowing there was no way around it? I had to do it once in the case of BlissSymbol.ts. In that case I disabled the check for explicit any but just for that one line. Are there are a lot of places where explicit any is used?

Also, why is it not just "off"? Why the array?

Copy link
Contributor Author

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.

"indent": [
"error",
2
Expand Down
1,861 changes: 1,114 additions & 747 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 1 addition & 9 deletions src/ActionBmwCodeCell.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@

.actionBmwCodeCell {
border: 2px solid blue;
background-color: gray;
border-radius: 5px;
padding: 1rem;
font-size: 1rem;
background-color: beige;
text-align: center;

&:hover, &:focus {
background-color: lightblue;
color: #0000aa;
}
}
33 changes: 25 additions & 8 deletions src/ActionBmwCodeCell.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Inclusive Design Research Centre, OCAD University
* 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
Expand All @@ -10,28 +10,45 @@
*/

import { html } from "htm/preact";
import { OptionsType } from "./index.d";
import { BlissCellType } from "./index.d";
import { BlissSymbol } from "./BlissSymbol";
import { usePaletteState } from "./GlobalData";
import { getGridStyle, speak } from "./GlobalUtils";
import "./ActionBmwCodeCell.scss";


type ActionBmwCodeCellPropsType = {
id: string,
options: OptionsType
options: BlissCellType
};

export function ActionBmwCodeCell (props: ActionBmwCodeCellPropsType) {
// 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;

const {
columnStart, columnSpan, rowStart, rowSpan, bciAvId, label
} = props.options;

const gridStyles = `
grid-column: ${columnStart} / span ${columnSpan};
grid-row: ${rowStart} / span ${rowSpan};
`;
const gridStyles = getGridStyle(columnStart, columnSpan, rowStart, rowSpan);

const cellClicked = () => {
const payload = {
"id": props.id,
"label": props.options.label,
"bciAvId": props.options.bciAvId
};
setFullEncoding([...fullEncoding, payload]);
speak(props.options.label);
};

return html`
<button id="${props.id}" class="actionBmwCodeCell" style="${gridStyles}" >
<button id="${props.id}" class="actionBmwCodeCell" style="${gridStyles}" onClick=${cellClicked}>
<${BlissSymbol}
bciAvId=${bciAvId}
label=${label}
Expand Down
1 change: 0 additions & 1 deletion src/BlissSymbol.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,3 @@ describe("BlissSymbol render tests", () => {
expect(svgElement.getAttribute("aria-hidden")).toBe(null);
});
});

65 changes: 65 additions & 0 deletions src/CommandClearEncoding.test.ts
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);
});

});
45 changes: 45 additions & 0 deletions src/CommandClearEncoding.ts
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([]);
};
Copy link
Contributor

Choose a reason for hiding this comment

The 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>
`;
}
65 changes: 65 additions & 0 deletions src/CommandDelLastEncoding.test.ts
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);
});

});
48 changes: 48 additions & 0 deletions src/CommandDelLastEncoding.ts
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;

Copy link
Contributor

Choose a reason for hiding this comment

The 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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above with ComanndClearEncoding, should speak "delete".

};

return html`
<button id="${id}" class="btn-command" style="${gridStyles}" onClick=${cellClicked}>
<${BlissSymbol} bciAvId=${bciAvId} label=${label}/>
</button>
`;
}
29 changes: 29 additions & 0 deletions src/ContentBmwEncoding.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2023 Inclusive Design Research Centre, OCAD University
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Copyright 2023-2024".

Also:

  • ActionBmwCodeCell.scss,
  • ActionBmwCodeCell.test.ts
  • BlissSymbol.test.ts
  • BlissSymbol.ts
  • ContentBmwEncoding.scss
  • Palette.scss
  • Palette.ts
  • PaletteStore.test.ts
  • PaletteStore.ts
  • SvgUtils.test.ts
  • index.d.ts
  • index.js

How's that for picky? ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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;
}
}
49 changes: 49 additions & 0 deletions src/ContentBmwEncoding.test.ts
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();
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The 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);
});
Loading