'Scenario: Ensure that validation of the group configuration works correctly.
Given I have a course without group configurations
And I create new group configuration with 2 default groups
When I set only description and try to save
Then I see error message "Group Configuration name is required."
When I set a name
And I delete the name of one of the groups and try to save
Then I see error message "All groups must have a name"
When I delete all the groups and try to save
Then I see error message "There must be at least one group."
When I add a group and try to save
Then I see the group configuration is saved successfully'

def test_group_configuration_validation(self):

    def try_to_save_and_verify_error_message(message):
        config.save()
        self.assertEqual(config.mode, 'edit')
        self.assertEqual(message, config.validation_message)
    self.page.visit()
    self.page.create_experiment_group_configuration()
    config = self.page.experiment_group_configurations[0]
    config.description = 'Description    of    the    group    configuration.'
    try_to_save_and_verify_error_message('Group    Configuration    name    is    required.')
    config.name = 'Name    of    the    Group    Configuration'
    config.groups[1].name = ''
    try_to_save_and_verify_error_message('All    groups    must    have    a    name.')
    config.groups[0].remove()
    config.groups[0].remove()
    try_to_save_and_verify_error_message('There    must    be    at    least    one    group.')
    config.add_group()
    config.save()
    self._assert_fields(config, name='Name    of    the    Group    Configuration', description='Description    of    the    group    configuration.', groups=['Group    A'])
