Skip to content

Commit

Permalink
integration test - execution
Browse files Browse the repository at this point in the history
  • Loading branch information
dlopezalvas committed Sep 26, 2024
1 parent 4a3e3af commit 366d04e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 27 deletions.
6 changes: 4 additions & 2 deletions src/components/challengeView/SceneButtons/Execute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const ExecuteButton = ({ challenge }: ExecuteButtonProps) => {

const { isSmallScreen } = useThemeContext()
const [showModal, setShowModal] = useState(false)
const [finishedExecution, setFinishedExecution] = useState(false)
const { t } = useTranslation('challenge')

const handleExcecute = async () => {
Expand All @@ -26,6 +27,7 @@ export const ExecuteButton = ({ challenge }: ExecuteButtonProps) => {
}

const whenExecuteEnd = async () => {
setFinishedExecution(true)
const solved = await scene.isTheProblemSolved()
if (solved)
setShowModal(true)
Expand Down Expand Up @@ -57,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'>
<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'>{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/components/challengeView/SceneView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const SceneView = ({ descriptor, onLoad }: SceneViewProps) => {
style={{ border: "inherit", borderRadius: "inherit", ...size }}
id="sceneIframe"
data-testid="scene-iframe"
data-loaded={isLoading}
data-loaded={!isLoading}
key={descriptor} // rerenders on descriptor changes
title='iframePilas'
src={adaptURL(`pilas.html`)}
Expand Down
37 changes: 13 additions & 24 deletions src/test/integration/ChallengeView.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,25 @@ describe('<ChallengeView />', () => {
</block>
</xml>`
}
it('renders', () => {


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(() => {
expect((iframe.contentWindow as any).eval(`pilas.escena_actual().${expression}`)).to.equal(expected)
})
})
}

it('Executes ', () => {
LocalStorage.saveCreatorChallenge(challenge)
mount(
<ThemeContextProvider>
<ChallengeView
path={EMBER_IMPORTED_CHALLENGE_PATH} />
</ThemeContextProvider>
)
cy.get('[data-testid="scene-iframe"]').should('have.attr', 'data-loaded', 'false').then($iframe => {
const iframe = $iframe[0] as HTMLIFrameElement;
cy.get('[data-testid="execute-button"]').click()
//console.log((iframe.contentWindow as any).eval('pilas.escena_actual().automata.casillaActual().nroColumna'))
})
executeChallengeWithEval('automata.casillaActual().nroColumna', 1)
})
})

/*
mountWithThemeContext()
cy.get('[data-testid="scene-iframe"]').should('have.attr', 'data-loaded', 'false').then($iframe => {
const iframe = $iframe[0] as HTMLIFrameElement;
console.log((iframe.contentWindow as any).eval('pilas.escena_actual().automata'))
})
mount(<SceneView descriptor={`new EscenaDuba("\
[O,O,O,O,O,O],\
[O,-,-,-,O,-],\
[-,A,-,-,P,-],\
[-,-,-,O,-,-],\
[O,O,O,O,-,O],\
")`} onLoad={() =>console.log((screen.getByTestId("scene-iframe") as any).contentWindow.eval("pilas.escena_actual().automata"))} />)
*/

0 comments on commit 366d04e

Please sign in to comment.