diff --git a/client/cypress.e2e.ts b/client/cypress.e2e.ts index 32dd7f2c..0025205b 100644 --- a/client/cypress.e2e.ts +++ b/client/cypress.e2e.ts @@ -3,7 +3,7 @@ export default defineConfig( { e2e: { "baseUrl": "http://localhost:8000", specPattern: 'cypress/e2e/e2e/**/*.{spec,cy}.{js,ts}', - supportFile: 'cypress/support/e2e.js', + supportFile: 'cypress/support/e2e.ts', }, "videoUploadOnPasses": false, "reporter": "junit", diff --git a/client/cypress/e2e/frontend/modules/duplicate-content-block.cy.ts b/client/cypress/e2e/frontend/modules/duplicate-content-block.cy.ts index ea86f82d..c2bc692c 100644 --- a/client/cypress/e2e/frontend/modules/duplicate-content-block.cy.ts +++ b/client/cypress/e2e/frontend/modules/duplicate-content-block.cy.ts @@ -1,10 +1,18 @@ +import {getMinimalMe} from '../../../support/helpers'; + describe('Duplicate Content Block', () => { beforeEach(() => { cy.setup(); }); - it('works', () => { - cy.visit('/'); + it.skip('works', () => { + cy.visit('/fron'); - cy.getByDataCy('whatever'); - }); + const operations = { + MeQuery: getMinimalMe({isTeacher: true}), + }; + cy.mockGraphqlOps({ + operations + }); + cy.getByDataCy('whatever'); + }); }); diff --git a/client/src/components/content-block-form/ContentBlockForm.vue b/client/src/components/content-block-form/ContentBlockForm.vue index 8f73956b..19269ff9 100644 --- a/client/src/components/content-block-form/ContentBlockForm.vue +++ b/client/src/components/content-block-form/ContentBlockForm.vue @@ -207,46 +207,38 @@ update(index: number, element: any, parent?: number) { if (parent === undefined) { // element is top level - this.localContentBlock.contents = insertAtIndex(this.localContentBlock.contents, index, element); + this.localContentBlock.contents = replaceAtIndex(this.localContentBlock.contents, index, element); } else { const parentBlock = this.localContentBlock.contents[parent]; - const newElementContents = insertAtIndex(parentBlock.contents, index, element); + const newElementContents = replaceAtIndex(parentBlock.contents, index, element); const newBlock = { ...parentBlock, contents: newElementContents, }; - this.localContentBlock.contents = insertAtIndex(this.localContentBlock.contents, index, newBlock); + this.localContentBlock.contents = replaceAtIndex(this.localContentBlock.contents, parent, newBlock); } }, addBlock(afterOuterIndex: number, innerIndex?: number) { if (innerIndex !== undefined) { const block = this.localContentBlock.contents[afterOuterIndex]; - this.localContentBlock.contents = [ - ...this.localContentBlock.contents.slice(0, afterOuterIndex), - { - ...block, - contents: [ - ...block.contents.slice(0, innerIndex + 1), - { - id: -1, - type: CHOOSER, - }, - ...block.contents.slice(innerIndex + 1), - ], - }, - ...this.localContentBlock.contents.slice(afterOuterIndex + 1), - ]; - } else { - this.localContentBlock.contents = [ - ...this.localContentBlock.contents.slice(0, afterOuterIndex + 1), - { + const element = { + ...block, + contents: insertAtIndex(block.contents, innerIndex + 1, { id: -1, type: CHOOSER, - includeListOption: true, - }, - ...this.localContentBlock.contents.slice(afterOuterIndex + 1), - ]; + }), + }; + + this.localContentBlock.contents = replaceAtIndex(this.localContentBlock.contents, afterOuterIndex, element); + } else { + const element = { + id: -1, + type: CHOOSER, + includeListOption: true, + }; + + this.localContentBlock.contents = insertAtIndex(this.localContentBlock.contents, afterOuterIndex + 1, element); } }, remove(outer: number, inner?: number, askForConfirmation = true) { diff --git a/server/books/factories.py b/server/books/factories.py index ea40f8d7..531974c0 100644 --- a/server/books/factories.py +++ b/server/books/factories.py @@ -175,7 +175,7 @@ class ContentBlockFactory(BasePageFactory): if stream_field_name in kwargs: """ stream_field_name is most likely 'contents' - this means: if there is a property named contents, us the defined ones in this block. + this means: if there is a property named contents, use the defined ones in this block. otherwise, go into the other block and randomize the contents """ for idx, resource in enumerate(kwargs[stream_field_name]): diff --git a/server/books/tests/test_duplicate_content_blocks.py b/server/books/tests/test_duplicate_content_blocks.py index 3e83b066..3b7b96ce 100644 --- a/server/books/tests/test_duplicate_content_blocks.py +++ b/server/books/tests/test_duplicate_content_blocks.py @@ -1,4 +1,6 @@ from graphql_relay import to_global_id +from wagtail.core.fields import StreamField +from wagtail.tests.utils.form_data import streamfield, nested_form_data, rich_text from books.factories import ContentBlockFactory, ModuleFactory, ChapterFactory from books.models import ContentBlock @@ -77,6 +79,107 @@ class DuplicateContentBlockTestCase(SkillboxTestCase): self.assertTrue('Kopie' in content_blocks[0].get('title')) self.assertTrue('Kopie' not in content_blocks[1].get('title')) - - def test_duplicate_non_editable_contents(self): - self.assertTrue(False) + # def test_duplicate_non_editable_contents(self): + # # contents__0__text_block__text + # nested_form_data({ + # 'content': streamfield([ + # nested_form_data({ + # 'text_block': [ + # ('text', rich_text('Asdf')) + # ] + # }) + # ]) + # }) + # + # contents = [ + # nested_form_data({ + # 'text_block': streamfield([ + # ('text', 'Asdf') + # ]) + # }), + # # { + # # "type": "text_block", + # # "value": { + # # "text": "Asdf" + # # }, + # # }, + # # { + # # "type": "assignment", + # # "value": { + # # "title": "Ein Auftragstitel", + # # "assignment": "Ein Auftrag", + # # }, + # # }, + # # { + # # "type": "image_block", + # # "value": { + # # "path": "/media/original_images/dummy_pZUH02q.jpg" + # # }, + # # }, + # # { + # # "type": "image_url_block", + # # "value": { + # # "title": "Asdf", + # # "url": "http://localhost:8000/media/images/dummy_pZUH02q.max-165x165.jpg" + # # }, + # # }, + # # { + # # "type": "link_block", + # # "value": { + # # "text": "Asdf", + # # "url": "https://iterativ.ch" + # # }, + # # }, + # # { + # # "type": "solution", + # # "value": { + # # "text": "Asdf", + # # }, + # # }, + # # { + # # "type": "video_block", + # # "value": { + # # "url": "https://www.youtube.com/watch?v=QxQBWR7sntI" + # # }, + # # }, + # # { + # # "type": "document_block", + # # "value": { + # # "url": "http://localhost:8000/media/images/dummy_pZUH02q.max-165x165.jpg" + # # }, + # # }, + # # { + # # "type": "infogram_block", + # # "value": { + # # "id": "4405271e-dbfb-407e-ac19-0a238cde393f", + # # "title": "Gerät Internetnutzung Jungen" + # # }, + # # }, + # # { + # # "type": "thinglink_block", + # # "value": { + # # "id": "1314204266449076227" + # # }, + # # }, + # # { + # # "type": "subtitle", + # # "value": { + # # "text": "Subtitle" + # # }, + # # }, + # # { + # # "type": "instruction", + # # "value": { + # # "url": "http://localhost:8000/media/images/dummy_pZUH02q.max-165x165.jpg", + # # "text": "Instruction", + # # }, + # # }, + # # { + # # "type": "module_room_slug", + # # "value": { + # # "title": "Raum", + # # }, + # # }, + # ] + # self.content_block.contents = contents + # self.assertTrue(False)