Add new tests for module and chapter highlights
This commit is contained in:
parent
3887616ec7
commit
4ad5031803
|
|
@ -2,9 +2,12 @@ import { defaultModuleQueriesandMutations } from '../../../support/helpers';
|
||||||
|
|
||||||
const getModule = (contents) => {
|
const getModule = (contents) => {
|
||||||
return {
|
return {
|
||||||
|
intro: '<p>Introducing this great paragraph!</p>',
|
||||||
|
highlights: [],
|
||||||
chapters: [
|
chapters: [
|
||||||
{
|
{
|
||||||
title: 'A Chapter',
|
title: 'A Chapter',
|
||||||
|
description: 'This is something else',
|
||||||
contentBlocks: [
|
contentBlocks: [
|
||||||
{
|
{
|
||||||
title: 'A Content Block',
|
title: 'A Content Block',
|
||||||
|
|
@ -47,8 +50,39 @@ const contentListContents = [
|
||||||
const contentBlockId = window.btoa('ContentBlockNode:1');
|
const contentBlockId = window.btoa('ContentBlockNode:1');
|
||||||
const instrumentId = window.btoa('InstrumentNode:2');
|
const instrumentId = window.btoa('InstrumentNode:2');
|
||||||
const instrumentSlug = 'my-instrument';
|
const instrumentSlug = 'my-instrument';
|
||||||
|
const chapterId = window.btoa('ChapterNode:3');
|
||||||
|
const moduleId = window.btoa('ModuleNode:3');
|
||||||
|
const moduleSlug = 'my-module';
|
||||||
|
|
||||||
const getAddHighlight = (pageType: string = 'ContentBlockNode') => {
|
const getAddHighlight = (pageType: string = 'ModuleNode') => {
|
||||||
|
let page: { id: string; __typename: string; slug?: string };
|
||||||
|
if (pageType === 'ChapterNode') {
|
||||||
|
page = {
|
||||||
|
id: chapterId,
|
||||||
|
__typename: 'ChapterNode',
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
page = {
|
||||||
|
id: moduleId,
|
||||||
|
slug: moduleSlug,
|
||||||
|
__typename: 'ModuleNode',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return ({ input: { highlight } }) => {
|
||||||
|
lastHighlight = {
|
||||||
|
...highlight,
|
||||||
|
id: 'new-highlight-id',
|
||||||
|
page,
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
addHighlight: {
|
||||||
|
highlight: lastHighlight,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const getAddContentHighlight = (pageType: string = 'ContentBlockNode') => {
|
||||||
let page: { id: string; __typename: string; slug?: string };
|
let page: { id: string; __typename: string; slug?: string };
|
||||||
if (pageType === 'InstrumentNode') {
|
if (pageType === 'InstrumentNode') {
|
||||||
page = {
|
page = {
|
||||||
|
|
@ -70,7 +104,7 @@ const getAddHighlight = (pageType: string = 'ContentBlockNode') => {
|
||||||
page,
|
page,
|
||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
addHighlight: {
|
addContentHighlight: {
|
||||||
highlight: lastHighlight,
|
highlight: lastHighlight,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
@ -78,12 +112,19 @@ const getAddHighlight = (pageType: string = 'ContentBlockNode') => {
|
||||||
};
|
};
|
||||||
|
|
||||||
let lastHighlight;
|
let lastHighlight;
|
||||||
|
const defaultModule = getModule(defaultContents);
|
||||||
const operations = {
|
const operations = {
|
||||||
...defaultModuleQueriesandMutations,
|
...defaultModuleQueriesandMutations,
|
||||||
ModuleDetailsQuery: {
|
ModuleDetailsQuery: {
|
||||||
module: getModule(defaultContents),
|
module: defaultModule,
|
||||||
|
},
|
||||||
|
UpdateLastModule: {
|
||||||
|
updateLastModule: {
|
||||||
|
lastModule: defaultModule,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
AddHighlight: getAddHighlight(),
|
AddHighlight: getAddHighlight(),
|
||||||
|
AddContentHighlight: getAddContentHighlight(),
|
||||||
UpdateHighlight: ({ input: { note, color } }) => {
|
UpdateHighlight: ({ input: { note, color } }) => {
|
||||||
lastHighlight = {
|
lastHighlight = {
|
||||||
...lastHighlight,
|
...lastHighlight,
|
||||||
|
|
@ -110,11 +151,11 @@ const selectText = (elm: Node, start: number, end: number) => {
|
||||||
cy.window().then((win) => win.getSelection().addRange(range));
|
cy.window().then((win) => win.getSelection().addRange(range));
|
||||||
};
|
};
|
||||||
|
|
||||||
const markText = () => {
|
const markText = (dataCy = 'text-block') => {
|
||||||
/*
|
/*
|
||||||
* Mark the text (programmatically, as Cypress has no API for this)
|
* Mark the text (programmatically, as Cypress has no API for this)
|
||||||
*/
|
*/
|
||||||
cy.getByDataCy('text-block').then(($elm) => {
|
cy.getByDataCy(dataCy).then(($elm) => {
|
||||||
const textBlock = $elm[0];
|
const textBlock = $elm[0];
|
||||||
const paragraph = textBlock.querySelector('p');
|
const paragraph = textBlock.querySelector('p');
|
||||||
selectText(paragraph.childNodes[0], 2, 12);
|
selectText(paragraph.childNodes[0], 2, 12);
|
||||||
|
|
@ -136,12 +177,16 @@ const markText = () => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const createHighlight = (text) => {
|
const createHighlight = (text: string, content = false) => {
|
||||||
// delete doesn't make sense before the highlight exists
|
// delete doesn't make sense before the highlight exists
|
||||||
cy.getByDataCy('highlight-delete').should('not.exist');
|
cy.getByDataCy('highlight-delete').should('not.exist');
|
||||||
// mark the text with yellow and check the text
|
// mark the text with yellow and check the text
|
||||||
cy.getByDataCy('highlight-alpha').click();
|
cy.getByDataCy('highlight-alpha').click();
|
||||||
cy.wait('@AddHighlight');
|
if (content) {
|
||||||
|
cy.wait('@AddContentHighlight');
|
||||||
|
} else {
|
||||||
|
cy.wait('@AddHighlight');
|
||||||
|
}
|
||||||
cy.getByDataCy('highlight-mark').should('contain', text);
|
cy.getByDataCy('highlight-mark').should('contain', text);
|
||||||
|
|
||||||
// we only want to have one of each element and not accidentally create multiple
|
// we only want to have one of each element and not accidentally create multiple
|
||||||
|
|
@ -211,7 +256,7 @@ describe('Highlights', () => {
|
||||||
markText();
|
markText();
|
||||||
|
|
||||||
const highlightedText = 'es ist ein';
|
const highlightedText = 'es ist ein';
|
||||||
createHighlight(highlightedText);
|
createHighlight(highlightedText, true);
|
||||||
updateHighlight(highlightedText);
|
updateHighlight(highlightedText);
|
||||||
|
|
||||||
openSidebar(highlightedText);
|
openSidebar(highlightedText);
|
||||||
|
|
@ -264,7 +309,7 @@ describe('Highlights', () => {
|
||||||
|
|
||||||
markText();
|
markText();
|
||||||
cy.getByDataCy('highlight-note').click();
|
cy.getByDataCy('highlight-note').click();
|
||||||
cy.wait('@AddHighlight');
|
cy.wait('@AddContentHighlight');
|
||||||
|
|
||||||
addNote();
|
addNote();
|
||||||
});
|
});
|
||||||
|
|
@ -278,6 +323,39 @@ describe('Highlights', () => {
|
||||||
markText();
|
markText();
|
||||||
const highlightedText = 'es ist ein';
|
const highlightedText = 'es ist ein';
|
||||||
|
|
||||||
|
// delete doesn't make sense before the highlight exists
|
||||||
|
cy.getByDataCy('highlight-delete').should('not.exist');
|
||||||
|
openSidebar(highlightedText);
|
||||||
|
cy.wait('@AddContentHighlight');
|
||||||
|
updateHighlight(highlightedText);
|
||||||
|
cy.getByDataCy('highlight-mark').should('have.length', 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it.skip('visits a module and highlights the chapter description', () => {
|
||||||
|
cy.mockGraphqlOps({
|
||||||
|
operations,
|
||||||
|
});
|
||||||
|
cy.visit('/module/my-module');
|
||||||
|
|
||||||
|
markText('chapter-intro');
|
||||||
|
const highlightedText = 'is is somet';
|
||||||
|
|
||||||
|
// delete doesn't make sense before the highlight exists
|
||||||
|
cy.getByDataCy('highlight-delete').should('not.exist');
|
||||||
|
openSidebar(highlightedText);
|
||||||
|
cy.wait('@AddHighlight');
|
||||||
|
updateHighlight(highlightedText);
|
||||||
|
cy.getByDataCy('highlight-mark').should('have.length', 1);
|
||||||
|
});
|
||||||
|
it('visits a module and highlights the module description', () => {
|
||||||
|
cy.mockGraphqlOps({
|
||||||
|
operations,
|
||||||
|
});
|
||||||
|
cy.visit('/module/my-module');
|
||||||
|
|
||||||
|
markText('module-intro');
|
||||||
|
const highlightedText = 'troducing';
|
||||||
|
|
||||||
// delete doesn't make sense before the highlight exists
|
// delete doesn't make sense before the highlight exists
|
||||||
cy.getByDataCy('highlight-delete').should('not.exist');
|
cy.getByDataCy('highlight-delete').should('not.exist');
|
||||||
openSidebar(highlightedText);
|
openSidebar(highlightedText);
|
||||||
|
|
@ -290,7 +368,7 @@ describe('Highlights', () => {
|
||||||
cy.mockGraphqlOps({
|
cy.mockGraphqlOps({
|
||||||
operations: {
|
operations: {
|
||||||
...operations,
|
...operations,
|
||||||
AddHighlight: getAddHighlight('InstrumentNode'),
|
AddContentHighlight: getAddContentHighlight('InstrumentNode'),
|
||||||
InstrumentQuery: {
|
InstrumentQuery: {
|
||||||
instrument: {
|
instrument: {
|
||||||
title: 'My Instrument',
|
title: 'My Instrument',
|
||||||
|
|
@ -314,7 +392,7 @@ describe('Highlights', () => {
|
||||||
cy.wait('@InstrumentQuery');
|
cy.wait('@InstrumentQuery');
|
||||||
markText();
|
markText();
|
||||||
const highlightedText = 'llo my bea';
|
const highlightedText = 'llo my bea';
|
||||||
createHighlight(highlightedText);
|
createHighlight(highlightedText, true);
|
||||||
updateHighlight(highlightedText);
|
updateHighlight(highlightedText);
|
||||||
addNote();
|
addNote();
|
||||||
deleteHighlight();
|
deleteHighlight();
|
||||||
|
|
@ -324,7 +402,7 @@ describe('Highlights', () => {
|
||||||
cy.mockGraphqlOps({
|
cy.mockGraphqlOps({
|
||||||
operations: {
|
operations: {
|
||||||
...operations,
|
...operations,
|
||||||
AddHighlight: getAddHighlight('InstrumentNode'),
|
AddContentHighlight: getAddContentHighlight('InstrumentNode'),
|
||||||
InstrumentQuery: {
|
InstrumentQuery: {
|
||||||
instrument: {
|
instrument: {
|
||||||
title: 'My Instrument',
|
title: 'My Instrument',
|
||||||
|
|
@ -349,7 +427,7 @@ describe('Highlights', () => {
|
||||||
markText();
|
markText();
|
||||||
const highlightedText = 'llo my bea';
|
const highlightedText = 'llo my bea';
|
||||||
openSidebar(highlightedText);
|
openSidebar(highlightedText);
|
||||||
cy.wait('@AddHighlight');
|
cy.wait('@AddContentHighlight');
|
||||||
updateHighlight(highlightedText);
|
updateHighlight(highlightedText);
|
||||||
deleteHighlight();
|
deleteHighlight();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -88,9 +88,11 @@ export default {
|
||||||
slug: 'some-slug',
|
slug: 'some-slug',
|
||||||
metaTitle: 'Meta Title',
|
metaTitle: 'Meta Title',
|
||||||
heroImage: '',
|
heroImage: '',
|
||||||
|
heroSource: '',
|
||||||
teaser: '',
|
teaser: '',
|
||||||
intro: '',
|
intro: '',
|
||||||
assignments: [],
|
assignments: [],
|
||||||
|
highlights: [],
|
||||||
objectiveGroups: [],
|
objectiveGroups: [],
|
||||||
id: getModuleId(),
|
id: getModuleId(),
|
||||||
bookmark: null,
|
bookmark: null,
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@
|
||||||
<div
|
<div
|
||||||
:class="{ 'hideable-element--greyed-out': descriptionGreyedOut }"
|
:class="{ 'hideable-element--greyed-out': descriptionGreyedOut }"
|
||||||
class="chapter__intro intro hideable-element"
|
class="chapter__intro intro hideable-element"
|
||||||
|
data-cy="chapter-intro"
|
||||||
v-if="!descriptionHidden"
|
v-if="!descriptionHidden"
|
||||||
>
|
>
|
||||||
<visibility-action
|
<visibility-action
|
||||||
|
|
@ -46,7 +47,10 @@
|
||||||
type="chapter-description"
|
type="chapter-description"
|
||||||
v-if="editMode"
|
v-if="editMode"
|
||||||
/>
|
/>
|
||||||
<p class="chapter__description">
|
<p
|
||||||
|
data-cy="chapter-description"
|
||||||
|
class="chapter__description"
|
||||||
|
>
|
||||||
{{ chapter.description }}
|
{{ chapter.description }}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue