DickinsonCollege / FD2School-FarmData2-S23

A fork of FarmData2 that is used for the FarmData2 School Activities.
Other
1 stars 36 forks source link

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

Open thorpIV opened 1 year ago

thorpIV commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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.

udvale commented 1 year ago

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 commented 1 year ago

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.

aliouas commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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:

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 commented 1 year ago

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 commented 1 year ago

@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:

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 commented 1 year ago

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 commented 1 year ago

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.