Skip to content

Commit

Permalink
addChangeAssignmentPage component testen
Browse files Browse the repository at this point in the history
  • Loading branch information
mathis2003 committed May 23, 2024
1 parent 70055c3 commit 1fb7248
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 85 deletions.
Original file line number Diff line number Diff line change
@@ -1,56 +1,18 @@
import {AddChangeAssignmentPage} from '../../../src/pages/addChangeAssignmentPage/AddChangeAssignmentPage'; // Check if the file path is correct and if the required module exists in the specified location.
import {BrowserRouter} from 'react-router-dom';
import fixtures from '../../fixtures/fixtures.json';
import { AddChangeAssignmentPage } from '../../../src/pages/addChangeAssignmentPage/AddChangeAssignmentPage' // Check if the file path is correct and if the required module exists in the specified location.
import { BrowserRouter } from 'react-router-dom'

// This page fetches data from the backend.
// So as far as the component test is concerned,
// we can only show what shows up before the fetch.
// This is why only the loading animation is checked.
// The rest of the tests are in the integration tests.
describe('AddChangeAssignmentPage', () => {

it('renders assignment name', () => {
cy.mount(<BrowserRouter><AddChangeAssignmentPage/></BrowserRouter>);
// check if the header is rendered
cy.get('#logo').should('exist');
cy.get('#userMenu').should('exist');
// title field
cy.get('#titleField').should('have.attr', 'placeholder', 'Title');
cy.get('#titleField').type('New title');
cy.get('#titleField').should('have.value', 'New title');
cy.get('#uploadButton').should('exist');
// deadline field
cy.get('#deadline').should('have.text', 'Deadline:');
cy.get('#deadlineField').should('have.attr', 'placeholder', 'DD/MM/YYYY hh:mm');
cy.get('#deadlineField').type('311220252359');
cy.get('#deadlineField').should('have.value', '31/12/2025 23:59');
// extra deadline field
cy.get('#extraDeadline').should('have.text', 'Extra Deadline:');
cy.get('#extraDeadlineField').should('have.attr', 'placeholder', 'DD/MM/YYYY hh:mm');
cy.get('#extraDeadlineField').type('311220262359');
cy.get('#extraDeadlineField').should('have.value', '31/12/2026 23:59');
//description field
cy.get('#descriptionField').should('have.attr', 'placeholder', 'Description');
cy.get('#descriptionField').type('New description');
cy.get('#descriptionField').should('have.value', 'New description');
// restrictions field
cy.get('#addRestrictionButton').should('exist').click();
cy.get('#upload').should('exist');
cy.get('#newScript').should('exist');
cy.get('#fileExtensionCheck').should('exist');
cy.get('#filesPresentCheck').should('exist');
cy.get('#mustPassSwitch').should('exist');
cy.get('#cancelButton').should('exist').click();
// max score field
cy.get('#maxScore').should('have.text', 'Max Score:');
cy.get('#maxScoreField').should('have.value', '20');
cy.get('#maxScoreField').clear().type('30');
cy.get('#maxScoreField').should('have.value', '30');
// all buttons
cy.get('#visibilityOff').should('exist').click();
cy.get('#visibilityOn').should('exist').click();
cy.get('#cancel').should('exist').click();
// these have popups
cy.get('#submit').should('exist').click();
cy.get('#cancelButton').should('exist').click();
cy.get('#delete').should('exist').click();
cy.get('#actionButton').should('exist').click();

});

});
cy.mount(
<BrowserRouter>
<AddChangeAssignmentPage />
</BrowserRouter>
)
cy.get('[data-cy=loadingAnimation]').should('exist')
})
})
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import AddRestrictionButton from '../../../src/pages/addChangeAssignmentPage/AddRestrictionButton';
import {BrowserRouter} from 'react-router-dom';
import AddRestrictionButton from '../../../src/pages/addChangeAssignmentPage/AddRestrictionButton'
import { BrowserRouter } from 'react-router-dom'

describe('AddRestrictionsButton', () => {

const mockProps = {
restrictions: [],
setRestrictions: () => {}
};
setRestrictions: () => {},
}

it('renders the restrictions add button', () => {
cy.mount(<BrowserRouter><AddRestrictionButton {...mockProps} /></BrowserRouter>);
cy.get('#addRestrictionButton').should('exist').click();
cy.get('#upload').should('exist');
cy.get('#newScript').should('exist');
cy.get('#fileExtensionCheck').should('exist');
cy.get('#filesPresentCheck').should('exist');
cy.get('#mustPassSwitch').should('exist').click();
cy.get('#cancelButton').should('exist').click();
});

});
cy.mount(
<BrowserRouter>
<AddRestrictionButton {...mockProps} />
</BrowserRouter>
)
cy.get('#addRestrictionButton').should('exist').click()
cy.get('#upload').should('exist')
cy.get('#newScript').should('exist')
cy.get('#cancelButton').should('exist').click()
})
})
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
import RestrictionsDialog from '../../../src/pages/addChangeAssignmentPage/RestrictionsDialog';
import {BrowserRouter} from 'react-router-dom';
import RestrictionsDialog from '../../../src/pages/addChangeAssignmentPage/RestrictionsDialog'
import { BrowserRouter } from 'react-router-dom'

describe('RestrictionsDialog', () => {

const mockProps = {
userid: 1,
restrictions: [],
setRestrictions: () => {},
closeParentDialog: () => {},
};
}

it('renders the dialog', () => {
cy.mount(<BrowserRouter><RestrictionsDialog {...mockProps} /></BrowserRouter>);
cy.get('#upload').should('exist');
cy.get('#newScript').should('exist');
cy.get('#fileExtensionCheck').should('exist');
cy.get('#filesPresentCheck').should('exist');
cy.get('#mustPassSwitch').should('exist').click();
});

});
cy.mount(
<BrowserRouter>
<RestrictionsDialog {...mockProps} />
</BrowserRouter>
)
cy.get('[data-cy=new_scripts_section]').should('exist')
cy.get('#upload').should('exist')
cy.get('[data-cy=uploadInput]').should('exist')
cy.get('#newScript').should('exist')
cy.get('[data-cy=existing_scripts_section]').should('exist')
cy.get('#newScript').click()
cy.get('[data-cy=closeIcon]').should('exist')
cy.get('#scriptName').should('exist')
cy.get('#extension').should('exist')
cy.get('#saveTemplate').should('exist')
cy.get('#saveScript').should('exist')
cy.get('#scriptContent').should('exist')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ export function AddChangeAssignmentPage() {
height: '100vh',
}}
>
<CircularProgress color={'primary'} />
<CircularProgress color={'primary'} data-cy="loadingAnimation" />
<Box></Box>
</Box>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ export default function RestrictionsDialog({
<React.Fragment>
{/* File input for uploading files */}
<input
data-cy="uploadInput"
type="file"
style={{ display: 'none' }}
onChange={(e) => {
Expand All @@ -242,7 +243,11 @@ export default function RestrictionsDialog({
multiple
/>
{/* Vertical button group */}
<Typography variant={'h6'} color={'secondary.contrastText'}>
<Typography
variant={'h6'}
color={'secondary.contrastText'}
data-cy="new_scripts_section"
>
{t('make_new_script') + ':'}
</Typography>

Expand All @@ -255,7 +260,11 @@ export default function RestrictionsDialog({
{buttons}
</Box>
<Box padding="20px" />
<Typography variant={'h6'} color={'secondary.contrastText'}>
<Typography
variant={'h6'}
color={'secondary.contrastText'}
data-cy="existing_scripts_section"
>
{t('choose_existing') + ':'}
</Typography>
<Box
Expand Down Expand Up @@ -434,6 +443,7 @@ export default function RestrictionsDialog({
justifyContent={'flex-start'}
>
<IconButton
data-cy="closeIcon"
edge="start"
color="inherit"
onClick={handleCloseTextEditor}
Expand Down

0 comments on commit 1fb7248

Please sign in to comment.