use of net.n2oapp.framework.api.metadata.meta.page.Page in project n2o-framework by i-novus-llc.
the class OpenPageCompileTest method dynamicPage.
@Test
public void dynamicPage() {
SimplePage page = (SimplePage) compile("net/n2oapp/framework/config/metadata/compile/action/testOpenPageDynamicPage.page.xml").get(new PageContext("testOpenPageDynamicPage", "/page"));
PageContext context = (PageContext) route("/page/testOpenPageSimplePageAction1/id1", Page.class);
DataSet data = new DataSet();
data.put("page_test_id", "testOpenPageSimplePageAction1");
SimplePage openPage = (SimplePage) read().compile().bind().get(context, data);
assertThat(openPage.getBreadcrumb().size(), is(2));
assertThat(openPage.getBreadcrumb().get(0).getLabel(), is("first"));
assertThat(openPage.getBreadcrumb().get(1).getLabel(), is("second"));
assertThat(openPage.getWidget().getId(), is("page_testOpenPageSimplePageAction1_id1_main"));
assertThat(openPage.getRoutes().getList().get(0).getPath(), is("/page/testOpenPageSimplePageAction1/id1"));
assertThat(openPage.getWidget(), instanceOf(Form.class));
context = (PageContext) route("/page/testOpenPageSimplePageAction2/id1", Page.class);
data = new DataSet();
data.put("page_test_id", "testOpenPageSimplePageAction2");
openPage = (SimplePage) read().compile().bind().get(context, data);
assertThat(openPage.getBreadcrumb().size(), is(2));
assertThat(openPage.getBreadcrumb().get(0).getLabel(), is("first"));
assertThat(openPage.getBreadcrumb().get(1).getLabel(), is("second2"));
assertThat(openPage.getWidget().getId(), is("page_testOpenPageSimplePageAction2_id1_main"));
assertThat(openPage.getRoutes().getList().get(0).getPath(), is("/page/testOpenPageSimplePageAction2/id1"));
assertThat(openPage.getWidget(), instanceOf(Form.class));
}
use of net.n2oapp.framework.api.metadata.meta.page.Page in project n2o-framework by i-novus-llc.
the class OpenPageCompileTest method breadcrumb.
@Test
public void breadcrumb() {
// проверка breadcrumb при открытии open-page из таблицы
DataSet data = new DataSet().add("parent_id", 123);
PageContext context = new PageContext("testOpenPageSimplePage", "/page/:parent_id/view");
context.setBreadcrumbs(Collections.singletonList(new Breadcrumb("parent", "/page/:parent_id")));
Page page = compile("net/n2oapp/framework/config/metadata/compile/action/testOpenPageSimplePage.page.xml").bind().get(context, data);
assertThat(page.getRoutes().findRouteByUrl("/page/123/view"), notNullValue());
Page createPage = routeAndGet("/page/123/view/action1", Page.class);
assertThat(createPage.getRoutes().findRouteByUrl("/page/123/view/action1"), notNullValue());
assertThat(createPage.getBreadcrumb().size(), is(3));
assertThat(createPage.getBreadcrumb().get(0).getLabel(), is("parent"));
assertThat(createPage.getBreadcrumb().get(0).getPath(), is("/page/123"));
assertThat(createPage.getBreadcrumb().get(1).getLabel(), is("first"));
assertThat(createPage.getBreadcrumb().get(1).getPath(), is("/page/123/view"));
assertThat(createPage.getBreadcrumb().get(2).getLabel(), is("second"));
assertThat(createPage.getBreadcrumb().get(2).getPath(), nullValue());
Page updatePage = routeAndGet("/page/123/view/456/action2", Page.class);
assertThat(updatePage.getRoutes().findRouteByUrl("/page/123/view/456/action2"), notNullValue());
assertThat(updatePage.getBreadcrumb().size(), is(3));
assertThat(updatePage.getBreadcrumb().get(0).getLabel(), is("parent"));
assertThat(updatePage.getBreadcrumb().get(0).getPath(), is("/page/123"));
assertThat(updatePage.getBreadcrumb().get(1).getLabel(), is("first"));
assertThat(updatePage.getBreadcrumb().get(1).getPath(), is("/page/123/view"));
assertThat(updatePage.getBreadcrumb().get(2).getLabel(), is("second"));
assertThat(updatePage.getBreadcrumb().get(2).getPath(), nullValue());
HashMap<String, String[]> params = new HashMap<>();
data.put("name", "ivan");
data.put("secondName", "ivanov");
Page masterDetailPage = routeAndGet("/page/123/view/456/masterDetail", Page.class, params);
assertThat(masterDetailPage.getRoutes().findRouteByUrl("/page/123/view/456/masterDetail"), notNullValue());
assertThat(masterDetailPage.getBreadcrumb().size(), is(3));
assertThat(masterDetailPage.getBreadcrumb().get(0).getLabel(), is("parent"));
assertThat(masterDetailPage.getBreadcrumb().get(0).getPath(), is("/page/123"));
assertThat(masterDetailPage.getBreadcrumb().get(1).getLabel(), is("first"));
assertThat(masterDetailPage.getBreadcrumb().get(1).getPath(), is("/page/123/view"));
assertThat(masterDetailPage.getBreadcrumb().get(2).getLabel(), is("second"));
assertThat(masterDetailPage.getBreadcrumb().get(2).getPath(), nullValue());
Page level3Page = routeAndGet("/page/123/view/456/masterDetail/level3", Page.class, params);
assertThat(level3Page.getBreadcrumb().size(), is(4));
assertThat(level3Page.getBreadcrumb().get(0).getLabel(), is("parent"));
assertThat(level3Page.getBreadcrumb().get(0).getPath(), is("/page/123"));
assertThat(level3Page.getBreadcrumb().get(1).getLabel(), is("first"));
assertThat(level3Page.getBreadcrumb().get(1).getPath(), is("/page/123/view"));
assertThat(level3Page.getBreadcrumb().get(2).getLabel(), is("second"));
assertThat(level3Page.getBreadcrumb().get(2).getPath(), is("/page/123/view/456/masterDetail?name=:name&surname=:surname&secondName=test"));
// проверка breadcrumb при открытии open-page не из таблицы, а другого виджета
// при этом в parentId не должны сохраняться id выбранных записей
context = new PageContext("testOpenPageSimplePage2", "/page/:parent_id/view2");
context.setBreadcrumbs(Collections.singletonList(new Breadcrumb("parent", "/page/:parent_id")));
Page page2 = compile("net/n2oapp/framework/config/metadata/compile/action/testOpenPageSimplePage2.page.xml").bind().get(context, data);
assertThat(page2.getRoutes().findRouteByUrl("/page/123/view2"), notNullValue());
updatePage = routeAndGet("/page/123/view2/456/action2", Page.class);
assertThat(updatePage.getRoutes().findRouteByUrl("/page/123/view2/456/action2"), notNullValue());
assertThat(updatePage.getBreadcrumb().size(), is(3));
assertThat(updatePage.getBreadcrumb().get(0).getLabel(), is("parent"));
assertThat(updatePage.getBreadcrumb().get(0).getPath(), is("/page/123"));
assertThat(updatePage.getBreadcrumb().get(1).getLabel(), is("first"));
// не содержит :page_test_id
assertThat(updatePage.getBreadcrumb().get(1).getPath(), is("/page/123/view2"));
assertThat(updatePage.getBreadcrumb().get(2).getLabel(), is("second"));
assertThat(updatePage.getBreadcrumb().get(2).getPath(), nullValue());
}
use of net.n2oapp.framework.api.metadata.meta.page.Page in project n2o-framework by i-novus-llc.
the class ShowModalCompileTest method updateWithPreFilters.
@Test
public void updateWithPreFilters() {
PageContext pageContext = new PageContext("testShowModalRootPage", "/p");
Page rootPage = compile("net/n2oapp/framework/config/metadata/compile/action/testShowModalRootPage.page.xml").get(pageContext);
PageContext modalContext = (PageContext) route("/p/123/updateWithPrefilters", Page.class);
assertThat(modalContext.getSourceId(null), is("testShowModalPage"));
assertThat(modalContext.getDatasources().size(), is(1));
assertThat(modalContext.getDatasources().get(0).getDefaultValuesMode(), is(DefaultValuesMode.query));
N2oPreFilter[] filters = modalContext.getDatasources().get(0).getFilters();
assertThat(filters.length, is(1));
assertThat(filters[0].getDatasource(), is("main"));
assertThat(filters[0].getRefPageId(), is("p"));
assertThat(filters[0].getFieldId(), is(N2oQuery.Field.PK));
assertThat(filters[0].getType(), is(FilterType.eq));
assertThat(filters[0].getModel(), is(ReduxModel.resolve));
assertThat(filters[0].getValue(), is("{id}"));
SimplePage modalPage = (SimplePage) read().compile().get(modalContext);
assertThat(modalPage.getId(), is("p_updateWithPrefilters"));
assertThat(modalPage.getBreadcrumb(), nullValue());
Widget modalWidget = modalPage.getWidget();
Datasource ds = modalPage.getDatasources().get(modalWidget.getDatasource());
assertThat(ds.getProvider().getPathMapping().get("id").getBindLink(), is("models.resolve['p_main']"));
assertThat(ds.getProvider().getPathMapping().get("id").getValue(), is("`id`"));
assertThat(ds.getProvider().getQueryMapping().get("name").getBindLink(), is("models.filter['p_second']"));
assertThat(ds.getProvider().getQueryMapping().get("name").getValue(), is("`name`"));
assertThat(ds.getDefaultValuesMode(), is(DefaultValuesMode.query));
List<AbstractButton> buttons = modalPage.getToolbar().get("bottomRight").get(0).getButtons();
assertThat(buttons.size(), is(2));
assertThat(buttons.get(0).getId(), is("submit"));
assertThat(buttons.get(0).getAction(), notNullValue());
assertThat(buttons.get(1).getId(), is("close"));
assertThat(buttons.get(1).getAction(), notNullValue());
InvokeAction submit = (InvokeAction) modalPage.getToolbar().getButton("submit").getAction();
assertThat(submit.getMeta().getSuccess().getRefresh().getDatasources(), hasItem("p_main"));
assertThat(submit.getMeta().getSuccess().getModalsToClose(), is(1));
assertThat(submit.getPayload().getDataProvider().getUrl(), is("n2o/data/p/:id/updateWithPrefilters/submit"));
ActionContext submitContext = (ActionContext) route("/p/:id/updateWithPrefilters/submit", CompiledObject.class);
assertThat(submitContext.getSourceId(null), is("testShowModal"));
assertThat(submitContext.getOperationId(), is("update"));
assertThat(submitContext.getOperationId(), is("update"));
DataSet data = new DataSet();
data.put("id", 222);
modalPage = (SimplePage) read().compile().bind().get(modalContext, data);
assertThat(modalPage.getDatasources().get(modalPage.getWidget().getDatasource()).getProvider().getUrl(), is("n2o/data/p/222/updateWithPrefilters/modal"));
submit = (InvokeAction) modalPage.getToolbar().getButton("submit").getAction();
assertThat(submit.getPayload().getDataProvider().getPathMapping(), not(hasKey("p_main_id")));
}
use of net.n2oapp.framework.api.metadata.meta.page.Page in project n2o-framework by i-novus-llc.
the class ShowModalCompileTest method copyActionWithTwoWidgetWithoutCopyAttributes.
@Test
public void copyActionWithTwoWidgetWithoutCopyAttributes() {
Page rootPage = compile("net/n2oapp/framework/config/metadata/compile/action/testShowModalCopyActionWithTwoWidgetDefault.page.xml").get(new PageContext("testShowModalCopyActionWithTwoWidgetDefault"));
PageContext modalContext = (PageContext) route("/testShowModalCopyActionWithTwoWidgetDefault/123/update", Page.class);
StandardPage modalPage = (StandardPage) read().compile().get(modalContext);
CopyAction submit = (CopyAction) modalPage.getToolbar().getButton("submit").getAction();
assertThat(submit.getType(), is("n2o/models/COPY"));
assertThat(submit.getPayload().getSource().getPrefix(), is(ReduxModel.resolve.getId()));
assertThat(submit.getPayload().getSource().getKey(), is("testShowModalCopyActionWithTwoWidgetDefault_update_master"));
assertThat(submit.getPayload().getSource().getField(), nullValue());
assertThat(submit.getPayload().getTarget().getPrefix(), is(ReduxModel.edit.getId()));
assertThat(submit.getPayload().getTarget().getKey(), is("testShowModalCopyActionWithTwoWidgetDefault_ignore_table"));
assertThat(submit.getPayload().getTarget().getField(), is("dictionary.id"));
assertThat(submit.getPayload().getMode(), is(CopyMode.replace));
assertThat(submit.getMeta().getModalsToClose(), is(1));
List<AbstractButton> buttons = modalPage.getToolbar().get("bottomRight").get(0).getButtons();
assertThat(buttons.get(0).getId(), is("submit"));
assertThat(buttons.get(0).getAction(), is(submit));
assertThat(buttons.get(0).getLabel(), is("Выбрать"));
}
use of net.n2oapp.framework.api.metadata.meta.page.Page in project n2o-framework by i-novus-llc.
the class ShowModalCompileTest method testShowModalPreFilters.
/**
* Проверяет, что show-modal pre-filters пробрасываются на модальную страницу
*/
@Test
public void testShowModalPreFilters() {
PageContext pageContext = new PageContext("testShowModalPreFilters", "/p");
compile("net/n2oapp/framework/config/metadata/compile/action/testShowModalPreFilters.page.xml").get(pageContext);
SimplePage page = (SimplePage) routeAndGet("/p/create", Page.class);
ClientDataProvider provider = page.getDatasources().get("p_create_modal").getProvider();
assertThat(provider, notNullValue());
assertThat(provider.getQueryMapping().get("modal_id").normalizeLink(), is("models.resolve['p_form'].id"));
assertThat(provider.getQueryMapping().get("modal_name").getValue(), is(123));
}
Aggregations