diff --git a/client/cypress/e2e/frontend/modules/highlights.cy.ts b/client/cypress/e2e/frontend/modules/highlights.cy.ts index 510d97d2..106553ea 100644 --- a/client/cypress/e2e/frontend/modules/highlights.cy.ts +++ b/client/cypress/e2e/frontend/modules/highlights.cy.ts @@ -45,21 +45,35 @@ const contentListContents = [ ]; const contentBlockId = window.btoa('ContentBlockNode:1'); +let lastHighlight; const operations = { ...defaultModuleQueriesandMutations, ModuleDetailsQuery: { module: getModule(defaultContents), }, AddHighlight: ({ input: { highlight } }) => { + lastHighlight = { + ...highlight, + id: 'new-highlight-id', + contentBlock: { + id: contentBlockId, + }, + }; return { addHighlight: { - highlight: { - ...highlight, - id: 'new-highlight-id', - contentBlock: { - id: contentBlockId, - }, - }, + highlight: lastHighlight, + }, + }; + }, + UpdateHighlight: ({ input: { note, color } }) => { + lastHighlight = { + ...lastHighlight, + note, + color, + }; + return { + updateHighlight: { + highlight: lastHighlight, }, }; }, @@ -116,8 +130,12 @@ describe('Highlights', () => { markText(); + // delete doesn't make sense before the highlight exists + cy.getByDataCy('highlight-delete').should('not.exist'); + // mark the text with yellow and check the text cy.getByDataCy('highlight-alpha').click(); + cy.wait('@AddHighlight'); cy.getByDataCy('highlight-mark').should('contain', 'es ist ein'); // we only want to have one of each element and not accidentally create multiple @@ -126,7 +144,9 @@ describe('Highlights', () => { // mark the text with yellow and check the text cy.getByDataCy('highlight-beta').click(); + cy.wait('@UpdateHighlight'); cy.getByDataCy('highlight-mark').should('contain', 'es ist ein'); + cy.getByDataCy('highlight-mark').should('have.class', 'highlight--beta'); // // we only want to have one of each element and not accidentally create multiple cy.getByDataCy('highlight-popover').should('have.length', 1); // there should only be one popover @@ -167,7 +187,7 @@ describe('Highlights', () => { cy.getByDataCy('highlight-mark').should('not.exist'); }); - it.only('visits a module with a ContentListItem and highlights some text', () => { + it('visits a module with a ContentListItem and highlights some text', () => { cy.mockGraphqlOps({ operations: { ...operations, diff --git a/client/src/components/ContentBlock.vue b/client/src/components/ContentBlock.vue index e9b508d3..5c9e0b57 100644 --- a/client/src/components/ContentBlock.vue +++ b/client/src/components/ContentBlock.vue @@ -351,7 +351,20 @@ onMounted(() => { el: element, contentBlock: props.contentBlock, onChangeColor: (newHighlight: AddHighlightArgument) => { - createHighlight(newHighlight); + createHighlight(newHighlight).then( + ({ + data: { + addHighlight: { highlight }, + }, + }) => { + // we need to replace the Popover after the Highlight is created + // todo: is there a cleaner way than to look for the element and click it? + const mark = document.querySelector(`mark[data-id="${highlight.id}"]`); + if (mark) { + mark.click(); + } + } + ); }, onCreateNote: (newHighlight: AddHighlightArgument) => { // we also open the sidebar when clicking on the note icon diff --git a/client/src/components/highlights/HighlightPopover.vue b/client/src/components/highlights/HighlightPopover.vue index f32bb6b0..3de89843 100644 --- a/client/src/components/highlights/HighlightPopover.vue +++ b/client/src/components/highlights/HighlightPopover.vue @@ -26,7 +26,10 @@ @click="$emit('note')" /> -
+