# Manual Integration Test: Message Handling in Sales Orders Application (V2)

## DESCRIPTION

Test message handling in the OData V2 Model with the Sales Orders application.

## PREPARATION

To check console errors open the developer tools before starting the application and check with each step, that there are no errors and warnings.

### Testing with back end

Configure your IDE to be able to execute the Sales Orders application against an ABAP back end system.
Depending on your installation, you have to replace the port 8080 of all following links to the port of your local server hosting the Sales Orders application.
It might also be necessary to remove the first URL segment `/testsuite` from the following URLs depending on your development setup.
Start the Sales Orders V2 application with English locale:

- http://localhost:8080/testsuite/test-resources/sap/ui/core/internal/samples/odata/v2/SalesOrders/index.html?sap-language=en&realOData=true

### Testing with mock data

Configure your IDE to be able to execute the Sales Orders application locally or use a centrally deployed version of the Sales Orders application as provided by the test coordinator.
Depending on your installation, you have to replace the port 8080 of all following links to the port of your local server hosting the Sales Orders application.
It might also be necessary to remove the first URL segment `/testsuite` from the following URLs depending on your development setup.
Start the Sales Orders V2 application with English locale:

- http://localhost:8080/testsuite/test-resources/sap/ui/core/internal/samples/odata/v2/SalesOrders/index.html?sap-language=en

The service implementation does some checks which produce messages.

#### Checks for a Sales Order

- If the note of the sales order is empty the service returns a warning message for that sales order note to enter a note.
- If the note of the sales order has a prefix "Error:", "Warning:", "Info:" or "Success:" then the service returns a message for that note with the corresponding message severity and the message text as given in the note after the ":".

#### Checks for a Sales Order Item

- If the note of the sales order item is empty the service returns a warning message for that sales order item note to enter a note.
- If the note of the sales order item has a prefix "Error:", "Warning:", "Info:" or "Success:" then the service returns a message for that sales order item note with the corresponding message severity and the message text as given in the note after the ":".
- If the quantity of the sales order item is 0 then the service returns an error message for that quantity indicating that the quantity must not be 0.
- If the quantity of the sales order item is 1 for the product HT-1000 then the service returns a warning message for that quantity indicating that the quantity must be at least 2.
- If the quantity of the sales order item is greater than 1 for the product HT-1022 then the service returns a multi target warning message which points simultaneously to the quantity and the note field until the note has a "Reason:" prefix.
- If the product of the sales order item is HT-1110 then the service returns a warning message for the product ID of the associated product (using the target `ToProduct/ProductID`) indicating that the product is out of maintenance.
- If the product of the sales order item is HT-1501, the service returns an information message for the currency of that sales order item indicating that the currency 'JPY' should be avoided.

### Finding a Sales Order

To find a sales order that can be used for testing, you can either use the OData V4 Sales Orders application or you can trigger a service request.

#### Via OData V4 Application

Start the OData V4 Sales Orders application:

- http://localhost:8080/testsuite/test-resources/sap/ui/core/demokit/sample/common/index.html?component=odata.v4.SalesOrders&realOData=true&sap-language=en

In that application you can search for a sales order or you can create your own one that is matching the requirements for the test.

#### Via OData Service Calls

Execute for example following URL:

- http://localhost:8080/testsuite/proxy/sap/opu/odata/sap/ZUI5_GWSAMPLE_BASIC/SalesOrderSet?$select=SalesOrderID,Note,ToLineItems/ItemPosition,ToLineItems/ProductID,ToLineItems/Quantity,ToLineItems/Note&$expand=ToLineItems&$top=20&$inlinecount=allpages&$format=json

You get a JSON for the first 20 sales orders.
Copy the resulting JSON and paste it into the console of the Chrome Developer Tools and press enter. You can drill down into the data to find a Sales Order that is matching the requirements for the test.
If there is no matching sales order you can add `&$skip=` followed by a start index, e.g. `&$skip=40`, to the URL to get another set of sales orders.

## REALIZE and CHECK

### (I) Messages for Note Fields

Search for a sales order with at least 1 item and note down the sales order ID. In case of mock data: Use sales order `101`.

1. Enter that sales order ID into the `Sales Order` input field and press `Enter` or click the `Show Sales Order` button.
   Check: The sales order and the sales order items are loaded and displayed in the `Sales Order Details` section.
2. Remember the number of messages displayed on the `Show Messages` button in the footer of the application.
3. Repeat the next steps with following values for the note:
   - `Error: My error message`
   - `Warning: My warning message`
   - `Info: My information message`
   - `Success: My success message`
   1. Go to a sales order item without messages and change the `Note` to the value above and press the `Save` button in the footer.
      Check: The number of messages has been increased by 1.
      Check: The border of the sales order item's note field has a border indicating the corresponding severity of the message.
      Check: When clicking into the sales order item's note field, the message text (i.e. the text as entered after the ":") is shown.
      Check: The table row is highlighted with the same color as the border of the sales order item's note input field.
   2. Click the `Show Messages` button.
      Check: A popover is displayed with the current messages.
      Check: The message popover contains an entry with the message text as described above.
   3. Click into the modified sales order item's note input field, change the text to `No message` and press the `Save` button.
      Check: The number of messages has been decreased by 1.
      Check: The message has been removed from the message popover.

### (II) Message Strip and Aggregated Table Row Highlighting

Search for a sales order with at least 2 items and with at least one item for the product `HT-1000` and note down the sales order ID. An item for the product `HT-1110` should not be contained. In case of mock data: Use sales order `102`.

1. Enter that sales order ID into the `Sales Order` input field and press `Enter` or click the `Show Sales Order` button.
   Check: The sales order and the sales order items are loaded and displayed in the `Sales Order Details` section.
2. Change the note value of the items in a way that the service returns a message for that note (see (I) Messages for Note Fields) and save the changes.
   Check: If there is at least one message for an item, a message strip is displayed above the table indicating that there are messages for items.
   Check: Depending on the severity of the messages (`Error`, `Warning`, `Success` or `Information`) the message strip of the table changes its text, icon and color.
3. If there is more than one message for a sales order item the highest severity is used for the row highlighting. Change the quantity of a sales order item with the product `HT-1000` to the value `1` and save it.
   Check: There is a message for the quantity of the item that at least 2 have to be ordered.
   Check: If the corresponding note field does not start with `Error:` the row highlighter indicates a warning.
4. Change the note of that sales order item to `Error: My error message` and save.
   Check: There is an error message for the note field and the row highlighter indicates an error.

Search for a sales order with an item for the product `HT-1110` and note down the sales order ID. In case of mock data: Use sales order `102.2`.

1. Enter that sales order ID into the `Sales Order` input field and press `Enter` or click the `Show Sales Order` button.
   Check: The sales order and the sales order items are loaded and displayed in the `Sales Order Details` section.
2. If the item shows an error for the note, remove the prefix `Error:`, `Warning:`, `Info:` or `Success:` and save.
   Check: The table row is still marked with a warning because the associated product is out of maintenance.

### (III) Message Lifecycle - Side-Effects

Search for a sales order with more than 4 items and with three items for the product `HT-1000` with a quantity less than 2. Two of these items are in the visible area an the third is at the 5th (or later) position in the sales order. Note down the sales order ID. In case of mock data: Use sales order `103`.

1. Enter that sales order ID into the `Sales Order` input field and press `Enter` or click the `Show Sales Order` button.
   Check: The sales order and the sales order items are loaded and displayed in the `Sales Order Details` section.
   Check: For all three items for product `HT-1000` with a quantity less than 2, there are warnings that at least `2 EA` of that product has to be ordered.
   Check: The visible table rows with product `HT-1000` are marked with a warning because the quantity is less than 2.
   Check: Remember the number of messages.
2. Press the `Fix Quantities` button.
   Check: The number of messages has not changed.
   Check: The `Quantity` value of the table rows with product `HT-1000` has been changed to the value `2`.
   Check: The visible table rows with product `HT-1000` are marked with a success because the quantity is updated to 2.
3. Scroll to the end of the sales order line items table.
   Check: All items for `HT-1000` have at least a quantity of 2.
   Check: The visible table rows with product `HT-1000` are marked with a success because the quantity is updated to 2.
4. Open the message popover.
   Check: The previous warning messages are disappeared.
   Check: There are three messages that the quantity has been successfully updated.
5. Close the message popover.
   Check: The number of messages has been decreased by 3.

### (IV) Transition Messages Only

If a table is embedded into an object page, all messages for the table need to be displayed. If the application starts with a table, only the messages for the table rows which are on the client have to be displayed. The framework is not able to detect these scenarios automatically, so the application has to set the `transitionMessagesOnly` parameter at the list binding:

- `transitionMessagesOnly=true`:
  The root entity of the object page handles messages and the list binding for the table does not take care of messages. This scenario has been tested above.
- `transitionMessagesOnly=false`:
  The binding for the table takes care of messages. This scenario is tested with this test.

Search for a sales order with at least 5 items and note down the sales order ID. In case of mock data: Use sales order `104`.

1. Enter that sales order ID into the `Sales Order` input field and press `Enter` or click the `Show Sales Order` button.
   Check: The sales order and the sales order items are loaded and displayed in the `Sales Order Details` section.
2. Change the note value of the first item in a way that the service returns a message for that note (see (I) Messages for Note Fields) and save the changes.
3. Change the note value of the 5th item in a way that the service returns a message for that note (see (I) Messages for Note Fields) and save the changes.
4. Remember the number of messages for that sales order.
5. Scroll to the top of the table and press the `Transition Messages Only` button to disable that feature.
   Check: The sales order and the sales order items are reloaded and the number of messages is less than before.
   Check: The message for the 5th item is not contained in the message popover.
6. Scroll in the table that the 5th item is requested.
   Check: The number of messages increases.
   Check: The message for the 5th item is contained in the message popover.

### (V) Filter Sales Order Items by Items with Messages

Search for a sales order with items with and without messages. The messages should have a different message severity. In case of mock data: Use sales order `105`.

1. Enter that sales order ID into the `Sales Order` input field and press `Enter` or click the `Show Sales Order` button.
   Check: The sales order and the sales order items are loaded and displayed in the `Sales Order Details` section.
   Check: There are items with and without messages.
2. Change the `Filter` value in the `Sales Order Items` table from `Show all` to any other value.
   Check: Only items that match the selected filter are displayed.
   Check: If there is no item matching the selected filter, you get a message box with the information, that no item matches. The filter for the table has been changed back to `Show all`.
3. Repeat the steps above with different filter values.

### (VI) Create and Delete Sales Order Items

Search for a sales order with at most two items. In case of mock data: Use sales order `106`.

1. Enter that sales order ID into the `Sales Order` input field and press `Enter` or click the `Show Sales Order` button.
   Check: The sales order and the sales order items are loaded and displayed in the `Sales Order Details` section.
   Check: Remember the number of messages.
2. In the `Sales Order Items` table click on the `Create a sales order item` button.
   Check: A `Create a New Sales Order Item` dialog opens.
3. In the `Create a New Sales Order Item` dialog remove the value of the `Product ID` field and press the `Save` button.
   Check: A message box is displayed indicating that the mandatory field 'PRODUCT_GUID' is empty.
4. Close the error message box.
   Check: The `Create a New Sales Order Item` dialog is still open.
5. In the `Create a New Sales Order Item` dialog click the `Discard` button.
   Check: The `Create a New Sales Order Item` dialog is closed.
6. Remember the `Gross Amount` and the `Changed At` data from the `Sales Order` section.
7. Repeat the steps (2) - (4).
8. In the `Create a New Sales Order Item` dialog enter `HT-1000` in the `Product ID` field, remove the content of the `Note` field and press the `Save` button.
   Check: A success message box is displayed with the information, that the item has been created. Confirm that message box.
   Check: The newly created item is displayed in the `Sales Order Items` table.
   Check: The `Gross Amount` and the `Changed At` values are updated.
   Check: There are two new messages in the message popover, one for the quantity which has to be at least 2 and one for the missing note of the new sales order item.
9. Only with back end: Open the developer tools, navigate to the network tab, clear the requests and filter for `$batch` requests.
10. In the `Sales Order Items` table click on the `>` at the end of the row for the newly created entity to open the product details.
    Check: A `Product Details` dialog is opened showing the `Product ID` and the corresponding product `Name`.
    Only with back end: Check: There is no `$batch` request.
11. Close the `Product Details` dialog.
12. In the `Sales Order Items` table select the newly created item and press the `Delete the selected sales order item` button.
    Check: A `Sales Order Item Deletion` dialog opens.
13. In the `Sales Order Item Deletion` dialog click on the `OK` button.
    Check: The `Sales Order Item Deletion` dialog is closed and a message toast is displayed with the information, that the deletion was successful.
    Check: The deleted item has been removed from the `Sales Order Items` table.
    Check: The `Gross Amount` and the `Changed At` values are updated.
    Check: The messages for the deleted item have been removed from the message popover.

### (VII) Unbound Messages

Search for a sales order with an ID less than `0500000010`. In case of mock data: Use sales order `107`.

1. Enter that sales order ID into the `Sales Order` input field and press `Enter` or click the `Show Sales Order` button.
   Check: The sales order and the sales order items are loaded and displayed in the `Sales Order Details` section.
2. Open the message popover.
   Check: There is a message `System maintenance starts in 2 hours`.
3. Navigate to the message details and click on `Technical Details` link to open the `Message Details` dialog.
   Check: The values for `Target` and `Full Target` are empty.
4. Close the `Message Details` dialog and close the message popover.
   Check: The number of messages has been decreased and the message is no longer listed in the message popover.

### (VIII) Messages with multiple Targets

Search for a sales order with an item for the product `HT-1022`. In case of mock data: Use sales order `108`.

1. Enter that sales order ID into the `Sales Order` input field and press `Enter` or click the `Show Sales Order` button.
   Check: The sales order and the sales order items are loaded and displayed in the `Sales Order Details` section.
2. Change the `Quantity` value of the item with product `HT-1022` to the value `1`, set its `Note` to `No message` and save it.
   Check: There are no messages for the modified sales order item.
   Check: Remember the number of messages.
3. Change the modified sales order item's `Quantity` value to `2` and save it.
   Check: The number of messages has been increased by 1.
   Check: The fields of the sales order item's `Quantity` and also the `Note` have borders indicating the warning `For a quantity greater than 1 you need an approval reason`.
4. Open the message popover.
   Check: There is exactly one warning with the message `For a quantity greater than 1 you need an approval reason` for that item.
5. Navigate to the message details and click on `Technical Details` link to open the `Message Details` dialog.
   Check: The values for `Target` and `Full Target` contain each two different paths.
6. Close the `Message Details` dialog and close the message popover. Change the modified sales order item's `Note` value by adding the prefix `"Reason:"` and save it.
   Check: The `Quantity` and the `Note` fields do not have a warning border indicator anymore.
   Check: The number of messages has been decreased by 1.
   Check: The message has been removed from the message popover.

### (IX) Messages returned from a function import

Search for a sales order with an item for the product `HT-1000`. In case of mock data: Use sales order `109`.

1. Enter that sales order ID into the `Sales Order` input field and press `Enter` or click the `Show Sales Order` button.
   Check: The sales order and the sales order items are loaded and displayed in the `Sales Order Details` section.
   Check: Remember the number of messages.
2. Change the `Quantity` value of the item with product `HT-1000` to the value `1` and save it.
   Check: The number of messages has been increased by 1.
   Check: There is a warning message for the quantity of the item that at least 2 have to be ordered.
3. Make sure that the message popover is closed and press the `Fix` button in the item's row.
   Check: The `Quantity` value has been changed to the value `2`.
   Check: The number of messages has not changed.
   Check: The previous warning message has disappeared.
   Check: There is a new message that the quantity has been successfully updated.
4. Close the message popover.
   Check: The number of messages has been decreased by 1.
   Check: The new message of the last step has been removed from the message popover.

### (X) Suppress messages for the currency code if the code is not displayed by the control

Search for a sales order with an item for the product `HT-1501`. In case of mock data: Use sales order `110`.

1. Enter that sales order ID into the `Sales Order` input field and press `Enter` or click the `Show Sales Order` button.
   Check: The sales order and the sales order items are loaded and displayed in the `Sales Order Details` section.
   Check: In the message popover you see an information message `Avoid currency 'JPY'`.
   Check: The border of the `Currency` field of the sales order item with the product `HT-1501` indicates an information message.
   Check: When clicking into the sales order item's `Currency` field, the message text `Avoid currency 'JPY'` is shown.
   Check: There is no border around the `Gross Amount` field of that sales order item.
   Check: When clicking into the sales order item's `Gross Amount` field, no info message is shown.

### (XI) Clone a sales order item and expand product information

Search for a sales order with an item that has exactly one message for its `Quantity`. In case of mock data: Use sales order `111`.

1. Enter that sales order ID into the `Sales Order` input field and press `Enter` or click the `Show Sales Order` button.
   Check: The sales order and the sales order items are loaded and displayed in the `Sales Order Details` section.
2. Remember the number of messages.
3. Remember the `Gross Amount` and the `Changed At` data from the `Sales Order` section.
4. In the `Sales Order Items` table select the item with a message for its `Quantity`.
5. Click on the `Clone Item` button of the `Sales Order Items` table.
   Check: The item is cloned, that means an additional item is added to the `Sales Order Items` table with the same data as the selected item, except the `Item Position` and the `Note`.
   Check: The number of massages has been increased by 1.
   Check: The cloned item has the same message as the selected item.
   Check: The `Gross Amount` and the `Changed At` values are updated.
6. Only with back end: Open the developer tools, navigate to the network tab, clear the requests and filter for `$batch` requests.
7. In the `Sales Order Items` table click on the `>` at the end of the row for the cloned item to open the product details.
   Check: A `Product Details` dialog is opened showing the `Product ID` and the corresponding product `Name`.
   Only with back end: Check: There is no `$batch` request.
8. Close the `Product Details` dialog.