Add new test for instrument page and add onNote function
This commit is contained in:
parent
848a4764d2
commit
ebe7be43cb
|
|
@ -160,12 +160,12 @@ const updateHighlight = (text) => {
|
||||||
cy.getByDataCy('highlight-mark').should('have.length', 1);
|
cy.getByDataCy('highlight-mark').should('have.length', 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
const openSidebar = () => {
|
const openSidebar = (text) => {
|
||||||
// display the sidebar and popover and check them
|
// display the sidebar and popover and check them
|
||||||
cy.getByDataCy('highlight-note').click();
|
cy.getByDataCy('highlight-note').click();
|
||||||
cy.getByDataCy('highlight-popover').should('be.visible');
|
cy.getByDataCy('highlight-popover').should('be.visible');
|
||||||
cy.getByDataCy('highlight-sidebar').should('be.visible');
|
cy.getByDataCy('highlight-sidebar').should('be.visible');
|
||||||
cy.getByDataCy('highlight-in-sidebar').should('contain', 'es ist ein');
|
cy.getByDataCy('highlight-in-sidebar').should('contain', text);
|
||||||
|
|
||||||
cy.getByDataCy('highlight-popover').should('have.length', 1); // there should only be one popover
|
cy.getByDataCy('highlight-popover').should('have.length', 1); // there should only be one popover
|
||||||
cy.getByDataCy('highlight-mark').should('have.length', 1);
|
cy.getByDataCy('highlight-mark').should('have.length', 1);
|
||||||
|
|
@ -214,7 +214,7 @@ describe('Highlights', () => {
|
||||||
createHighlight(highlightedText);
|
createHighlight(highlightedText);
|
||||||
updateHighlight(highlightedText);
|
updateHighlight(highlightedText);
|
||||||
|
|
||||||
openSidebar();
|
openSidebar(highlightedText);
|
||||||
|
|
||||||
// click outside the created components to make them disappear
|
// click outside the created components to make them disappear
|
||||||
cy.getByDataCy('module-title').click();
|
cy.getByDataCy('module-title').click();
|
||||||
|
|
@ -276,17 +276,17 @@ describe('Highlights', () => {
|
||||||
cy.visit('/module/my-module');
|
cy.visit('/module/my-module');
|
||||||
|
|
||||||
markText();
|
markText();
|
||||||
|
const highlightedText = 'es ist ein';
|
||||||
|
|
||||||
// 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();
|
openSidebar(highlightedText);
|
||||||
cy.wait('@AddHighlight');
|
cy.wait('@AddHighlight');
|
||||||
const highlightedText = 'es ist ein';
|
|
||||||
updateHighlight(highlightedText);
|
updateHighlight(highlightedText);
|
||||||
cy.getByDataCy('highlight-mark').should('have.length', 1);
|
cy.getByDataCy('highlight-mark').should('have.length', 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it.only('visits an instrument and highlights some text', () => {
|
it('visits an instrument and highlights some text', () => {
|
||||||
cy.mockGraphqlOps({
|
cy.mockGraphqlOps({
|
||||||
operations: {
|
operations: {
|
||||||
...operations,
|
...operations,
|
||||||
|
|
@ -319,4 +319,38 @@ describe('Highlights', () => {
|
||||||
addNote();
|
addNote();
|
||||||
deleteHighlight();
|
deleteHighlight();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('visits an instrument and writes a note', () => {
|
||||||
|
cy.mockGraphqlOps({
|
||||||
|
operations: {
|
||||||
|
...operations,
|
||||||
|
AddHighlight: getAddHighlight('InstrumentNode'),
|
||||||
|
InstrumentQuery: {
|
||||||
|
instrument: {
|
||||||
|
title: 'My Instrument',
|
||||||
|
id: instrumentId,
|
||||||
|
slug: instrumentSlug,
|
||||||
|
highlights: [],
|
||||||
|
contents: [
|
||||||
|
{
|
||||||
|
type: 'text_block',
|
||||||
|
id: 'some-other-content-component-id',
|
||||||
|
value: {
|
||||||
|
text: '<p>Hello my beautiful World!</p>',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
cy.visit(`/instrument/${instrumentSlug}`);
|
||||||
|
cy.wait('@InstrumentQuery');
|
||||||
|
markText();
|
||||||
|
const highlightedText = 'llo my bea';
|
||||||
|
openSidebar(highlightedText);
|
||||||
|
cy.wait('@AddHighlight');
|
||||||
|
updateHighlight(highlightedText);
|
||||||
|
deleteHighlight();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,8 @@ import { useQuery } from '@vue/apollo-composable';
|
||||||
import { computed } from '@vue/reactivity';
|
import { computed } from '@vue/reactivity';
|
||||||
import { AddHighlightArgument, InstrumentNode } from '@/__generated__/graphql';
|
import { AddHighlightArgument, InstrumentNode } from '@/__generated__/graphql';
|
||||||
import { getSelectionHandler, replacePopover, SelectionHandlerOptions } from '@/helpers/highlight';
|
import { getSelectionHandler, replacePopover, SelectionHandlerOptions } from '@/helpers/highlight';
|
||||||
import { doCreateHighlight } from '@/graphql/mutations';
|
import { doCreateHighlight, doUpdateHighlight } from '@/graphql/mutations';
|
||||||
|
import highlightSidebar from '@/helpers/highlight-sidebar';
|
||||||
|
|
||||||
const instrumentDiv = ref<HTMLElement | null>(null);
|
const instrumentDiv = ref<HTMLElement | null>(null);
|
||||||
|
|
||||||
|
|
@ -107,7 +108,7 @@ const instrumentHighlightsFragment = graphql(`
|
||||||
|
|
||||||
// todo: merge with other createHighlight function over in ContentBlock.vue
|
// todo: merge with other createHighlight function over in ContentBlock.vue
|
||||||
const createHighlight = (highlight: AddHighlightArgument) => {
|
const createHighlight = (highlight: AddHighlightArgument) => {
|
||||||
doCreateHighlight(
|
return doCreateHighlight(
|
||||||
{
|
{
|
||||||
input: {
|
input: {
|
||||||
highlight,
|
highlight,
|
||||||
|
|
@ -163,6 +164,23 @@ onResult(() => {
|
||||||
onChangeColor: (newHighlight: AddHighlightArgument) => {
|
onChangeColor: (newHighlight: AddHighlightArgument) => {
|
||||||
createHighlight(newHighlight);
|
createHighlight(newHighlight);
|
||||||
},
|
},
|
||||||
|
onCreateNote: (newHighlight: AddHighlightArgument) => {
|
||||||
|
// todo: the same as the other one in ContentBlock.vue, possible to merge
|
||||||
|
// we also open the sidebar when clicking on the note icon
|
||||||
|
createHighlight(newHighlight).then((highlight) => {
|
||||||
|
highlightSidebar.open({
|
||||||
|
highlight,
|
||||||
|
onUpdateText: (text: string) => {
|
||||||
|
doUpdateHighlight({
|
||||||
|
input: {
|
||||||
|
note: text,
|
||||||
|
id: highlight.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
};
|
};
|
||||||
selectionHandler = getSelectionHandler(options);
|
selectionHandler = getSelectionHandler(options);
|
||||||
element.addEventListener('mouseup', selectionHandler);
|
element.addEventListener('mouseup', selectionHandler);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue