Skip to content
This repository has been archived by the owner on Aug 17, 2023. It is now read-only.

added new test for Deleting a seeding log on the Seeding Report Tab #229

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

thorpIV
Copy link

@thorpIV thorpIV commented Apr 26, 2023

Pull Request Description

The test allows you to create new logs and check if they are deleted from the database. The test accomplishes the following requirements to check whether the seeding report is deleting log(s) properly:

1.) When a single row is deleted from a table, the corresponding log is also removed from database.
2.) When multiple rows are deleted from a table, all the corresponding logs are removed from the database.
3.) When a row is checked to be deleted but cancels so no log is removed from the database.

Closes #205


Licensing Certification

FarmData2 is a Free Cultural Work and all accepted contributions are licensed as described in the LICENSE.md file. This requires that the contributor holds the rights to do so. By submitting this pull request I certify that I satisfy the terms of the Developer Certificate of Origin for its contents.

@braughtg
Copy link
Member

Please provide a description of your PR in and include a "Closes" line that links to the issue that will be resolved when the PR is merged.

@thorpIV
Copy link
Author

thorpIV commented Apr 30, 2023

image
We had trouble accessing the delete button, such that it does not show up on the Cypress page but shows up on the Firefox browser. We set up the test to function once the delete button problem is solved.

@braughtg
Copy link
Member

braughtg commented May 4, 2023

We had trouble accessing the delete button, such that it does not show up on the Cypress page but shows up on the Firefox browser.

This issue happens sometimes in Cypress testing due to the way a particular component is being rendered in the browser. While it appears that the button is there, the browser for some reason believes that it is hidden behind another element.

The fix is to add the {force: true} argument to click. So call click({force: true}) instead of click() as described here: https://subscription.packtpub.com/book/web-development/9781839213854/9/ch09lvl1sec51/forcing-actionability.

.click((response) => {
expect(response.status).to.equal(200)
})
expect(true).to.equal(true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point you'll need to check the contents of the table and the database to ensure that the deleted record does not appear in the report and that it has been removed from the database.

@udvale
Copy link

udvale commented May 11, 2023

Description:
When creating new logs, we made 3 copies of the makeDirectSedding() with different values (dates, crops, etc) using cy.wrap. When the test is rendered, it only shows 1 seeding report instead of 3. If we try to loop or make multiple copies of cy.wrap it gives an error. How can this be resolved?
after2

@braughtg
Copy link
Member

If we try to loop or make multiple copies of cy.wrap it gives an error. How can this be resolved?

It would be very helpful if you could give the code you are using that is causing the error and also a clear illustration of the specific error that is caused. Please add the code that you are using to create the records and a screenshot of the error that is happening.

context("Create a new logs, delete the log(s)", () => {
let logID = null

context("Adding logs, dates and testing for singular seeding log", () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not have a context inside of another context.

@aliouas
Copy link

aliouas commented May 14, 2023

I am not sure why when I run the Cypress test it fails at waitForPage. Here is the error and the code:
Screen Shot 2023-05-13 at 5 11 01 AM
Screen Shot 2023-05-14 at 5 45 36 AM

@braughtg
Copy link
Member

I am not sure why when I run the Cypress test it fails at waitForPage. Here is the error and the code:

This looks like it could be a timeout issue with the speed of the machine on which it is running. Try quitting any other applications that are running and see if that gets you past this point.

I suggest that because when I ran the test it got past that point, but then failed later. The error that I was seeing is:

image

Here it looks like you are getting r1-cbuttonCheckbox but the report you have generated contains only one row which would be r0.

@udvale
Copy link

udvale commented May 14, 2023

Description:
To test whether the created new logs(s) are being deleted, I created 4 different functions for creating new logs and used "cy.wrap" to get the logs into the database. However, even before the test begins, I get wrap{} error indicating creating the logs in the database failed.

The code to be run and the error response:
Code from seedingReport.deleteLog.spec.js:
image
Output when the test is run:
image

Steps to Reproduce:

  1. Go to: /home/fd2dev/FarmData2/farmdata2/farmdata2_modules/fd2_barn_kit/seedingReport/seedingReport.deleteLog.spec.js
  2. Try running the test the cypress GUI, using the command "./test_runner.bash" in the terminal. As there is only 1 "cy.wrap", it shouldn't give error.
  3. After that, try uncommenting the 3 "cy.wraps," run it in the cypress GUI using the same command.

Observation:

  • With the same code, my other group member tried testing, and it created the logs in the database and went to the next step in deleting them.
  • I also tried changing the alias => (makeseeding) but it still gave the same above error.
  • It may depend on the machine of each person is using when testing but it also doesn't give explanation on how it works on some and don't.

Expected Result:
After running the lines in seedingReport.deleteLog.spec.js, the cy.wrap and cy.get should successfully get the logs that was created and begin the actual testing.
after2
The above report is rendered after only using 1 cy.wrap and cy.get to get the log. However, it should work for multiple logs not only 1.

@thorpIV
Copy link
Author

thorpIV commented May 15, 2023

We had trouble accessing the delete button, such that it does not show up on the Cypress page but shows up on the Firefox browser.

This issue happens sometimes in Cypress testing due to the way a particular component is being rendered in the browser. While it appears that the button is there, the browser for some reason believes that it is hidden behind another element.

The fix is to add the {force: true} argument to click. So call click({force: true}) instead of click() as described here: https://subscription.packtpub.com/book/web-development/9781839213854/9/ch09lvl1sec51/forcing-actionability.

I tried this possible solution, and received the same error message. There is no button element in the div when I looked on the developer tools.

@braughtg
Copy link
Member

@udvale Nicely presented question! Well done.

To test whether the created new logs(s) are being deleted, I created 4 different functions for creating new logs and used "cy.wrap" to get the logs into the database. However, even before the test begins, I get wrap{} error indicating creating the logs in the database failed.

I pulled your code, tried it out and reduced it to a small example that I was able to get to run. Below is the context that I came up with. It creates 2 logs and then deletes them. You'll need to adapt it to your purposes. In particular:

  • You do not need multiple makeDirectSeeding functions. One that you call multiple times will do.
  • You need a different cy.wrap and a different cy.wait and a different logID variable for each log that you create
  • If you delete a log in an it using the UI, then you will not want to delete the log in the afterEach
  • Your it tests are not actually testing that the action was successful. You cannot check the status code when you click a button in the UI. That deletes the log, but you'll need to check the database directly using the getLog function from FarmOSAPI. See the example in the testdb example in the fd2_example module.
context("Create new log(s), delete the log(s)", () => {
        let logID0 = null
        let logID1 = null

            //Create new logs for testing and add dates
            beforeEach(() => {
                cy.wrap(makeDirectSeeding("Test Seeding0")).as("make-seeding0")
                cy.get("@make-seeding0")
                .then((response) => {
                    logID0 = response.data.id            
                })

                cy.wrap(makeDirectSeeding("Test Seeding1")).as("make-seeding1")
                cy.get("@make-seeding1")
                .then((response) => {
                    logID1 = response.data.id            
                })

                cy.get('[data-cy=start-date-select]')
                    .should("exist")
                    .type('2023-05-01')
                cy.get('[data-cy=end-date-select]')
                    .should("exist")
                    .type('2023-05-04')
                cy.get('[data-cy=generate-rpt-btn]')
                    .click()

            })

            it("Delete a singular seeding log from the row.", () => {
                expect(true).to.equal(true)
            })

            //Delete the created logs so the database is refreshed
            afterEach(() => {
                cy.wrap(deleteRecord("/log/"+logID0, sessionToken)).as("delete-seeding0")
                cy.wrap(deleteRecord("/log/"+logID1, sessionToken)).as("delete-seeding1")
                cy.get("@delete-seeding0")
                cy.get("@delete-seeding1")
            })
    })

@braughtg
Copy link
Member

I tried this possible solution, and received the same error message. There is no button element in the div when I looked on the developer tools.

@thorpIV This may be related to the organization of the tests overall. When I ran the code I posted above, I was able to get the delete button element with no error. So, I'd suggest that you check my reply to @udvale above and once you have the tests reorganized a little, see if it works for you. If not get back in touch if the problem persists.

@braughtg
Copy link
Member

Also, there appears to be changes to a lot of files in this PR that are not related to the PR itself. It is possible that you can resolve those by synchronizing your main branch with the upstream and then merging your main into this feature branch.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Seeding Report: Test Seeding Log(s) Deleted
4 participants