Skip to content

Commit 737a41f

Browse files
committed
Merge branch 'master' into improvement/react-18-update
2 parents 8686fe4 + a0d484a commit 737a41f

34 files changed

+722
-397
lines changed

.github/workflows/cypress.yml

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ jobs:
1616
steps:
1717
- name: Checkout
1818
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
1921
- name: Cypress run (Ada)
2022
uses: cypress-io/github-action@v6
2123
with:
@@ -24,15 +26,62 @@ jobs:
2426
env:
2527
CYPRESS_SITE: ada
2628
- name: Cypress run (Physics)
29+
if: ${{ success() || failure() }}
2730
uses: cypress-io/github-action@v6
2831
with:
2932
component: true
3033
browser: chrome
3134
env:
3235
CYPRESS_SITE: phy
33-
- name: Upload artifacts
36+
- name: VRT update - create or update branch
37+
id: cypress-create-branch
3438
if: ${{ failure() }}
35-
uses: actions/upload-artifact@v4
39+
run: |
40+
target_ref=${{ github.head_ref || github.ref_name }}
41+
update_branch_name=vrt/$target_ref
42+
git config --global user.email "actions@github.com"
43+
git config --global user.name "GitHub Actions"
44+
find ./src/test/pages/__image_snapshots__ -type f -name "*.actual.png" -exec bash -c 'mv "$1" "${1/.actual./.}"' shell {} \;
45+
git fetch origin $target_ref
46+
git checkout -B $update_branch_name origin/$target_ref
47+
git commit -am "Update VRT baselines"
48+
git push --set-upstream origin $update_branch_name --force
49+
echo "TARGET_REF=$target_ref" >> "$GITHUB_ENV"
50+
echo "UPDATE_BRANCH_NAME=$update_branch_name" >> "$GITHUB_ENV"
51+
- name: VRT update - create PR if required
52+
id: cypress-create-pr
53+
if: ${{ failure() && steps.cypress-create-branch.outcome == 'success' }}
54+
uses: actions/github-script@v7
3655
with:
37-
name: visual-diffs
38-
path: src/test/**/*.diff.png
56+
result-encoding: string
57+
script: |
58+
const { repo, owner } = context.repo;
59+
const pulls = await github.rest.pulls.list({
60+
owner: owner,
61+
repo: repo,
62+
head: "${{ env.UPDATE_BRANCH_NAME }}",
63+
base: "${{ env.TARGET_REF }}",
64+
state: 'open',
65+
});
66+
67+
if (pulls.data.length == 0) {
68+
const pr = await github.rest.pulls.create({
69+
title: '[VRT] Update baselines for ${{ env.TARGET_REF }}',
70+
owner: owner,
71+
repo: repo,
72+
head: "${{ env.UPDATE_BRANCH_NAME }}",
73+
base: "${{ env.TARGET_REF }}",
74+
body: 'Updates VRT baselines'
75+
});
76+
return pr.data.html_url;
77+
} else {
78+
return pulls.data[0].html_url;
79+
};
80+
env:
81+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
82+
- name: VRT update - write job summary
83+
if: ${{ failure() && steps.cypress-create-pr.outcome == 'success' }}
84+
run: |
85+
echo '## 👀 Visual Regression Test updates' >> $GITHUB_STEP_SUMMARY
86+
echo 'This run failed due to visual differences compared to our baseline images. A PR with new baseline images has been generated. Please review it [here](${{ steps.cypress-create-pr.outputs.result }}) and merge it if the differences are expected.' >> $GITHUB_STEP_SUMMARY
87+

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
"html-to-text": "^9.0.5",
2424
"identity-obj-proxy": "3.0.0",
2525
"immer": "^9.0.21",
26-
"inequality": "1.1.0",
27-
"inequality-grammar": "1.2.2",
26+
"inequality": "1.1.1",
27+
"inequality-grammar": "1.3.2",
2828
"isaac-graph-sketcher": "0.13.7",
2929
"js-cookie": "^3.0.5",
3030
"katex": "^0.16.11",

src/IsaacApiTypes.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ export interface IsaacCardDeckDTO extends ContentDTO {
1818
cards?: (IsaacCardDTO & { imageClassName?: string; buttonText?: string })[];
1919
}
2020

21-
export interface ChemicalFormulaDTO extends ChoiceDTO {
22-
mhchemExpression?: string;
23-
}
24-
2521
export interface TestCaseDTO extends QuestionValidationResponseDTO {
2622
expected?: boolean;
2723
}
@@ -210,6 +206,7 @@ export interface IsaacRegexMatchQuestionDTO extends QuestionDTO {
210206
}
211207

212208
export interface IsaacSymbolicChemistryQuestionDTO extends IsaacSymbolicQuestionDTO {
209+
isNuclear?: boolean;
213210
}
214211

215212
export interface IsaacSymbolicLogicQuestionDTO extends IsaacSymbolicQuestionDTO {

src/app/components/content/IsaacCard.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ const PhysicsCard = ({doc, imageClassName}: IsaacCardProps) => {
1515
const classes = classNames("menu-card", {"disabled": disabled, "isaac-card-vertical": verticalContent});
1616
const imgSrc = image?.src && apiHelper.determineImageUrl(image.src);
1717

18-
const link = (clickUrl && isAppLink(clickUrl)) ? <Link to={clickUrl} className={classes + " stretched-link"} aria-label={title} aria-disabled={disabled}/> :
19-
<a href={clickUrl} className={classes + " stretched-link"} aria-label={title} aria-disabled={disabled}/>
18+
const link = (clickUrl && isAppLink(clickUrl)) ? <Link to={clickUrl} className={"stretched-link"} aria-label={title} aria-disabled={disabled}/> :
19+
<a href={clickUrl} className={"stretched-link"} aria-label={title} aria-disabled={disabled}/>
2020

21-
return <Col className="d-flex justify-content-center">
21+
return <Col className="d-flex h-100 justify-content-center">
2222
{verticalContent ?
2323
<Card className={classes}>
2424
{image && <Row className={imageClassName}>
@@ -39,7 +39,7 @@ const PhysicsCard = ({doc, imageClassName}: IsaacCardProps) => {
3939
{title}
4040
</CardTitle>
4141
<CardBody>
42-
<Row className="mx-2">
42+
<Row className="h-100 mx-2">
4343
{image && <Col xs={4} sm={12} lg={4} className="col-centered">
4444
<img className={classes} src={imgSrc} alt=""/>
4545
</Col>}

src/app/components/content/IsaacClozeQuestion.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
NULL_CLOZE_ITEM,
1414
NULL_CLOZE_ITEM_ID,
1515
isDefined,
16+
isTouchDevice,
1617
useCurrentQuestionAttempt,
1718
useDeviceSize
1819
} from "../../services";
@@ -497,7 +498,7 @@ const IsaacClozeQuestion = ({doc, questionId, readonly, validationResponse}: Isa
497498
{doc.children}
498499
</IsaacContentValueOrChildren>
499500

500-
{deviceSize !== "xs" && <>
501+
{(!(deviceSize === "xs" || isTouchDevice())) && <>
501502
{/* The item attached to the users cursor while dragging (just for display, shouldn't contain useDraggable/useSortable hooks) */}
502503
<DragOverlay>
503504
{activeItem && <Badge className="p-2 cloze-item is-dragging">

src/app/components/content/IsaacCoordinateQuestion.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {Button, Input} from "reactstrap";
55
import {isDefined, useCurrentQuestionAttempt} from "../../services";
66
import {IsaacQuestionProps} from "../../../IsaacAppTypes";
77
import {Immutable} from "immer";
8+
import QuestionInputValidation from "../elements/inputs/QuestionInputValidation";
89

910
// Custom input component for coordinates - a pair of inputs, one for x and one for y, formatted with brackets
1011
// and a comma in between.
@@ -16,6 +17,15 @@ interface CoordinateInputProps {
1617
readonly?: boolean;
1718
remove?: () => void;
1819
}
20+
21+
export const coordinateInputValidator = (input: string) => {
22+
const errors = [];
23+
if (/[0-9]\s*[+/÷\-x×]\s*[0-9]/.test(input)) {
24+
errors.push('Simplify your answer into a single decimal number.');
25+
}
26+
return errors;
27+
};
28+
1929
const CoordinateInput = (props: CoordinateInputProps) => {
2030
const {value, placeholderXValue, placeholderYValue, onChange, readonly, remove} = props;
2131
return <span className="coordinate-input">
@@ -105,6 +115,7 @@ const IsaacCoordinateQuestion = ({doc, questionId, readonly}: IsaacQuestionProps
105115
onChange={value => updateItem(0, value)}
106116
/>
107117
}
118+
<QuestionInputValidation userInput={currentAttempt?.items?.map(answer => ((answer.x ?? "").concat(" ", answer.y ?? ""))).toString() ?? ""} validator={coordinateInputValidator}/>
108119
{!doc.numberOfCoordinates && <Button color="secondary" size="sm" className="mt-3" onClick={() => updateItem(currentAttempt?.items?.length ?? 1, {...DEFAULT_COORDINATE_ITEM})}>Add coordinate</Button>}
109120
</div>;
110121
};

0 commit comments

Comments
 (0)