Skip to content

Commit

Permalink
Merge pull request revisit-studies#459 from revisit-studies/update-cl…
Browse files Browse the repository at this point in the history
…ick-accuracy-demo

Update click accuracy demo
  • Loading branch information
dyr429 authored Aug 26, 2024
2 parents 7696867 + 50a2e14 commit f159645
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 24 deletions.
46 changes: 32 additions & 14 deletions public/demo-click-accuracy-test/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,12 @@
"autoDownloadStudy": false,
"sidebar": true
},
"components": {
"introduction": {
"type": "markdown",
"path": "demo-click-accuracy-test/assets/introduction.md",
"response": []
},
"baseComponents": {
"trial": {
"meta": {
"nr-dots": 1
},
"description": "try to click on the center of the moving dot",
"instruction": "Click on the moving dot",
"type": "react-component",
"path": "demo-click-accuracy-test/assets/ClickAccuracyTest.tsx",
"parameters": {
"speed": 100,
"taskid": "accuracy"
},
"nextButtonLocation": "sidebar",
"response": [
{
Expand All @@ -50,13 +38,43 @@
"type": "iframe"
}
]
},

},
"components": {
"introduction": {
"type": "markdown",
"path": "demo-click-accuracy-test/assets/introduction.md",
"response": []
},
"trial1": {
"baseComponent": "trial",
"meta": {
"nr-dots": 1
},
"parameters": {
"speed": 100,
"taskid": "accuracy"
},

},
"trial2": {
"baseComponent": "trial",
"meta": {
"nr-dots": 1
},
"parameters": {
"speed": 200,
"taskid": "accuracy"
},
}
},
"sequence": {
"order": "fixed",
"components": [
"introduction",
"trial"
"trial1",
"trial2"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function ClickAccuracyTest({ parameters, setAnswer }: StimulusParams<any>) {
const [ref, dms] = useChartDimensions(chartSettings);
const [x, setX] = useState(100);
const [y, setY] = useState(100);
const [speed, setSpeed] = useState(300);
const [speed, setSpeed] = useState(parameters.speed);
const { taskid } = parameters;

const { actions, trrack } = useMemo(() => {
Expand Down
22 changes: 13 additions & 9 deletions tests/demo-click-accuracy-test.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* eslint-disable no-await-in-loop */
import { test, expect } from '@playwright/test';

test('test', async ({ page }) => {
const trialLen = 2;
await page.goto('/');
await page.getByRole('button', { name: 'Dynamic React Stimuli and Provenance Tracking' }).click();

Expand All @@ -10,19 +12,21 @@ test('test', async ({ page }) => {
await page.getByRole('button', { name: 'Next', exact: true }).click();

// Check click accuracy test
const questionText = await page.getByText('Task:');
await expect(questionText).toBeVisible();
// eslint-disable-next-line no-plusplus
for (let i = 0; i < trialLen; i++) {
const questionText = await page.getByText('Task:');
await expect(questionText).toBeVisible();

const emptyAnswers = await page.getByRole('listitem');
await expect(await emptyAnswers.count()).toEqual(0);
const emptyAnswers = await page.getByRole('listitem');
await expect(await emptyAnswers.count()).toEqual(0);

await page.getByRole('main').getByRole('img').click();
await page.getByRole('main').getByRole('img').click();

const oneAnswer = await page.getByRole('listitem');
await expect(await oneAnswer.count()).toEqual(1);

await page.getByRole('button', { name: 'Next', exact: true }).click();
const oneAnswer = await page.getByRole('listitem');
await expect(await oneAnswer.count()).toEqual(1);

await page.getByRole('button', { name: 'Next', exact: true }).click();
}
// Check that the thank you message is displayed
await page.getByText('Please wait while your answers are uploaded.').click();
});

0 comments on commit f159645

Please sign in to comment.