Add frontend tests for team creation
This commit is contained in:
parent
c6ddb3b051
commit
3045da7491
|
|
@ -251,7 +251,7 @@ describe('Teacher Class Management', () => {
|
||||||
cy.getByDataCy('active-member').should('have.length', 2);
|
cy.getByDataCy('active-member').should('have.length', 2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it.only('creates a new class', () => {
|
it('creates a new class', () => {
|
||||||
const name = 'Hill Valley';
|
const name = 'Hill Valley';
|
||||||
let selectedClass = teacher.selectedClass;
|
let selectedClass = teacher.selectedClass;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,77 @@
|
||||||
|
import {getMinimalMe} from '../../support/helpers';
|
||||||
|
import {hasOperationName} from '../../support/graphql';
|
||||||
|
|
||||||
|
const teacher = getMinimalMe();
|
||||||
|
|
||||||
|
const mockCreateTeamCall = (name) => {
|
||||||
|
cy.intercept('POST', '/api/graphql', (req) => {
|
||||||
|
if (hasOperationName(req, 'CreateTeamMutation')) {
|
||||||
|
let result;
|
||||||
|
if (name) {
|
||||||
|
result = {
|
||||||
|
__typename: 'TeamNode',
|
||||||
|
id: 'newTeamId',
|
||||||
|
name,
|
||||||
|
code: 'ABC',
|
||||||
|
members: [],
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
result = {
|
||||||
|
__typename: 'DuplicateName',
|
||||||
|
reason: 'Dieser Name wird bereits verwendet.'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
req.reply({
|
||||||
|
data: {
|
||||||
|
createTeam: {
|
||||||
|
result,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('Team', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
cy.setup();
|
||||||
|
cy.mockGraphqlOps({
|
||||||
|
operations: {
|
||||||
|
MeQuery: {
|
||||||
|
me: {
|
||||||
|
...teacher,
|
||||||
|
team: null,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('creates a new team', () => {
|
||||||
|
const name = 'Team Böhmi';
|
||||||
|
|
||||||
|
mockCreateTeamCall(name);
|
||||||
|
|
||||||
|
cy.visit('/me/team');
|
||||||
|
|
||||||
|
cy.getByDataCy('create-team-button').click();
|
||||||
|
cy.getByDataCy('join-form-input').type(name);
|
||||||
|
cy.getByDataCy('join-form-confirm').click();
|
||||||
|
|
||||||
|
cy.getByDataCy('group-list-name').should('contain', name);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('tries to create team but fails due to duplicate name', () => {
|
||||||
|
const name = 'Gibt\'s schon';
|
||||||
|
|
||||||
|
mockCreateTeamCall(false);
|
||||||
|
cy.visit('/me/team');
|
||||||
|
|
||||||
|
cy.getByDataCy('create-team-button').click();
|
||||||
|
cy.getByDataCy('join-form-input').type(name);
|
||||||
|
cy.getByDataCy('join-form-confirm').click();
|
||||||
|
|
||||||
|
cy.getByDataCy('join-form-input-error').should('contain', 'Dieser Name wird bereits verwendet.');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
title="Team erfassen"
|
title="Team erfassen"
|
||||||
ok-text="Team erfassen"
|
ok-text="Team erfassen"
|
||||||
label-text="Name"
|
label-text="Name"
|
||||||
|
:error="error"
|
||||||
cancel-text="Abbrechen"
|
cancel-text="Abbrechen"
|
||||||
@input="updateName"
|
@input="updateName"
|
||||||
@cancel="cancel"
|
@cancel="cancel"
|
||||||
|
|
@ -34,8 +35,6 @@
|
||||||
updateName(event) {
|
updateName(event) {
|
||||||
this.name = event.target.value;
|
this.name = event.target.value;
|
||||||
this.error = '';
|
this.error = '';
|
||||||
// todo: pass error to component
|
|
||||||
// throw new Error('NotImplemented');
|
|
||||||
},
|
},
|
||||||
createTeam(name) {
|
createTeam(name) {
|
||||||
this.$apollo.mutate({
|
this.$apollo.mutate({
|
||||||
|
|
@ -45,12 +44,16 @@
|
||||||
name,
|
name,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
update: (store, {data: {createTeam: {team}}}) => {
|
update: (store, {data: {createTeam: {result}}}) => {
|
||||||
addTeam(store, team);
|
if(result.__typename === 'DuplicateName') {
|
||||||
|
this.error = result.reason;
|
||||||
|
} else {
|
||||||
|
addTeam(store, result);
|
||||||
|
|
||||||
this.$router.push({
|
this.$router.push({
|
||||||
name: MY_TEAM,
|
name: MY_TEAM,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@
|
||||||
</h2>
|
</h2>
|
||||||
<router-link
|
<router-link
|
||||||
:to="createTeamRoute"
|
:to="createTeamRoute"
|
||||||
|
data-cy="create-team-button"
|
||||||
class="button button--primary"
|
class="button button--primary"
|
||||||
>
|
>
|
||||||
Team erfassen
|
Team erfassen
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue