Add new cypress test for changing class in room view

This commit is contained in:
Ramon Wenger 2021-09-01 14:27:57 +02:00
parent 1a3d9afd31
commit 704da5a749
7 changed files with 118 additions and 74 deletions

View File

@ -1,4 +1,5 @@
import { GraphQLError } from 'graphql'; import { GraphQLError } from 'graphql';
import {assertStartPage} from '../../../support/helpers';
const schema = require('../../../fixtures/schema.json'); const schema = require('../../../fixtures/schema.json');
@ -30,7 +31,7 @@ describe('Email Verification', () => {
cy.visit('/license-activation'); cy.visit('/license-activation');
redeemCoupon('12345asfd'); redeemCoupon('12345asfd');
cy.assertStartPage(); assertStartPage();
}); });
it('displays error if input is missing', () => { it('displays error if input is missing', () => {

View File

@ -1,6 +1,4 @@
import {mockUpdateOnboardingProgress} from '../../support/helpers'; import {assertStartPage} from '../../support/helpers';
const me = require('../../fixtures/me.join-class.json');
describe('Onboarding', () => { describe('Onboarding', () => {
beforeEach(() => { beforeEach(() => {
@ -29,12 +27,12 @@ describe('Onboarding', () => {
}); });
cy.visit('/'); cy.visit('/');
cy.assertStartPage(true); assertStartPage(true);
cy.get('[data-cy=onboarding-next-link]').click(); cy.get('[data-cy=onboarding-next-link]').click();
cy.get('[data-cy=onboarding-next-link]').click(); cy.get('[data-cy=onboarding-next-link]').click();
cy.get('[data-cy=onboarding-next-link]').click(); cy.get('[data-cy=onboarding-next-link]').click();
cy.get('[data-cy=onboarding-next-link]').click(); cy.get('[data-cy=onboarding-next-link]').click();
cy.assertStartPage(false); assertStartPage(false);
}); });
it('shows the onboarding steps and skips them', () => { it('shows the onboarding steps and skips them', () => {
@ -58,9 +56,9 @@ describe('Onboarding', () => {
}); });
cy.visit('/'); cy.visit('/');
cy.assertStartPage(true); assertStartPage(true);
cy.getByDataCy('onboarding-skip-link').click(); cy.getByDataCy('onboarding-skip-link').click();
cy.assertStartPage(false); assertStartPage(false);
}); });
it('does not show the onboarding', () => { it('does not show the onboarding', () => {
@ -73,6 +71,6 @@ describe('Onboarding', () => {
}); });
cy.visit('/'); cy.visit('/');
cy.assertStartPage(false); assertStartPage(false);
}); });
}); });

View File

@ -1,6 +1,8 @@
import {getMinimalMe} from '../../../support/helpers'; import {getMinimalMe} from '../../../support/helpers';
describe('The Room Page', () => { describe('The Room Page', () => {
const MeQuery = getMinimalMe();
const selectedClass = MeQuery.me.selectedClass;
const entryText = 'something should be here'; const entryText = 'something should be here';
const entryTitle = 'some title'; const entryTitle = 'some title';
const slug = 'ein-historisches-festival'; const slug = 'ein-historisches-festival';
@ -8,6 +10,7 @@ describe('The Room Page', () => {
const room = { const room = {
id, id,
slug, slug,
schoolClass: selectedClass,
restricted: false, restricted: false,
roomEntries: { roomEntries: {
edges: [], edges: [],
@ -19,7 +22,7 @@ describe('The Room Page', () => {
}; };
const operations = { const operations = {
MeQuery: getMinimalMe({}), MeQuery,
RoomEntriesQuery, RoomEntriesQuery,
AddRoomEntry: { AddRoomEntry: {
addRoomEntry: { addRoomEntry: {
@ -136,11 +139,11 @@ describe('The Room Page', () => {
const roomToDelete = { const roomToDelete = {
id: 'room-to-delete', id: 'room-to-delete',
roomEntries: { roomEntries: {
edges: [] edges: [],
} },
}; };
const otherRoom = { const otherRoom = {
id: 'otherRoom' id: 'otherRoom',
}; };
let rooms = [roomToDelete, otherRoom]; let rooms = [roomToDelete, otherRoom];
const operations = { const operations = {
@ -148,21 +151,21 @@ describe('The Room Page', () => {
RoomsQuery() { RoomsQuery() {
return { return {
rooms: { rooms: {
edges: rooms.map(room => ({node: room})) edges: rooms.map(room => ({node: room})),
} },
}; };
}, },
RoomEntriesQuery: { RoomEntriesQuery: {
room: roomToDelete room: roomToDelete,
}, },
DeleteRoom: { DeleteRoom: {
deleteRoom: { deleteRoom: {
success: true success: true,
} },
} },
}; };
cy.mockGraphqlOps({ cy.mockGraphqlOps({
operations operations,
}); });
cy.visit(`/rooms`); cy.visit(`/rooms`);
@ -190,22 +193,22 @@ describe('The Room Page', () => {
contents: [], contents: [],
author: { author: {
...me, ...me,
id: authorId id: authorId,
} },
} },
} },
] ],
} },
}; };
const operations = { const operations = {
MeQuery: MeQuery, MeQuery: MeQuery,
RoomEntriesQuery: { RoomEntriesQuery: {
room room,
}, },
RoomEntryQuery: {} RoomEntryQuery: {},
}; };
cy.mockGraphqlOps({ cy.mockGraphqlOps({
operations operations,
}); });
cy.visit(`/room/${slug}`); cy.visit(`/room/${slug}`);
cy.getByDataCy('room-entry-actions').click(); cy.getByDataCy('room-entry-actions').click();
@ -217,22 +220,58 @@ describe('The Room Page', () => {
const room = { const room = {
id: 'some-room', id: 'some-room',
roomEntries: { roomEntries: {
edges: [] edges: [],
} },
}; };
const operations = { const operations = {
MeQuery, MeQuery,
RoomEntriesQuery: { RoomEntriesQuery: {
room room,
}, },
}; };
cy.mockGraphqlOps({ cy.mockGraphqlOps({
operations operations,
}); });
cy.visit(`/room/${slug}`); cy.visit(`/room/${slug}`);
cy.getByDataCy('add-room-entry-button').click(); cy.getByDataCy('add-room-entry-button').click();
cy.getByDataCy('add-room-entry-modal').should('exist'); cy.getByDataCy('add-room-entry-modal').should('exist');
}); });
it.only('changes class while on room page', () => {
const {me} = MeQuery;
const operations = {
MeQuery: {
me: {
...me,
schoolClasses: {
edges: [
...me.schoolClasses.edges,
{
node: {
id: btoa('SchoolClassNode:other-class'),
name: 'Other Class'
},
},
],
},
},
},
RoomEntriesQuery,
UpdateSettings: {
updateSettings: {
success: true
}
}
};
cy.mockGraphqlOps({
operations,
});
cy.visit(`/room/${slug}`);
cy.getByDataCy('room-title').should('contain', 'A Room');
cy.selectClass('Other Class');
cy.url().should('include', 'rooms');
});
}); });

View File

@ -1,4 +1,3 @@
import {mockUpdateLastModule} from '../../support/helpers';
import module from '../../fixtures/module.minimal'; import module from '../../fixtures/module.minimal';
const spellCheck = require('../../fixtures/spell-check.json'); const spellCheck = require('../../fixtures/spell-check.json');
@ -126,7 +125,11 @@ const operations = {
}, },
}, },
}, },
...mockUpdateLastModule(), UpdateLastModule: {
updateLastModule: {
lastModule: {},
},
},
}; };
describe('Spellcheck', () => { describe('Spellcheck', () => {

View File

@ -119,14 +119,6 @@ Cypress.Commands.add('enterPassword', (password) => {
cy.get('[data-cy="login-button"]').click(); cy.get('[data-cy="login-button"]').click();
}); });
Cypress.Commands.add('assertStartPage', (onboarding) => {
if (onboarding) {
cy.get('[data-cy=onboarding-page]').should('exist');
} else {
cy.get('[data-cy=start-modules-list]').should('exist');
}
});
Cypress.Commands.add('getByDataCy', (selector) => { Cypress.Commands.add('getByDataCy', (selector) => {
return cy.get(`[data-cy=${selector}]`); return cy.get(`[data-cy=${selector}]`);
}); });

View File

@ -1,16 +1,25 @@
// todo: clean up this file // todo: clean up this file
export const getMinimalMe = ({readOnly = false, classReadOnly = false, isTeacher = true} = {}) => ({ export const getMinimalMe = ({readOnly = false, classReadOnly = false, isTeacher = true} = {}) => {
me: { const selectedClass = {
id: btoa('PrivateUserNode:1'), name: 'Selected Class',
readOnly, id: btoa('SchoolClassNode:selectedClassId'),
isTeacher, readOnly: classReadOnly,
selectedClass: { };
id: 'selectedClassId', return {
readOnly: classReadOnly, me: {
id: btoa('PrivateUserNode:1'),
readOnly,
isTeacher,
selectedClass,
schoolClasses: {
edges: [
{node: selectedClass},
],
},
}, },
}, };
}); };
const getSchoolClassNode = (id, schoolClassName) => ({ const getSchoolClassNode = (id, schoolClassName) => ({
'id': btoa(`SchoolClassNode:${id}`), 'id': btoa(`SchoolClassNode:${id}`),
@ -18,6 +27,14 @@ const getSchoolClassNode = (id, schoolClassName) => ({
'__typename': 'SchoolClassNode', '__typename': 'SchoolClassNode',
}); });
export const assertStartPage = (onboarding) => {
if (onboarding) {
cy.get('[data-cy=onboarding-page]').should('exist');
} else {
cy.get('[data-cy=start-modules-list]').should('exist');
}
};
export const getMe = ({schoolClasses, teacher}) => { export const getMe = ({schoolClasses, teacher}) => {
let schoolClassNodes; let schoolClassNodes;
if (schoolClasses) { if (schoolClasses) {
@ -329,23 +346,3 @@ export const getModules = () => {
}, },
}; };
}; };
export const mockUpdateOnboardingProgress = () => {
return {
UpdateOnboardingProgress: {
updateOnboardingProgress: {
success: true,
},
},
};
};
export const mockUpdateLastModule = () => {
return {
UpdateLastModule: {
updateLastModule: {
lastModule: {},
},
},
};
};

View File

@ -50,6 +50,7 @@
import me from '@/mixins/me'; import me from '@/mixins/me';
import BackLink from '@/components/BackLink'; import BackLink from '@/components/BackLink';
import RoomVisibilityWidget from '@/components/rooms/RoomVisibilityWidget'; import RoomVisibilityWidget from '@/components/rooms/RoomVisibilityWidget';
import {ROOMS_PAGE} from '@/router/room.names';
export default { export default {
props: ['slug'], props: ['slug'],
@ -62,7 +63,20 @@
}, },
isReadOnly() { isReadOnly() {
return this.me.readOnly || this.me.selectedClass.readOnly; return this.me.readOnly || this.me.selectedClass.readOnly;
} },
},
mounted() {
this.$watch(
'me.selectedClass.id',
(newValue, _) => {
if (this.room.schoolClass.id !== newValue) {
this.$router.push({
name: ROOMS_PAGE,
});
}
},
);
}, },
apollo: { apollo: {