<commit_before>describe('SelectAction', function () {
    it('successful build', function () {
        // Given
        var view = new View();
        var builder = new ApplicationBuilder();

        var metadata = {
            SelectAction: {
                LinkView: {
                    ExistsView: {
                    }
                },
                SourceValue: {
                    Source: 'FirstDS',
                    Property: 'Name'
                },
                DestinationValue: {
                    Source: 'SecondDS',
                    Property: 'Name'
                }
            }
        };

        // When
        var selectAction = builder.build(metadata, {parentView: view});

        // Then
        assert.isNotNull( selectAction );
        assert.isNotNull( selectAction.execute, 'action should have execute' );
    });
});<commit_msg>UI-1672: Дописать тесты для selectAction #resolved<commit_after>describe('SelectAction', function () {
    it('successful build', function () {
        // Given
        var view = new View();
        var builder = new ApplicationBuilder();

        var metadata = {
            SelectAction: {
                LinkView: {
                    ExistsView: {
                    }
                },
                SourceValue: {
                    Source: 'FirstDS',
                    Property: 'Name'
                },
                DestinationValue: {
                    Source: 'SecondDS',
                    Property: 'Name'
                }
            }
        };

        // When
        var selectAction = builder.build(metadata, {parentView: view});

        // Then
        assert.isNotNull( selectAction );
        assert.isNotNull( selectAction.execute, 'action should have execute' );
    });

    it('should set selected item if dialog result is accepted', function (done) {
        // Given
        var viewMetadata = {
            "Text": 'Parent View',
            "DataSources": [
                {
                    "ObjectDataSource": {
                        "Name": "ObjectDataSource",
                        "IsLazy": false,
                        "Items": [
                            {
                                SelectedObject: "empty"
                            }
                        ]
                    }
                }
            ],
            "Items": [{
                "Button": {
                    "Name": "SelectButton",
                    "Action": {
                        "SelectAction": {
                            "DestinationValue": {
                                "Source": "ObjectDataSource",
                                "Property": "$.SelectedObject"
                            },
                            "SourceValue": {
                                "Source": "MainDataSource",
                                "Property": "$"
                            },
                            "LinkView": {
                                "InlineView": {
                                    "OpenMode": "Dialog",
                                    "View": {
                                        "Name": "SelectView",
                                        "DataSources": [
                                            {
                                                "ObjectDataSource": {
                                                    "Name": "MainDataSource",
                                                    "IsLazy": false,
                                                    "Items": [
                                                        {
                                                            "Name": "first"
                                                        },
                                                        {
                                                            "Name": "second"
                                                        }
                                                    ]
                                                }
                                            }
                                        ],
                                        "Items": [
                                            {
                                                "Button": {
                                                    "Name": "AcceptBtn",
                                                    "Action": {
                                                        "AcceptAction": {
                                                        }
                                                    }
                                                }
                                            }
                                        ]
                                    }
                                }
                            }
                        }
                    }
                }
            }]
        };

        testHelper.applyViewMetadata(viewMetadata, function(view){
            var selectBtn = view.context.controls['SelectButton'];
            var destinationDS = view.context.dataSources['ObjectDataSource'];

            assert.equal(destinationDS.getSelectedItem().SelectedObject, "empty");

            // When
            selectBtn.click();

            var childView = view.context.controls['SelectView'];
            var sourceDS = childView.context.dataSources['MainDataSource'];
            var acceptBtn = childView.context.controls['AcceptBtn'];

            var selectedValue = sourceDS.getItems()[1];
            sourceDS.setSelectedItem(selectedValue);

            acceptBtn.click();

            // Then
            assert.deepEqual(destinationDS.getSelectedItem().SelectedObject, selectedValue);

            done();
        });
    });

    it('should not set selected item if dialog result is cancel', function (done) {
        // Given
        // todo: выяснить почему, если вынести viewMetadata из этого и предыдущего тестов, то они работают с одной и той же view
        var viewMetadata = {
            "Text": 'Parent View',
            "DataSources": [
                {
                    "ObjectDataSource": {
                        "Name": "ObjectDataSource",
                        "IsLazy": false,
                        "Items": [
                            {
                                SelectedObject: "empty"
                            }
                        ]
                    }
                }
            ],
            "Items": [{
                "Button": {
                    "Name": "SelectButton",
                    "Action": {
                        "SelectAction": {
                            "DestinationValue": {
                                "Source": "ObjectDataSource",
                                "Property": "$.SelectedObject"
                            },
                            "SourceValue": {
                                "Source": "MainDataSource",
                                "Property": "$"
                            },
                            "LinkView": {
                                "InlineView": {
                                    "OpenMode": "Dialog",
                                    "View": {
                                        "Name": "SelectView",
                                        "DataSources": [
                                            {
                                                "ObjectDataSource": {
                                                    "Name": "MainDataSource",
                                                    "IsLazy": false,
                                                    "Items": [
                                                        {
                                                            "Name": "first"
                                                        },
                                                        {
                                                            "Name": "second"
                                                        }
                                                    ]
                                                }
                                            }
                                        ],
                                        "Items": [
                                            {
                                                "Button": {
                                                    "Name": "AcceptBtn",
                                                    "Action": {
                                                        "AcceptAction": {
                                                        }
                                                    }
                                                }
                                            }
                                        ]
                                    }
                                }
                            }
                        }
                    }
                }
            }]
        };

        testHelper.applyViewMetadata(viewMetadata, function(view){
            var selectBtn = view.context.controls['SelectButton'];
            var destinationDS = view.context.dataSources['ObjectDataSource'];

            assert.equal(destinationDS.getSelectedItem().SelectedObject, "empty");

            // When
            selectBtn.click();

            var childView = view.context.controls['SelectView'];
            var sourceDS = childView.context.dataSources['MainDataSource'];
            var acceptBtn = childView.context.controls['AcceptBtn'];

            var selectedValue = sourceDS.getItems()[1];
            sourceDS.setSelectedItem(selectedValue);

            childView.close();

            // Then
            assert.equal(destinationDS.getSelectedItem().SelectedObject, "empty");

            done();
        });
    });
});
{'fraction_non_alphanumeric': 0.08244734202607823, 'fraction_numerical': 0.0006018054162487463, 'mean_word_length': 0.5794392523364486, 'pattern_counts': {'":': 68, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 108, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5916891', 'n_tokens_mistral': 1693, 'n_tokens_neox': 1602, 'n_words': 304}