Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion cypress/component/ImportContextSchemePreview.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import ImportContextSchemePreview from '../../src/modules/modals/ImportContextSc

const MENU_SWITCH = '[data-cy="importSchemeMenu"]'
const SKIPPED = '[data-cy="importSchemeMenuSkipped"]'
const PAGES_SWITCH = '[data-cy="importSchemePages"]'
const PAGES_SKIPPED = '[data-cy="importSchemePagesSkipped"]'

const schemeMenu = [
{ parent: null, title: 'Reports', displayTitle: 'Reports', icon: null, description: null, target: null },
Expand Down Expand Up @@ -40,22 +42,64 @@ describe('Import application scheme preview', () => {
cy.get(SKIPPED).should('contain', 'Missing table')
})

it('sends the pages of the scheme with the import', () => {
mountPreview(undefined, { from: [{ technicalName: 'dashboard', title: 'Old start' }], to: schemePages, skipped: [] })
.then(({ wrapper }) => {
cy.get(PAGES_SWITCH).should('exist')
cy.contains('Old start').should('exist')
cy.contains('Overview').should('exist')
cy.wrap(null).then(() => {
expect(lastPayload(wrapper).pages).to.deep.equal(schemePages)
})
})
})

it('leaves the pages out when the switch is turned off', () => {
mountPreview(undefined, { from: [], to: schemePages, skipped: [] })
.then(({ wrapper }) => {
cy.get(PAGES_SWITCH).click({ force: true })
cy.wrap(null).then(() => {
expect(lastPayload(wrapper)).to.not.have.property('pages')
})
})
})

it('lists the pages and widgets the import would skip', () => {
mountPreview(undefined, {
from: [],
to: [],
skipped: [
{ pageIndex: 0, page: 'Overview', widgetIndex: 2, widget: 'Elsewhere', reason: 'its table is not here or cannot be managed by the user' },
{ pageIndex: 1, page: 'Second start', widgetIndex: null, widget: null, reason: 'an application has one start page' },
],
})

cy.get(PAGES_SKIPPED).should('contain', 'Overview: Elsewhere').and('contain', 'Second start')
})

it('has no menu section for a preview without a menu', () => {
mountPreview(undefined)
.then(({ wrapper }) => {
cy.get(MENU_SWITCH).should('not.exist')
cy.get(PAGES_SWITCH).should('not.exist')
cy.wrap(null).then(() => {
expect(lastPayload(wrapper)).to.not.have.property('menu')
expect(lastPayload(wrapper)).to.not.have.property('pages')
})
})
})
})

const schemePages = [
{ page_type: 'grid', technical_name: 'overview', title: 'Overview', widgets: [{ type: 'data', title: 'Tasks', source: { targetType: 'table', targetUuid: 'table-uuid' } }] },
]

/**
* @param {object|undefined} menu the menu part of the preview response
* @param {object|undefined} pages the pages part of the preview response
* @return {Cypress.Chainable} the mount result
*/
function mountPreview(menu) {
function mountPreview(menu, pages = undefined) {
return cy.mount(ImportContextSchemePreview, {
props: {
previewData: {
Expand All @@ -66,6 +110,7 @@ function mountPreview(menu) {
addTables: {},
modifyTables: {},
...(menu === undefined ? {} : { menu }),
...(pages === undefined ? {} : { pages }),
},
},
})
Expand Down
5 changes: 3 additions & 2 deletions lib/Controller/ContextController.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ public function previewSchemeChanges(int $contextId, array $updateScheme): DataR
* @param list<array{node_type: int, node_uuid: string, permissions: int}> $nodes Ordered meta data of the related nodes
* @psalm-param array{addTables: list<TablesTable>, modifyTables: list<TablesTable>} $tables Tables to be added or modified
* @param list<array<string, mixed>>|null $menu Menu of the scheme, replacing the menu of the context: pages by technical name, tables and views by uuid, the group of an item by its position in the list; items that cannot be used here are skipped. Left out, the menu stays as it is
* @param list<array<string, mixed>>|null $pages Pages of the scheme: the start page updates the start page, a grid page the page with its technical name or it is added, and its widgets replace the widgets of that page; a widget names its table or view by `targetType` and `targetUuid` in its `source`. Pages and widgets that cannot be used here are skipped. Left out, the pages stay as they are
*
* @return DataResponse<Http::STATUS_OK, array<string, mixed>, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND|Http::STATUS_FORBIDDEN|Http::STATUS_BAD_REQUEST, array{message: string}, array{}>
*
Expand All @@ -370,10 +371,10 @@ public function previewSchemeChanges(int $contextId, array $updateScheme): DataR
*/
#[NoAdminRequired]
#[RequirePermission(permission: Application::PERMISSION_MANAGE, typeParam: 'context', idParam: 'contextId')]
public function importScheme(int $contextId, string $name, string $iconName, string $description, array $nodes, array $tables, ?array $menu = null): DataResponse {
public function importScheme(int $contextId, string $name, string $iconName, string $description, array $nodes, array $tables, ?array $menu = null, ?array $pages = null): DataResponse {
try {
$this->db->beginTransaction();
$context = $this->contextService->importScheme($contextId, $name, $iconName, $description, $nodes, $tables, $this->userId, $menu);
$context = $this->contextService->importScheme($contextId, $name, $iconName, $description, $nodes, $tables, $this->userId, $menu, $pages);
$this->db->commit();
return new DataResponse($context->jsonSerialize());
} catch (\InvalidArgumentException $e) {
Expand Down
Loading
Loading