Skip to content

Commit

Permalink
AssignmentListItem test working
Browse files Browse the repository at this point in the history
  • Loading branch information
mathis2003 committed May 23, 2024
1 parent b9c3998 commit 3445adb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
29 changes: 23 additions & 6 deletions frontend/frontend/cypress/component/AssignmentListItem.cy.tsx
Original file line number Diff line number Diff line change
@@ -1,43 +1,60 @@
import { AssignmentListItem } from '../../src/components/AssignmentListItem';
import { BrowserRouter } from 'react-router-dom';
import fixtures from '../fixtures/fixtures.json';
import { SubmissionStatus } from '../../src/pages/submissionPage/SubmissionPage';

describe('AssignmentListItem', () => {
const mockProps = {
id: fixtures.id,
course_id: fixtures.course_id,
projectName: fixtures.project,
dueDate: new Date().toLocaleDateString(),
status: false,
status: SubmissionStatus.FAIL,
isStudent: true,
};

it('renders with cross', () => {
cy.mount(<BrowserRouter><AssignmentListItem {...mockProps} /></BrowserRouter>);
cy.get('.MuiListItem-root').should('exist');
cy.get('#project' + fixtures.id).should('exist');
cy.get('#projectName').should('contain.text', fixtures.project);
cy.get('[data-cy=projectName]').should('contain.text', fixtures.project);
cy.get('#dueDate').should('contain.text', new Date().toLocaleDateString());
cy.get('#cross').should('exist');
cy.get('#check').should('not.exist');
cy.get('#clock').should('not.exist');
});

it('renders with checkmark', () => {
mockProps.status = true;
mockProps.status = SubmissionStatus.PASSED;
cy.mount(<BrowserRouter><AssignmentListItem {...mockProps} /></BrowserRouter>);
cy.get('.MuiListItem-root').should('exist');
cy.get('#project' + fixtures.id).should('exist');
cy.get('#projectName').should('contain.text', fixtures.project);
cy.get('[data-cy=projectName]').should('contain.text', fixtures.project);
cy.get('#dueDate').should('contain.text', new Date().toLocaleDateString());
cy.get('#cross').should('not.exist');
cy.get('#check').should('exist');
cy.get('#clock').should('not.exist');
});

it('renders with alarm', () => {
mockProps.status = SubmissionStatus.PENDING;
cy.mount(<BrowserRouter><AssignmentListItem {...mockProps} /></BrowserRouter>);
cy.get('.MuiListItem-root').should('exist');
cy.get('#project' + fixtures.id).should('exist');
cy.get('[data-cy=projectName]').should('contain.text', fixtures.project);
cy.get('#dueDate').should('contain.text', new Date().toLocaleDateString());
cy.get('#cross').should('not.exist');
cy.get('#check').should('not.exist');
cy.get('#clock').should('exist');
});

it('renders with no due date', () => {
mockProps.dueDate = undefined;
mockProps.status = SubmissionStatus.PASSED;
cy.mount(<BrowserRouter><AssignmentListItem {...mockProps} /></BrowserRouter>);
cy.get('.MuiListItem-root').should('exist');
cy.get('#project' + fixtures.id).should('exist');
cy.get('#projectName').should('contain.text', fixtures.project);
cy.get('[data-cy=projectName]').should('contain.text', fixtures.project);
// normaal zou hier 'no deadline' moeten staan in de correcte taal, maar blijkbaar gaat dat niet in de testen
// omdat er hier niet echt een taal is ingesteld?
cy.get('#dueDate').should('not.contain.text', new Date().toLocaleDateString());
Expand All @@ -51,7 +68,7 @@ describe('AssignmentListItem', () => {
cy.mount(<BrowserRouter><AssignmentListItem {...mockProps} /></BrowserRouter>);
cy.get('.MuiListItem-root').should('exist');
cy.get('#project' + fixtures.id).should('exist');
cy.get('#projectName').should('contain.text', fixtures.project);
cy.get('[data-cy=projectName]').should('contain.text', fixtures.project);
cy.get('#dueDate').should('contain.text', new Date().toLocaleDateString());
cy.get('#cross').should('not.exist');
cy.get('#check').should('not.exist');
Expand Down
1 change: 1 addition & 0 deletions frontend/frontend/cypress/fixtures/fixtures.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"id": "1",
"course_id": "1",
"name": "Test Name",
"project": "Test Project",
"score": "10",
Expand Down
3 changes: 2 additions & 1 deletion frontend/frontend/src/components/AssignmentListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export function AssignmentListItem({
{/* Project Name */}
<ListItemText>
<Typography
data-cy="projectName"
maxWidth={170}
noWrap
textOverflow={'ellipsis'}
Expand Down Expand Up @@ -108,4 +109,4 @@ export function AssignmentListItem({
</ListItem>
</>
)
}
}

0 comments on commit 3445adb

Please sign in to comment.