Skip to content

Commit

Permalink
merge execute-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dlopezalvas committed Sep 27, 2024
2 parents 3d50a97 + c58c2f1 commit 701f6ea
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ jobs:
- name: Run tests
run: xvfb-run -a npm run test

- name: Cypress run
uses: cypress-io/github-action@v6
with:
component: true

pack-linux: # When there is a tag, pack the installers and upload to Github.
runs-on: ubuntu-latest
env:
Expand Down
4 changes: 2 additions & 2 deletions src/components/challengeView/SceneButtons/Execute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ export const ExecuteButton = ({ challenge }: ExecuteButtonProps) => {
return <>
<Tooltip title={t('run.tooltip')}>
{isSmallScreen ?
<IconButton className={styles['icon-button']} onClick={handleExcecute} data-testid='execute-button' data-finishedExecution={finishedExecution}>
<IconButton className={styles['icon-button']} onClick={handleExcecute} data-testid='execute-button' data-finishedexecution={finishedExecution}>
<Stack>
<Circle color='success' className={styles['circle-icon']} />
<PlayArrow className={styles['icon']} />
</Stack>
</IconButton >
:
<Button variant="contained" color="success" onClick={handleExcecute} data-testid='execute-button' data-finishedExecution={finishedExecution}>{t("run.label")} </Button>
<Button variant="contained" color="success" onClick={handleExcecute} data-testid='execute-button' data-finishedexecution={finishedExecution}>{t("run.label")} </Button>
}
</Tooltip>
<EndDialog showModal={showModal} setShowModal={setShowModal} />
Expand Down
2 changes: 1 addition & 1 deletion src/test/integration/ChallengeView.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('Integration - Challenge view (scene view and blockly)', () => {
const executeChallengeWithEval = (expression: string, expected: any) => {
cy.get('[data-testid="scene-iframe"]').should('have.attr', 'data-loaded', 'true').then($iframe => {
const iframe = $iframe[0] as HTMLIFrameElement;
cy.get('[data-testid="execute-button"]').click().should('have.attr', 'data-finishedExecution', 'true').then(() => {
cy.get('[data-testid="execute-button"]').click().should('have.attr', 'data-finishedexecution', 'true').then(() => {
expect((iframe.contentWindow as any).eval(`pilas.escena_actual().${expression}`)).to.equal(expected)
})
})
Expand Down
31 changes: 18 additions & 13 deletions src/test/unit/components/interpreter.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ExecuteButton } from "../../../components/challengeView/SceneButtons/Execute"
import { Challenge } from "../../../staticData/challenges"
import { renderComponent } from "../../testUtils"
import { screen, fireEvent, waitFor } from '@testing-library/react'
import { screen, fireEvent, waitFor, act } from '@testing-library/react'
import { interpreterFactory } from "../../../components/challengeView/SceneButtons/interpreterFactory"
import { scene } from "../../../components/challengeView/scene"

Expand All @@ -10,7 +10,7 @@ describe("Interpreter", () => {

beforeEach(() => {

scene['restartScene'] = (_descriptor: string) => {}
scene['restartScene'] = (_descriptor: string) => { }

interpreterMock = {
run: jest.fn(() => false),
Expand All @@ -19,23 +19,28 @@ describe("Interpreter", () => {

interpreterFactory['createInterpreter'] = () => interpreterMock

scene['isTheProblemSolved'] = () => true

})

const challenge = (): Challenge => {
return {
id: 1,
sceneDescriptor: `new EscenaLita(["[[A,L,T],[-,-,E],[-,-,-]]","[[A,T,L],[-,-,E],[-,-,-]]"])`,
toolboxBlockIds: ["AgarrarTomate"],
imageURL: () => ''
}
const challenge: Challenge = {
id: 1,
sceneDescriptor: `new EscenaLita(["[[A,L,T],[-,-,E],[-,-,-]]","[[A,T,L],[-,-,E],[-,-,-]]"])`,
toolboxBlockIds: ["AgarrarTomate"],
imageURL: () => ''
}

test('Interpreter runs on execution', async () => {
renderComponent(<ExecuteButton challenge={challenge()} />)
renderComponent(<ExecuteButton challenge={challenge} />)
const button = await screen.findByTestId('execute-button')
fireEvent.click(button)
await new Promise(r => setTimeout(r, 2000));
//await waitFor()
act(() => {
fireEvent.click(button);
});

await waitFor(() => {
expect(button).toHaveAttribute('data-finishedexecution', 'true');
});

expect(interpreterMock.run).toHaveBeenCalled();
})
})

0 comments on commit 701f6ea

Please sign in to comment.