Skip to content

Commit

Permalink
Merge pull request #353 from meaningfy-ws/feature/MWB-878
Browse files Browse the repository at this point in the history
Updated tests + fixes
  • Loading branch information
kaleanych authored Nov 22, 2024
2 parents a0165d2 + 972c1d4 commit 2aa8981
Show file tree
Hide file tree
Showing 17 changed files with 111 additions and 70 deletions.
2 changes: 1 addition & 1 deletion mapping_workbench/backend/mapping_package/services/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ async def remove_mapping_package_resources(mapping_package: MappingPackage):
).update_many(
Pull({ConceptualMappingRule.refers_to_mapping_package_ids: package_id})
)
print(Pull({GenericTripleMapFragment.refers_to_mapping_package_ids: package_id}))

await GenericTripleMapFragment.find(
GenericTripleMapFragment.project == project_link
).update_many(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,10 @@ async def route_update_test_data_file_resource(
del req_data['transform_test_data']
transform_mapping_package_id = None
if 'mapping_package_id' in req_data:
transform_mapping_package_id = PydanticObjectId(req_data['mapping_package_id'])
transform_mapping_package_id = PydanticObjectId(req_data['mapping_package_id']) \
if req_data['mapping_package_id'] else None
del req_data['mapping_package_id']

data = TestDataFileResourceUpdateIn(**req_data)
try:
return await update_test_data_file_resource(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async def update_generic_triple_map_fragment(
PydanticObjectId(package_id) for package_id in
update_data[GenericTripleMapFragment.refers_to_mapping_package_ids]
]

print(update_data)
return GenericTripleMapFragmentOut(**(
await generic_triple_map_fragment.set(update_data)
).model_dump())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Feature: Specific Triple Maps
Feature: Generic Triple Maps

As a valid user want to interact with Specific Triple Maps
As a valid user want to interact with Generic Triple Maps

Background:
Given Session Login
Expand All @@ -17,18 +17,18 @@ Feature: Specific Triple Maps

Scenario: Add Triple Map Fragment
Then I click on Triple Map Fragments
Then I get redirected to Specific Triple Maps
Then I get redirected to Generic Triple Maps

When I click on add button
Then I get redirected to create page
Then I enter name
Then I successfully create Specific Triple Maps
Then I successfully create Generic Triple Maps

Scenario: Update Resource
Then I click on Triple Map Fragments
Then I get redirected to Specific Triple Maps
Then I get redirected to Generic Triple Maps

Then I search for Specific Triple Map
Then I search for Generic Triple Map
Then I click edit button
Then I get redirected to edit page

Expand All @@ -37,8 +37,8 @@ Feature: Specific Triple Maps

Scenario: Delete Resource
Then I click on Triple Map Fragments
Then I get redirected to Specific Triple Maps
Then I get redirected to Generic Triple Maps

Then I search for updated Specific Triple Map
Then I search for updated Generic Triple Map
Then I click delete button
Then I get success delete
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const {username, password, homeURL, appURLPrefix, projectName} = Cypress.env()


let sessionProject = ''
const specificTripleMapName = 'test_specific_triple_map'
const genericTripleMapName = 'test_generic_triple_map'

Given('Session Login', () => {
// Caching session when logging in via page visit
Expand All @@ -31,12 +31,12 @@ When('I expand Triple Maps Fragments', () => {
})

Then('I click on Triple Map Fragments', () => {
cy.intercept('GET', appURLPrefix + 'specific_triple_map_fragments*').as('get')
cy.intercept('GET', appURLPrefix + 'generic_triple_map_fragments*').as('get')
cy.get('#nav_technical_mappings').click()
cy.get('#nav_triple_map_fragments').click()
})

Then('I get redirected to Specific Triple Maps', () => {
Then('I get redirected to Generic Triple Maps', () => {
cy.url().should('include','triple-map-fragments')
cy.wait('@get').its('response.statusCode').should('eq', 200)
})
Expand All @@ -51,25 +51,25 @@ Then('I get redirected to create page', () => {


Then('I enter name', () => {
cy.intercept('POST', appURLPrefix + 'specific_triple_map_fragments*').as('create')
cy.intercept('POST', appURLPrefix + 'generic_triple_map_fragments*').as('create')
cy.get("input[name=mapping_package_id]").parent().click()
.get('ul.MuiList-root').click()
cy.get("input[name=triple_map_uri]").clear().type(specificTripleMapName)
cy.get("input[name=triple_map_uri]").clear().type(genericTripleMapName)
cy.get("button[type=submit]").click('right')
})


Then('I successfully create Specific Triple Maps', () => {
Then('I successfully create Generic Triple Maps', () => {
cy.wait('@create').its('response.statusCode').should('eq', 201)
})

// update

Then('I search for Specific Triple Map', () => {
cy.get('input[type=text]').clear().type(specificTripleMapName + '{enter}')
Then('I search for Generic Triple Map', () => {
cy.get('input[type=text]').clear().type(genericTripleMapName + '{enter}')
})

Then('I receive Specific Triple Maps', () => {
Then('I receive Generic Triple Maps', () => {
cy.wait('@get').its('response.statusCode').should('eq', 200)
})

Expand All @@ -82,21 +82,21 @@ Then('I get redirected to edit page', () => {
})

Then('I enter updated name', () => {
cy.intercept('PATCH', appURLPrefix + 'specific_triple_map_fragments/*').as('update')
cy.get("input[name=triple_map_uri]").clear().type( specificTripleMapName + 1 +'{enter}')
cy.intercept('PATCH', appURLPrefix + 'generic_triple_map_fragments/*').as('update')
cy.get("input[name=triple_map_uri]").clear().type( genericTripleMapName + 1 +'{enter}')
})

Then('I get success update', () => {
cy.wait('@update').its('response.statusCode').should('eq', 200)
})

Then('I search for updated Specific Triple Map', () => {
cy.get('input[type=text]').clear().type(specificTripleMapName + 1 + '{enter}')
Then('I search for updated Generic Triple Map', () => {
cy.get('input[type=text]').clear().type(genericTripleMapName + 1 + '{enter}')
})

//delete
Then('I click delete button', () => {
cy.intercept('DELETE',appURLPrefix + 'specific_triple_map_fragments/*').as('delete')
cy.intercept('DELETE',appURLPrefix + 'generic_triple_map_fragments/*').as('delete')
cy.get('#delete_button').click()
cy.get('#yes_dialog_button').click()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const Page = () => {
identifier: item.identifier || '',
rdf_manifestation: item.rdf_manifestation || '',
transform_test_data: false,
mapping_package_id: ''
mapping_package_id: null
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,28 @@ import {RouterLink} from 'src/components/router-link';
import {ForItemCreateForm} from "src/contexts/app/section/for-item-form";
import {FileResourceEditForm} from 'src/sections/app/file-manager/file-resource-edit-form';
import {testDataFileResourcesApi as sectionApi} from 'src/api/test-data-suites/file-resources';
import * as React from "react";
import Grid from "@mui/material/Unstable_Grid2";
import {FormTextField} from "../../../../../components/app/form/text-field";

const ExtraForm = (props) => {
const {
item,
formik
} = props;

return (
<Stack gap={3}>
<Grid xs={12}
md={12}>
<FormTextField formik={formik}
name="identifier"
label="Identifier"
required/>
</Grid>
</Stack>
)
}

const Page = () => {
const router = useRouter();
Expand All @@ -27,6 +48,10 @@ const Page = () => {

let item = {};

const extra_form_fields = {
identifier: item.identifier || ''
}

return (
<>
<Seo title={`App: ${sectionApi.SECTION_ITEM_TITLE} Create`}/>
Expand Down Expand Up @@ -55,8 +80,12 @@ const Page = () => {
</Link>
</div>
</Stack>
<FileResourceEditForm itemctx={new ForItemCreateForm(item, sectionApi)}
collection_id={id}/>
<FileResourceEditForm
itemctx={new ForItemCreateForm(item, sectionApi)}
collection_id={id}
extra_form={ExtraForm}
extra_form_fields={extra_form_fields}
/>
</Stack>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ export const EditForm = (props) => {
priority: COMMENT_PRIORITY.NORMAL
}


const initialValues = {
source_structural_element: item.source_structural_element?.id ?? '',
xpath_condition: item.xpath_condition ?? '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ import {useHighlighterTheme} from "src/hooks/use-highlighter-theme";
import {FormCodeTextArea} from "src/components/app/form/code-text-area";
import TablePagination from "src/sections/components/table-pagination";
import {ListItemActions} from 'src/components/app/list/list-item-actions';
import TableSorterHeader from "src/sections/components/table-sorter-header";
import {ForListItemAction} from 'src/contexts/app/section/for-list-item-action';
import {genericTripleMapFragmentsApi} from "src/api/triple-map-fragments/generic";
import {sparqlTestFileResourcesApi} from "src/api/sparql-test-suites/file-resources";
Expand Down Expand Up @@ -372,7 +371,6 @@ export const ListTableMappingPackages = (props) => {
const {
item, initProjectMappingPackages = null, onPackagesUpdate = () => {
},
isCurrent,
isHovered
} = props;

Expand Down Expand Up @@ -413,14 +411,9 @@ export const ListTableMappingPackages = (props) => {
}

return (<>
{ruleMappingPackages.length > 0 && (
<Box sx={{mb: 1}}>
{ruleMappingPackages.map(x => (
<Chip key={"mapping_package_" + x.id}
label={x.identifier}/>
))}
</Box>
)}
{ruleMappingPackages.length > 0 && <>
{ruleMappingPackages.map(x => (<Box sx={{mb: 1}}><Chip key={"mapping_package_" + x.id} label={x.title}/></Box>))}
</>}
<Box sx={{
position: "absolute",
left: "50%",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export const FileCollectionListTable = (props) => {

const isItemSelected = itemId => selectedItems.indexOf(itemId) !== -1;

const allChecked = selectedItems.length === items.length
const allChecked = items.length > 0 && selectedItems.length === items.length

const handleItemsSelectAll = checked => {
setSelectedItems(checked ? items.map(item => item._id) : [])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,12 @@ export const TestDataCollectionListTable = (props) => {
const [currentItem, setCurrentItem] = useState(null);
const [selectedItems, setSelectedItems] = useState([]);

const isItemSelected = (itemId) => {
return selectedItems.indexOf(itemId) !== -1;
const isItemSelected = itemId => selectedItems.indexOf(itemId) !== -1;

const allChecked = items.length > 0 && selectedItems.length === items.length

const handleItemsSelectAll = checked => {
setSelectedItems(checked ? items.map(item => item._id) : [])
}

const handleItemSelect = (e, itemId) => {
Expand Down Expand Up @@ -362,6 +366,11 @@ export const TestDataCollectionListTable = (props) => {
<TableHead>
<TableRow>
<TableCell>
<Checkbox
checked={allChecked}
indeterminate={selectedItems.length && !allChecked}
onChange={(event) => handleItemsSelectAll(event.target.checked)}
/>
</TableCell>
<TableCell width="25%">
Title
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ export const EditForm = (props) => {

const onUpdateAndTransform = (values, helpers) => {
values['project'] = sessionApi.getSessionProject();
if (!values['mapping_package_id']) values['mapping_package_id'] = null;
const mapping_package_id = values['mapping_package_id'] || null;
delete values['mapping_package_id'];

values['id'] = item._id;
formik.setSubmitting(true)
const toastId = toastLoad("Updating Content")
Expand All @@ -142,7 +144,6 @@ export const EditForm = (props) => {
sectionApi.updateItem(values)
.then(res => {
toastLoad("Transforming Content", toastId);
const mapping_package_id = values['mapping_package_id']
sectionApi.getTripleMapRdfResultContent(item._id, selectedTree, useThisTripleMap, mapping_package_id)
.then(res => {
setRdfResultContent(res.rdf_manifestation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,9 @@ export const ListTableMappingPackages = (props) => {
}

return (<>
{!!itemMappingPackages.length && <Box sx={{mb: 1}}>
{itemMappingPackages.map(x =>
<Chip key={"mapping_package_" + x.id}
label={x.title}/>
)}
</Box>}
{!!itemMappingPackages.length && <>
{itemMappingPackages.map(x => <Box sx={{mb: 1}}><Chip key={"mapping_package_" + x.id} label={x.title}/></Box>)}
</>}
{isHovered && <Box sx={{position: "absolute", left: "50%", top: "50%"}}>
<Button
aria-describedby={"mapping_packages_dialog_" + item._id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,17 @@ export const MappingPackageCheckboxList = (props) => {
} = props;

const [projectMappingPackages, setProjectMappingPackages] = useState([]);

const allChecked = projectMappingPackages.length === mappingPackages.length

const mappingPackagesStore = useMappingPackagesStore(initProjectMappingPackages)

useEffect(() => {
setProjectMappingPackages(mappingPackagesStore.items);
if (withDefaultPackage) {
handleUpdate([mappingPackagesStore.items.find(pkg => pkg.identifier === 'default')?.id])
const defaultPackage = mappingPackagesStore.items.find(pkg => pkg.identifier === 'default')
if (defaultPackage) {
handleUpdate([defaultPackage.id])
}
}
}, [JSON.stringify(mappingPackagesStore.items)]);

Expand Down
12 changes: 10 additions & 2 deletions tests/e2e/backend/api/test_data_suite/test_routes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import pytest
from beanie import PydanticObjectId

from mapping_workbench.backend.mapping_package.models.entity import MappingPackage
from mapping_workbench.backend.mapping_package.services.api import get_mapping_package
from mapping_workbench.backend.test_data_suite.entrypoints.api.routes import ROUTE_PREFIX
from mapping_workbench.backend.test_data_suite.models.entity import TestDataSuite
from tests.e2e.backend.api import client, api_endpoint
Expand All @@ -14,6 +16,7 @@ async def test_test_data_suites_assign_mapping_packages_route(
dummy_mapping_package
):
await dummy_test_data_suite.save()
await dummy_mapping_package.save()

data = {
"project": str(dummy_project.id),
Expand All @@ -29,12 +32,17 @@ async def test_test_data_suites_assign_mapping_packages_route(

assert response.status_code == 200

test_data_suite = await TestDataSuite.get(dummy_test_data_suite.id)
assert dummy_mapping_package.id in test_data_suite.refers_to_mapping_package_ids
mapping_package: MappingPackage = await get_mapping_package(dummy_mapping_package.id)

test_data_suites_ids = [test_data_suite.to_ref().id for test_data_suite in mapping_package.test_data_suites]
assert dummy_test_data_suite.id in test_data_suites_ids

await dummy_test_data_suite.delete()
assert not await TestDataSuite.get(dummy_test_data_suite.id)

await dummy_mapping_package.delete()
assert not await MappingPackage.get(dummy_mapping_package.id)


@pytest.mark.asyncio
async def test_test_data_file_resources_struct_tree_route(
Expand Down
Loading

0 comments on commit 2aa8981

Please sign in to comment.