Skip to content

Commit

Permalink
linter
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnoutAllaert committed May 23, 2024
1 parent a21ab44 commit 72f6909
Show file tree
Hide file tree
Showing 43 changed files with 777 additions and 575 deletions.
22 changes: 21 additions & 1 deletion .github/workflows/django.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ jobs:
uses: actions/setup-python@v3
with:
python-version: '3.10'
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '16'
- name: Install Dependencies
run: |
python3 -m pip install --upgrade pip
Expand All @@ -41,7 +45,17 @@ jobs:
cd api
flake8 .
cd ..
- name: Run Tests
- name: Install Dependencies Frontend
run: |
cd frontend/frontend
npm i
cd ../..
- name: Linting Frontend
run: |
cd frontend/frontend
eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0
cd ../..
- name: Run Backend Tests
env:
CLIENT_ID: ${{ secrets.CLIENT_ID }}
CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}
Expand All @@ -55,7 +69,13 @@ jobs:
DB_PORT: ${{ secrets.DB_PORT }}
DB_ENGINE: ${{secrets.DB_ENGINE}}


run: |
python manage.py makemigrations api
python manage.py migrate api
python manage.py test
- name: Run Frontend Tests
run: |
cd frontend/frontend
npm run cypress-component
cd ../..
22 changes: 11 additions & 11 deletions frontend/frontend/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { defineConfig } from "cypress";
import { defineConfig } from 'cypress'

export default defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
e2e: {
setupNodeEvents() {
// implement node event listeners here
},
},
},

component: {
devServer: {
framework: "react",
bundler: "vite",
component: {
devServer: {
framework: 'react',
bundler: 'vite',
},
},
},
});
})
134 changes: 81 additions & 53 deletions frontend/frontend/cypress/component/AssignmentListItem.cy.tsx
Original file line number Diff line number Diff line change
@@ -1,59 +1,87 @@
import { AssignmentListItem } from '../../src/components/AssignmentListItem';
import { BrowserRouter } from 'react-router-dom';
import fixtures from '../fixtures/fixtures.json';
import { AssignmentListItem } from '../../src/components/AssignmentListItem'
import { BrowserRouter } from 'react-router-dom'
import fixtures from '../fixtures/fixtures.json'

describe('AssignmentListItem', () => {
const mockProps = {
id: fixtures.id,
projectName: fixtures.project,
dueDate: new Date().toLocaleDateString(),
status: false,
isStudent: true,
};
const mockProps = {
id: fixtures.id,
projectName: fixtures.project,
dueDate: new Date().toLocaleDateString(),
status: false,
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('#dueDate').should('contain.text', new Date().toLocaleDateString());
cy.get('#cross').should('exist');
cy.get('#check').should('not.exist');
});
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('#dueDate').should(
'contain.text',
new Date().toLocaleDateString()
)
cy.get('#cross').should('exist')
cy.get('#check').should('not.exist')
})

it('renders with checkmark', () => {
mockProps.status = true;
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('#dueDate').should('contain.text', new Date().toLocaleDateString());
cy.get('#cross').should('not.exist');
cy.get('#check').should('exist');
});
it('renders with checkmark', () => {
mockProps.status = true
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('#dueDate').should(
'contain.text',
new Date().toLocaleDateString()
)
cy.get('#cross').should('not.exist')
cy.get('#check').should('exist')
})

it('renders with no due date', () => {
mockProps.dueDate = undefined;
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);
// 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());
cy.get('#cross').should('not.exist');
cy.get('#check').should('exist');
});
it('renders with no due date', () => {
mockProps.dueDate = undefined
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)
// 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()
)
cy.get('#cross').should('not.exist')
cy.get('#check').should('exist')
})

it('renders as teacher', () => {
mockProps.isStudent = false;
mockProps.dueDate = new Date().toLocaleDateString();
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('#dueDate').should('contain.text', new Date().toLocaleDateString());
cy.get('#cross').should('not.exist');
cy.get('#check').should('not.exist');
});
});
it('renders as teacher', () => {
mockProps.isStudent = false
mockProps.dueDate = new Date().toLocaleDateString()
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('#dueDate').should(
'contain.text',
new Date().toLocaleDateString()
)
cy.get('#cross').should('not.exist')
cy.get('#check').should('not.exist')
})
})
104 changes: 61 additions & 43 deletions frontend/frontend/cypress/component/CourseCard.cy.tsx
Original file line number Diff line number Diff line change
@@ -1,64 +1,82 @@
import { CourseCard } from '../../src/components/CourseCard';
import { BrowserRouter } from 'react-router-dom';
import fixtures from '../fixtures/fixtures.json';
import { CourseCard } from '../../src/components/CourseCard'
import { BrowserRouter } from 'react-router-dom'
import fixtures from '../fixtures/fixtures.json'

describe('CourseCard', () => {
const mockProps = {
courseId: fixtures.id,
archived: false,
isStudent: true,
};
}

it('renders as student', () => {
cy.mount(<BrowserRouter><CourseCard {...mockProps} /></BrowserRouter>);
cy.mount(
<BrowserRouter>
<CourseCard {...mockProps} />
</BrowserRouter>
)
// data is fetched from the backend, so we can't check that
cy.get('.MuiCard-root').should('exist');
cy.get('.MuiCardContent-root').should('exist');
cy.get('#courseInfo').should('have.text', 'undefined: undefined: 0').click();
cy.get('#student').should('exist');
cy.get('#teacherArchived').should('not.exist');
cy.get('#teacherNonArchived').should('not.exist');
cy.get('#project').contains('Project');
cy.get('#deadline').contains('Deadline');
cy.get('#status').contains('Status');
cy.get('#archiveButton').should('not.exist');
});
cy.get('.MuiCard-root').should('exist')
cy.get('.MuiCardContent-root').should('exist')
cy.get('#courseInfo')
.should('have.text', 'undefined: undefined: 0')
.click()
cy.get('#student').should('exist')
cy.get('#teacherArchived').should('not.exist')
cy.get('#teacherNonArchived').should('not.exist')
cy.get('#project').contains('Project')
cy.get('#deadline').contains('Deadline')
cy.get('#status').contains('Status')
cy.get('#archiveButton').should('not.exist')
})

it('renders archived as teacher', () => {
const mockProps = {
courseId: fixtures.id,
archived: true,
isStudent: false,
};
cy.mount(<BrowserRouter><CourseCard {...mockProps} /></BrowserRouter>);
cy.get('.MuiCard-root').should('exist');
cy.get('.MuiCardContent-root').should('exist');
cy.get('#courseInfo').should('have.text', 'undefined: undefined: 0').click();
cy.get('#student').should('not.exist');
cy.get('#teacherArchived').should('exist');
cy.get('#teacherNonArchived').should('not.exist');
cy.get('#project').contains('Project');
cy.get('#deadline').contains('Deadline');
cy.get('#status').should('not.exist');
cy.get('#archiveButton').should('not.exist');
});
}
cy.mount(
<BrowserRouter>
<CourseCard {...mockProps} />
</BrowserRouter>
)
cy.get('.MuiCard-root').should('exist')
cy.get('.MuiCardContent-root').should('exist')
cy.get('#courseInfo')
.should('have.text', 'undefined: undefined: 0')
.click()
cy.get('#student').should('not.exist')
cy.get('#teacherArchived').should('exist')
cy.get('#teacherNonArchived').should('not.exist')
cy.get('#project').contains('Project')
cy.get('#deadline').contains('Deadline')
cy.get('#status').should('not.exist')
cy.get('#archiveButton').should('not.exist')
})

it('renders non-archived as teacher', () => {
const mockProps = {
courseId: fixtures.id,
archived: false,
isStudent: false,
};
cy.mount(<BrowserRouter><CourseCard {...mockProps} /></BrowserRouter>);
cy.get('.MuiCard-root').should('exist');
cy.get('.MuiCardContent-root').should('exist');
cy.get('#courseInfo').should('have.text', 'undefined: undefined: 0').click();
cy.get('#student').should('not.exist');
cy.get('#teacherArchived').should('not.exist');
cy.get('#teacherNonArchived').should('exist');
cy.get('#project').contains('Project');
cy.get('#deadline').contains('Deadline');
cy.get('#status').should('not.exist');
cy.get('#archiveButton').should('exist');
});
});
}
cy.mount(
<BrowserRouter>
<CourseCard {...mockProps} />
</BrowserRouter>
)
cy.get('.MuiCard-root').should('exist')
cy.get('.MuiCardContent-root').should('exist')
cy.get('#courseInfo')
.should('have.text', 'undefined: undefined: 0')
.click()
cy.get('#student').should('not.exist')
cy.get('#teacherArchived').should('not.exist')
cy.get('#teacherNonArchived').should('exist')
cy.get('#project').contains('Project')
cy.get('#deadline').contains('Deadline')
cy.get('#status').should('not.exist')
cy.get('#archiveButton').should('exist')
})
})
43 changes: 23 additions & 20 deletions frontend/frontend/cypress/component/FileUploadButton.cy.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import InputFileUpload from '../../src/components/FileUploadButton';
import fixtures from '../fixtures/fixtures.json';
import InputFileUpload from '../../src/components/FileUploadButton'
import fixtures from '../fixtures/fixtures.json'

describe('FileUploadButton', () => {
const mockProps = {
Expand All @@ -8,25 +8,28 @@ describe('FileUploadButton', () => {
onFileChange: () => {},
fileTypes: ['pdf'],
path: '../fixtures/test.pdf',
};
}

it('renders', () => {
cy.mount(<InputFileUpload {...mockProps} />);
cy.get('#uploadButton').should('exist').should('have.text', fixtures.name);
cy.get('input[type=file]').should('exist');
cy.contains(fixtures.tooltip).should('not.exist');
cy.get('#uploadButton').trigger('mouseover');
cy.contains(fixtures.tooltip).should('be.visible');
cy.get('#uploadButton').trigger('mouseout');
cy.contains(fixtures.tooltip).should('not.exist');
cy.get('#clearButton').should('exist');
});
cy.mount(<InputFileUpload {...mockProps} />)
cy.get('#uploadButton')
.should('exist')
.should('have.text', fixtures.name)
cy.get('input[type=file]').should('exist')
cy.contains(fixtures.tooltip).should('not.exist')
cy.get('#uploadButton').trigger('mouseover')
cy.contains(fixtures.tooltip).should('be.visible')
cy.get('#uploadButton').trigger('mouseout')
cy.contains(fixtures.tooltip).should('not.exist')
cy.get('#clearButton').should('exist')
})

it('no path', () => {
mockProps.path = '';
cy.mount(<InputFileUpload {...mockProps} />);
cy.get('#uploadButton').should('exist').should('have.text', fixtures.name);
cy.get('#clearButton').should('not.exist');
});

});
mockProps.path = ''
cy.mount(<InputFileUpload {...mockProps} />)
cy.get('#uploadButton')
.should('exist')
.should('have.text', fixtures.name)
cy.get('#clearButton').should('not.exist')
})
})
Loading

0 comments on commit 72f6909

Please sign in to comment.