Add test for deleting room entries, refactor test file
This commit is contained in:
parent
f2f7d30959
commit
35b0094670
|
|
@ -1,6 +1,6 @@
|
||||||
import {getMinimalMe} from '../../../support/helpers';
|
import {getMinimalMe} from '../../../support/helpers';
|
||||||
|
|
||||||
describe('The Room Page', () => {
|
describe('The Room Page (Teacher)', () => {
|
||||||
const MeQuery = getMinimalMe();
|
const MeQuery = getMinimalMe();
|
||||||
const selectedClass = MeQuery.me.selectedClass;
|
const selectedClass = MeQuery.me.selectedClass;
|
||||||
const entryText = 'something should be here';
|
const entryText = 'something should be here';
|
||||||
|
|
@ -72,21 +72,6 @@ describe('The Room Page', () => {
|
||||||
cy.get('.room-entry__content:first').should('contain', entryText).should('contain', 'Rachel Green');
|
cy.get('.room-entry__content:first').should('contain', entryText).should('contain', 'Rachel Green');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('room actions should not exist for student', () => {
|
|
||||||
const operations = {
|
|
||||||
MeQuery: getMinimalMe({isTeacher: false}),
|
|
||||||
RoomEntriesQuery,
|
|
||||||
};
|
|
||||||
|
|
||||||
cy.mockGraphqlOps({
|
|
||||||
operations,
|
|
||||||
});
|
|
||||||
cy.visit(`/room/${slug}`);
|
|
||||||
|
|
||||||
cy.getByDataCy('room-title').should('exist');
|
|
||||||
cy.getByDataCy('room-actions').should('not.exist');
|
|
||||||
});
|
|
||||||
|
|
||||||
// todo: re-enable once cypress can do it correctly
|
// todo: re-enable once cypress can do it correctly
|
||||||
it.skip('changes visibility of a room', () => {
|
it.skip('changes visibility of a room', () => {
|
||||||
const MeQuery = getMinimalMe({
|
const MeQuery = getMinimalMe({
|
||||||
|
|
@ -184,88 +169,6 @@ describe('The Room Page', () => {
|
||||||
cy.getByDataCy('room-widget').should('have.length', 1);
|
cy.getByDataCy('room-widget').should('have.length', 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('edits own room entry', () => {
|
|
||||||
const MeQuery = getMinimalMe({isTeacher: false});
|
|
||||||
const {me} = MeQuery;
|
|
||||||
const id = atob(me.id).split(':')[1];
|
|
||||||
const authorId = btoa(`PublicUserNode:${id}`);
|
|
||||||
const entrySlug = 'entry-slug';
|
|
||||||
const roomEntry = {
|
|
||||||
id: 'entry-id',
|
|
||||||
slug: entrySlug,
|
|
||||||
title: 'My Entry',
|
|
||||||
contents: [
|
|
||||||
{
|
|
||||||
type: 'text_block',
|
|
||||||
value: {
|
|
||||||
text: 'some text'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
comments: [],
|
|
||||||
author: {
|
|
||||||
...me,
|
|
||||||
id: authorId,
|
|
||||||
firstName: 'Hans',
|
|
||||||
lastName: 'Was Heiri',
|
|
||||||
avatarUrl: ''
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const room = {
|
|
||||||
id: 'some-room',
|
|
||||||
slug,
|
|
||||||
// schoolClass: me.selectedClass,
|
|
||||||
roomEntries: {
|
|
||||||
edges: [
|
|
||||||
{
|
|
||||||
node: roomEntry,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const operations = {
|
|
||||||
MeQuery: MeQuery,
|
|
||||||
RoomEntriesQuery: {
|
|
||||||
room,
|
|
||||||
},
|
|
||||||
RoomEntryQuery: {
|
|
||||||
roomEntry
|
|
||||||
},
|
|
||||||
};
|
|
||||||
cy.mockGraphqlOps({
|
|
||||||
operations,
|
|
||||||
});
|
|
||||||
cy.visit(`/room/${slug}`);
|
|
||||||
cy.getByDataCy('room-entry-actions').click();
|
|
||||||
cy.getByDataCy('edit-room-entry').click();
|
|
||||||
cy.location('pathname').should('include', entrySlug);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('creates a room entry', () => {
|
|
||||||
const MeQuery = getMinimalMe({isTeacher: false});
|
|
||||||
const room = {
|
|
||||||
id: 'some-room',
|
|
||||||
roomEntries: {
|
|
||||||
edges: [],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const operations = {
|
|
||||||
MeQuery,
|
|
||||||
RoomEntriesQuery: {
|
|
||||||
room,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
cy.mockGraphqlOps({
|
|
||||||
operations,
|
|
||||||
});
|
|
||||||
|
|
||||||
cy.visit(`/room/${slug}`);
|
|
||||||
cy.getByDataCy('add-room-entry-button').click();
|
|
||||||
|
|
||||||
cy.getByDataCy('content-form-section-title').should('have.text', 'Titel (Pflichtfeld)');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('changes class while on room page', () => {
|
it('changes class while on room page', () => {
|
||||||
const {me} = MeQuery;
|
const {me} = MeQuery;
|
||||||
const otherClass = {
|
const otherClass = {
|
||||||
|
|
@ -316,3 +219,186 @@ describe('The Room Page', () => {
|
||||||
cy.getByDataCy('current-class-name').should('contain', 'Other Class');
|
cy.getByDataCy('current-class-name').should('contain', 'Other Class');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('The Room Page (student)', () => {
|
||||||
|
const slug = 'ein-historisches-festival';
|
||||||
|
const MeQuery = getMinimalMe({isTeacher: false});
|
||||||
|
const {me} = MeQuery;
|
||||||
|
const id = atob(me.id).split(':')[1];
|
||||||
|
const authorId = btoa(`PublicUserNode:${id}`);
|
||||||
|
const entrySlug = 'entry-slug';
|
||||||
|
const {selectedClass} = me;
|
||||||
|
const room = {
|
||||||
|
id,
|
||||||
|
slug,
|
||||||
|
schoolClass: selectedClass,
|
||||||
|
restricted: false,
|
||||||
|
roomEntries: {
|
||||||
|
edges: [],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const RoomEntriesQuery = {
|
||||||
|
room,
|
||||||
|
};
|
||||||
|
const roomEntry = {
|
||||||
|
id: 'entry-id',
|
||||||
|
slug: entrySlug,
|
||||||
|
title: 'My Entry',
|
||||||
|
contents: [
|
||||||
|
{
|
||||||
|
type: 'text_block',
|
||||||
|
value: {
|
||||||
|
text: 'some text'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
comments: [],
|
||||||
|
author: {
|
||||||
|
...me,
|
||||||
|
id: authorId,
|
||||||
|
firstName: 'Hans',
|
||||||
|
lastName: 'Was Heiri',
|
||||||
|
avatarUrl: ''
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
cy.setup();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('room actions should not exist for student', () => {
|
||||||
|
const operations = {
|
||||||
|
MeQuery: getMinimalMe({isTeacher: false}),
|
||||||
|
RoomEntriesQuery,
|
||||||
|
};
|
||||||
|
|
||||||
|
cy.mockGraphqlOps({
|
||||||
|
operations,
|
||||||
|
});
|
||||||
|
cy.visit(`/room/${slug}`);
|
||||||
|
|
||||||
|
cy.getByDataCy('room-title').should('exist');
|
||||||
|
cy.getByDataCy('room-actions').should('not.exist');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('creates a room entry', () => {
|
||||||
|
const MeQuery = getMinimalMe({isTeacher: false});
|
||||||
|
const room = {
|
||||||
|
id: 'some-room',
|
||||||
|
roomEntries: {
|
||||||
|
edges: [],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const operations = {
|
||||||
|
MeQuery,
|
||||||
|
RoomEntriesQuery: {
|
||||||
|
room,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
cy.mockGraphqlOps({
|
||||||
|
operations,
|
||||||
|
});
|
||||||
|
|
||||||
|
cy.visit(`/room/${slug}`);
|
||||||
|
cy.getByDataCy('add-room-entry-button').click();
|
||||||
|
|
||||||
|
cy.getByDataCy('content-form-section-title').should('have.text', 'Titel (Pflichtfeld)');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('edits own room entry', () => {
|
||||||
|
const room = {
|
||||||
|
id: 'some-room',
|
||||||
|
slug,
|
||||||
|
// schoolClass: me.selectedClass,
|
||||||
|
roomEntries: {
|
||||||
|
edges: [
|
||||||
|
{
|
||||||
|
node: roomEntry,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const operations = {
|
||||||
|
MeQuery: MeQuery,
|
||||||
|
RoomEntriesQuery: {
|
||||||
|
room,
|
||||||
|
},
|
||||||
|
RoomEntryQuery: {
|
||||||
|
roomEntry
|
||||||
|
},
|
||||||
|
};
|
||||||
|
cy.mockGraphqlOps({
|
||||||
|
operations,
|
||||||
|
});
|
||||||
|
cy.visit(`/room/${slug}`);
|
||||||
|
cy.getByDataCy('room-entry-actions').click();
|
||||||
|
cy.getByDataCy('edit-room-entry').click();
|
||||||
|
cy.location('pathname').should('include', entrySlug);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Deletes room entry', () => {
|
||||||
|
const MeQuery = getMinimalMe({isTeacher: false});
|
||||||
|
const {me} = MeQuery;
|
||||||
|
const authorId = btoa(`PublicUserNode:${id}`);
|
||||||
|
const entrySlug = 'entry-slug';
|
||||||
|
const roomEntry = {
|
||||||
|
id: 'entry-id',
|
||||||
|
slug: entrySlug,
|
||||||
|
title: 'My Entry',
|
||||||
|
contents: [
|
||||||
|
{
|
||||||
|
type: 'text_block',
|
||||||
|
value: {
|
||||||
|
text: 'some text'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
comments: [],
|
||||||
|
author: {
|
||||||
|
...me,
|
||||||
|
id: authorId,
|
||||||
|
firstName: 'Hans',
|
||||||
|
lastName: 'Was Heiri',
|
||||||
|
avatarUrl: ''
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const room = {
|
||||||
|
id: 'some-room',
|
||||||
|
slug,
|
||||||
|
roomEntries: {
|
||||||
|
edges: [{
|
||||||
|
node: roomEntry
|
||||||
|
}],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const DeleteRoomEntry = {
|
||||||
|
deleteRoomEntry: {
|
||||||
|
success: true,
|
||||||
|
errors: null,
|
||||||
|
roomSlug: slug
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const operations = {
|
||||||
|
MeQuery,
|
||||||
|
RoomEntriesQuery: {
|
||||||
|
room,
|
||||||
|
},
|
||||||
|
DeleteRoomEntry
|
||||||
|
};
|
||||||
|
|
||||||
|
cy.mockGraphqlOps({
|
||||||
|
operations,
|
||||||
|
});
|
||||||
|
|
||||||
|
cy.visit(`/room/${slug}`);
|
||||||
|
cy.getByDataCy('room-entry').should('have.length', 1);
|
||||||
|
cy.getByDataCy('room-entry-actions').click();
|
||||||
|
cy.getByDataCy('delete-room-entry').click();
|
||||||
|
cy.getByDataCy('room-entry').should('have.length', 0);
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue