Feature: SpecificationManager
As admin
I can create Specifications

@auth @createorganisation_site @deleteorganisation @deleteform @logout
Scenario: Creating and Updating new Specification and then check Audit logs
	Given I create a Glossary
		| Name                |
		| TestColoursGlossary |
	And I create a Glossary Item
		| Name                           |
		| TestBlackGlossaryItemDifferent |
		| TestBlackGlossaryItem          |
	And I create a CustomField
		| Name          | FieldType | Glossary              | MaxEntries |
		| TestColoursCF | Glossary  | TestBlackGlossaryItem | 1          |
	And I create a FormTemplate
		| Name                    | NeedTable | TotalNumberOfColumns | TotalNumberOfRows | CustomFields | Text     | RowNumber | ColumnNumber |
		| TestColoursFormTemplate | true      | 2                    | 1                 | Glossary     |          | 1         | 2            |
		|                         |           |                      |                   |              | Glossary | 1         | 1            |
	When I added a Form Template into the Print Specifications
		| Name                        |
		| TestPrintSpecificationsForm |
	Then I create a Specification
		| Name                     | OrganisationName | SiteName        | PrintSpecification          | SpecificationItems | ItemValue       |
		| TestColoursSpecification | TestColoursOrg   | TestColoursSite | TestPrintSpecificationsForm | Glossary           | defaultGlossary |
	And I check Specification Audit logs
		| Timing | UserName | Comment | EntityDisplayName | Type   | DisplayName                 | Changes |
		|        |          |         |                   | Create | formNameFromScenarioContext |         |
	And I check Form Field Instance Audit logs
		| Timing | UserName | Comment | EntityDisplayName | Type   | DisplayName                              | Changes |
		|        |          |         |                   | Create | formFieldInstanceNameFromScenarioContext |         |
	And I edit a Specification
		| Name                           | SpecificationItems | ItemValue                      |
		| EditedTestCploursSpecification | Glossary           | TestBlackGlossaryItemDifferent |
	And I check Specification Audit logs
		| Timing | UserName | Comment | EntityDisplayName | Type   | DisplayName                 | Changes |
		|        |          |         |                   | Update | formNameFromScenarioContext |         |

	And I check Form Field Instance Audit logs
		| Timing | UserName | Comment | EntityDisplayName | Type   | DisplayName                              | Changes |
		|        |          |         |                   | Update | formFieldInstanceNameFromScenarioContext |         |


@auth @createdomain @createorganisation_site @createsequence @deleteorganisation @deletedomain @deleteform @logout
Scenario: Creating and deleting new Specification contains all custom fields
	Given I create a Glossary
		| Name                |
		| TestColoursGlossary |
	And I create a Glossary Item
		| Name                  |
		| TestBlackGlossaryItem |
	And I create a CustomField
		| Name          | FieldType | Glossary              | MaxEntries |
		| TestColoursCF | Glossary  | TestBlackGlossaryItem | 1          |
	And I create a CustomField
		| Name         | FieldType | MaxEntries | Required | MaxEntries |
		| TestCFDomain | Domain    | 1          | true     | 1          |
	And I create a CustomField
		| Name       | FieldType | DefaultValue | MultiLine |
		| TestCFText | Text      | Default Text | true      |
	And I create a CustomField
		| Name         | FieldType | DefaultValue | MinimumValue | MaximumValue | Step | Required |
		| TestCFNumber | Number    | 1            | 1            | 999          | 2    | true     |
	And I create a CustomField
		| Name    | FieldType | DefaultValue | Sequence     | Glossary |
		| TestCFS | Sequence  |              | sequenceName |          |
	And I create a CustomField
		| Name                | FieldType     |
		| TestCFForm Template | Form Template |
	And I create a FormTemplate
		| Name                         | NeedTable | TotalNumberOfColumns | TotalNumberOfRows | CustomFields | Text          | RowNumber | ColumnNumber | ChildFormName |
		| Form to use in specification | true      | 2                    | 2                 | Text         |               | 1         | 2            | contextName   |
		|                              |           |                      |                   |              | Field for E2E | 1         | 1            |               |
	And I create a FormTemplate
		| Name                    | NeedTable | TotalNumberOfColumns | TotalNumberOfRows | CustomFields  | Text          | RowNumber | ColumnNumber |
		| TestColoursFormTemplate | true      | 2                    | 6                 | Glossary      |               | 1         | 2            |
		|                         |           |                      |                   | Domain        |               | 2         | 2            |
		|                         |           |                      |                   | Sequence      |               | 3         | 2            |
		|                         |           |                      |                   | Text          |               | 4         | 2            |
		|                         |           |                      |                   | Number        |               | 5         | 2            |
		|                         |           |                      |                   | Form Template |               | 6         | 2            |
		|                         |           |                      |                   |               | Glossary      | 1         | 1            |
		|                         |           |                      |                   |               | Domain        | 2         | 1            |
		|                         |           |                      |                   |               | Sequence      | 3         | 1            |
		|                         |           |                      |                   |               | Text          | 4         | 1            |
		|                         |           |                      |                   |               | Number        | 5         | 1            |
		|                         |           |                      |                   |               | Form Template | 6         | 1            |
	When I added a Form Template into the Print Specifications
		| Name                        |
		| TestPrintSpecificationsForm |
	Then I create a Specification
		| Name                     | OrganisationName | SiteName        | PrintSpecification          | SpecificationItems | ItemValue                      |
		| TestColoursSpecification | TestColoursOrg   | TestColoursSite | TestPrintSpecificationsForm | Glossary           | defaultGlossary                |
		|                          |                  |                 |                             | Domain             | default                        |
		|                          |                  |                 |                             | Sequence           | Sequnce linked                 |
		|                          |                  |                 |                             | Text               | Free text field or description |
		|                          |                  |                 |                             | Number             | 21                             |
		|                          |                  |                 |                             | Form Template      | defaultTemplate                |
	And I check data on Specification
		| SpecificationItems | ItemValue               |
		| Glossary           | dataFromScenarioContext |
		| Domain             | dataFromScenarioContext |
		| Sequence           | dataFromScenarioContext |
		| Text               | dataFromScenarioContext |
		| Number             | 21                      |
		| Form Template      | dataFromScenarioContext |
	And new Specification is present on the list
	When I delete existing Specification
	Then new Specification is not present on the list
	And I check Specification Audit logs
		| Timing | UserName | Comment | EntityDisplayName | Type   | DisplayName                 | Changes |
		|        |          |         |                   | Delete | formNameFromScenarioContext |         |

#Bug 72982 uncomment after fix
@auth @createdomain @createsequence @createorganisation_site @deletedomain @deleteorganisation @deleteform @logout
Scenario: Creating a new Specification contains custom fields with default or null values
	Given I create a Glossary
		| Name                |
		| TestColoursGlossary |
	And I create a Glossary Item
		| Name                  |
		| TestBlackGlossaryItem |
	And I create a CustomField
		| Name          | FieldType | Glossary              | MaxEntries |
		| TestColoursCF | Glossary  | TestBlackGlossaryItem | 1          |
	And I create a CustomField
		| Name         | FieldType | MaxEntries | Required | MaxEntries |
		| TestCFDomain | Domain    | 1          | false    | 1          |
	And I create a CustomField
		| Name       | FieldType | DefaultValue | MultiLine |
		| TestCFText | Text      |              | false     |
	#And I create a CustomField
	#	| Name         | FieldType | DefaultValue | MinimumValue | MaximumValue | Step | Required |
	#	| TestCFNumber | Number    | 1            | 1            | 999          | 2    | true     |
	And I create a CustomField
		| Name    | FieldType | DefaultValue | Sequence     | Glossary |
		| TestCFS | Sequence  |              | sequenceName |          |
	And I create a CustomField
		| Name                | FieldType     |
		| TestCFForm Template | Form Template |
	And I create a FormTemplate
		| Name                         | NeedTable | TotalNumberOfColumns | TotalNumberOfRows | CustomFields | Text          | RowNumber | ColumnNumber | ChildFormName |
		| Form to use in specification | true      | 2                    | 2                 | Text         |               | 1         | 2            | contextName   |
		|                              |           |                      |                   |              | Field for E2E | 1         | 1            |               |
	And I create a FormTemplate
		| Name                    | NeedTable | TotalNumberOfColumns | TotalNumberOfRows | CustomFields  | Text          | RowNumber | ColumnNumber |
		| TestColoursFormTemplate | true      | 2                    | 6                 | Glossary      |               | 1         | 2            |
		|                         |           |                      |                   | Domain        |               | 2         | 2            |
		|                         |           |                      |                   | Sequence      |               | 3         | 2            |
		|                         |           |                      |                   | Text          |               | 4         | 2            |
		|                         |           |                      |                   | Form Template |               | 6         | 2            |
		|                         |           |                      |                   |               | Glossary      | 1         | 1            |
		|                         |           |                      |                   |               | Domain        | 2         | 1            |
		|                         |           |                      |                   |               | Sequence      | 3         | 1            |
		|                         |           |                      |                   |               | Text          | 4         | 1            |
		|                         |           |                      |                   |               | Form Template | 6         | 1            |
#		|                         |           |                      |                   | Number        |               | 5         | 2            |
#		|                         |           |                      |                   |               | Number        | 5         | 1            |
	When I added a Form Template into the Print Specifications
		| Name                        |
		| TestPrintSpecificationsForm |
	Then I create a Specification
		| Name                     | OrganisationName | SiteName        | PrintSpecification          | SpecificationItems | ItemValue       |
		| TestColoursSpecification | TestColoursOrg   | TestColoursSite | TestPrintSpecificationsForm | Glossary           |                 |
		|                          |                  |                 |                             | Domain             |                 |
		|                          |                  |                 |                             | Sequence           | Sequnce linked  |
		|                          |                  |                 |                             | Text               |                 |
		|                          |                  |                 |                             | Form Template      | defaultTemplate |
#		|                          |                  |                 |                             | Number             |                 |
	And I check data on Specification
		| SpecificationItems | ItemValue               |
		| Glossary           |                         |
		| Domain             |                         |
		| Sequence           | dataFromScenarioContext |
		| Text               |                         |
		| Form Template      | dataFromScenarioContext |
#		| Number             |           |

@auth @createorganisation_site @deleteorganisation @deleteform @logout
Scenario: Creating and deleting new Specification contains Gloassary custom field with empty default value and field is required
	Given I create a Glossary
		| Name                |
		| TestColoursGlossary |
	And I create a Glossary Item
		| Name                  |
		| TestBlackGlossaryItem |
	And I create a CustomField
		| Name          | FieldType | Glossary              | MaxEntries | Required |
		| TestColoursCF | Glossary  | TestBlackGlossaryItem |            | true     |
	And I create a FormTemplate
		| Name                     | NeedTable | TotalNumberOfColumns | TotalNumberOfRows | CustomFields | Text     | RowNumber | ColumnNumber |
		| TestColoursFormTemplate1 | true      | 2                    | 1                 | Glossary     |          | 1         | 2            |
		|                          |           |                      |                   |              | Glossary | 1         | 1            |
	When I added a Form Template into the Print Specifications
		| Name                         |
		| TestPrintSpecificationsForm1 |
	And I can not create a Specification with required fields and empty value
		| Name                      | OrganisationName | SiteName        | PrintSpecification          | SpecificationItems | ItemValue |
		| TestColoursSpecification2 | TestColoursOrg   | TestColoursSite | TestPrintSpecificationsForm | Glossary           |           |
	Then Error toast message is present
		| Message                             |
		| Request failed with status code 400 |
		| Failed to save form instance        |
	When I create a Specification
		| Name                      | OrganisationName | SiteName        | PrintSpecification          | SpecificationItems | ItemValue       |
		| TestColoursSpecification3 | TestColoursOrg   | TestColoursSite | TestPrintSpecificationsForm | Glossary           | defaultGlossary |
	Then new Specification is present on the list

@auth @createorganisation_site @createdomain @deleteorganisation @deleteform @logout
Scenario: Creating and deleting new Specification contains Form Template custom field with empty default value and field is required
	Given I create a CustomField
		| Name       | FieldType | DefaultValue | MultiLine |
		| TestCFText | Text      |              | false     |
	And I create a CustomField
		| Name                | FieldType     |
		| TestCFForm Template | Form Template |
	And I create a FormTemplate
		| Name                         | NeedTable | TotalNumberOfColumns | TotalNumberOfRows | CustomFields | Text          | RowNumber | ColumnNumber | ChildFormName |
		| Form to use in specification | true      | 2                    | 2                 | Text         |               | 1         | 2            | contextName   |
		|                              |           |                      |                   |              | Field for E2E | 1         | 1            |               |
	And I create a FormTemplate
		| Name                     | NeedTable | TotalNumberOfColumns | TotalNumberOfRows | CustomFields  | Text          | RowNumber | ColumnNumber |
		| TestColoursFormTemplate1 | true      | 2                    | 1                 | Form Template |               | 1         | 2            |
		|                          |           |                      |                   |               | Form Template | 1         | 1            |
	When I added a Form Template into the Print Specifications
		| Name                         |
		| TestPrintSpecificationsForm1 |
	And I can not create a Specification with required fields and empty value
		| Name                      | OrganisationName | SiteName        | PrintSpecification          | SpecificationItems | ItemValue |
		| TestColoursSpecification2 | TestColoursOrg   | TestColoursSite | TestPrintSpecificationsForm | Form Template      |           |
	Then Error toast message is present
		| Message                             |
		| Request failed with status code 400 |
		| Failed to save form instance        |
	When I create a Specification
		| Name                      | OrganisationName | SiteName        | PrintSpecification          | SpecificationItems | ItemValue       |
		| TestColoursSpecification3 | TestColoursOrg   | TestColoursSite | TestPrintSpecificationsForm | Form Template      | defaultTemplate |
	Then new Specification is present on the list

@auth @createorganisation_site @createdomain @deleteorganisation @deletedomain @deleteform @logout
Scenario Outline: Creating a new Specification with custom field with empty default value and field is required
	Given I create a CustomField
		| Name         | FieldType     | MaxEntries | Required | DefaultValue | MinimumValue | MaximumValue | Step |
		| TestCFDomain | <CustomField> | 1          | true     |              | 1            | 999          | 2    |
	And I create a FormTemplate
		| Name                     | NeedTable | TotalNumberOfColumns | TotalNumberOfRows | CustomFields  | Text          | RowNumber | ColumnNumber |
		| TestColoursFormTemplate1 | true      | 2                    | 1                 | <CustomField> |               | 1         | 2            |
		|                          |           |                      |                   |               | <CustomField> | 1         | 1            |
	When I added a Form Template into the Print Specifications
		| Name                         |
		| TestPrintSpecificationsForm1 |
	And I can not create a Specification with required fields and empty value
		| Name                      | OrganisationName | SiteName        | PrintSpecification          | SpecificationItems | ItemValue |
		| TestColoursSpecification2 | TestColoursOrg   | TestColoursSite | TestPrintSpecificationsForm | <CustomField>      |           |
	Then Error toast message is present
		| Message                             |
		| Request failed with status code 400 |
		| Failed to save form instance        |
	When I create a Specification
		| Name                      | OrganisationName | SiteName        | PrintSpecification          | SpecificationItems | ItemValue   |
		| TestColoursSpecification3 | TestColoursOrg   | TestColoursSite | TestPrintSpecificationsForm | <CustomField>      | <ItemValue> |
	Then new Specification is present on the list
Examples:
	| CustomField | ItemValue |
	| Domain      | default   |
	| Number      | 21        |

@auth @createorganisation_site @deleteorganisation @deletedomain @deleteform @logout
Scenario: Creating a new Specification contains Domain custom field MULTISELECT with empty default value and field is required
	Given I create a new domain via API
		| Name        |
		| DomainTest1 |
		| DomainTest2 |
		| DomainTest3 |
	And I create a CustomField
		| Name         | FieldType | MaxEntries | Required |
		| TestCFDomain | Domain    | 2          | true     |
	And I create a FormTemplate
		| Name                     | NeedTable | TotalNumberOfColumns | TotalNumberOfRows | CustomFields | Text   | RowNumber | ColumnNumber |
		| TestColoursFormTemplate1 | true      | 2                    | 1                 | Domain       |        | 1         | 2            |
		|                          |           |                      |                   |              | Domain | 1         | 1            |
	When I added a Form Template into the Print Specifications
		| Name                         |
		| TestPrintSpecificationsForm1 |
	And I can not create a Specification with required fields and empty value
		| Name                      | OrganisationName | SiteName        | PrintSpecification          | SpecificationItems | ItemValue |
		| TestColoursSpecification2 | TestColoursOrg   | TestColoursSite | TestPrintSpecificationsForm | Domain             |           |
	Then Error toast message is present
		| Message                             |
		| Request failed with status code 400 |
		| Failed to save form instance        |
	And new Specification is not present on the list
	When I can not create a Specification with required fields and empty value
		| Name                      | OrganisationName | SiteName        | PrintSpecification          | SpecificationItems | ItemValue | MultiselectField | NumberOfItems |
		| TestColoursSpecification3 | TestColoursOrg   | TestColoursSite | TestPrintSpecificationsForm | Domain             | default   | true             | 3             |
	Then Error toast message is present
		| Message                             |
		| Request failed with status code 400 |
		| Failed to save form instance        |
	And new Specification is not present on the list
	When I create a Specification
		| Name                      | OrganisationName | SiteName        | PrintSpecification          | SpecificationItems | ItemValue | MultiselectField | NumberOfItems |
		| TestColoursSpecification3 | TestColoursOrg   | TestColoursSite | TestPrintSpecificationsForm | Domain             | default   | true             | 2             |
	Then new Specification is present on the list
	
@auth @createorganisation_site @deleteorganisation @deleteform @logout
Scenario: Creating a new Specification contains Gloassary custom field MULTISELECT with empty default value and field is required
	Given I create a Glossary
		| Name                |
		| TestColoursGlossary |
	And I create a Glossary Item
		| Name                   |
		| TestBlackGlossaryItem1 |
		| TestBlackGlossaryItem2 |
		| TestBlackGlossaryItem3 |
	And I create a CustomField
		| Name          | FieldType | Glossary              | MaxEntries | Required |
		| TestColoursCF | Glossary  | TestBlackGlossaryItem | 2          | true     |
	And I create a FormTemplate
		| Name                     | NeedTable | TotalNumberOfColumns | TotalNumberOfRows | CustomFields | Text     | RowNumber | ColumnNumber |
		| TestColoursFormTemplate1 | true      | 2                    | 1                 | Glossary     |          | 1         | 2            |
		|                          |           |                      |                   |              | Glossary | 1         | 1            |
	When I added a Form Template into the Print Specifications
		| Name                         |
		| TestPrintSpecificationsForm1 |
	And I can not create a Specification with required fields and empty value
		| Name                      | OrganisationName | SiteName        | PrintSpecification          | SpecificationItems | ItemValue |
		| TestColoursSpecification2 | TestColoursOrg   | TestColoursSite | TestPrintSpecificationsForm | Glossary           |           |
	Then Error toast message is present
		| Message                             |
		| Request failed with status code 400 |
		| Failed to save form instance        |
	And I can not create a Specification with required fields and empty value
		| Name                      | OrganisationName | SiteName        | PrintSpecification          | SpecificationItems | ItemValue       | MultiselectField | NumberOfItems |
		| TestColoursSpecification2 | TestColoursOrg   | TestColoursSite | TestPrintSpecificationsForm | Glossary           | defaultGlossary | true             | 3             |
	And Error toast message is present
		| Message                             |
		| Request failed with status code 400 |
		| Failed to save form instance        |
	When I create a Specification
		| Name                      | OrganisationName | SiteName        | PrintSpecification          | SpecificationItems | ItemValue       | MultiselectField | NumberOfItems |
		| TestColoursSpecification3 | TestColoursOrg   | TestColoursSite | TestPrintSpecificationsForm | Glossary           | defaultGlossary | true             | 2             |
	Then new Specification is present on the list