Skip to content

Commit

Permalink
Merge pull request #1820 from cfpb/data-publication-2022
Browse files Browse the repository at this point in the history
Data Publication release for 2022
  • Loading branch information
Michaeldremy authored Jun 29, 2023
2 parents 1027987 + 100e521 commit 2aba3c7
Show file tree
Hide file tree
Showing 49 changed files with 7,929 additions and 373 deletions.
96 changes: 51 additions & 45 deletions cypress/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,58 +1,64 @@
FROM centos:7

RUN yum -y update

RUN yum install -y gcc-c++ make
RUN curl -sL https://rpm.nodesource.com/setup_14.x | bash -

# Install dependencies
RUN yum install -y xorg-x11-server-Xvfb
RUN yum install -y xorg-x11-xauth

RUN yum install -y gtk2-2.24*
RUN yum install -y gtk3-3.22*
RUN yum install -y gtk3-devel

RUN yum install -y libXtst*
# provides libXss
RUN yum install -y libXScrnSaver*
# provides libgconf-2
RUN yum install -y GConf2*
# provides libasound
RUN yum install -y alsa-lib*

RUN yum whatprovides libnss3.so
RUN yum install -y libnss3.so

# Install Node
RUN yum install -y epel-release
RUN yum install -y nodejs

RUN yum install -y wget
RUN yum install -y unzip
FROM redhat/ubi8
RUN dnf -y update

# Install node & yarn
RUN dnf -y module install nodejs:18
RUN npm install -g npm@latest
RUN npm install yarn -g

COPY / hmda-frontend/

WORKDIR /hmda-frontend/
# Integrate additional dependency source repositories
RUN dnf -y install --nogpgcheck https://dl.fedoraproject.org/pub/epel/epel-release-latest-$(rpm -E %rhel).noarch.rpm
RUN dnf -y install --nogpgcheck https://mirrors.rpmfusion.org/free/el/rpmfusion-free-release-$(rpm -E %rhel).noarch.rpm
RUN dnf -y install --nogpgcheck https://rpms.remirepo.net/enterprise/remi-release-$(rpm -E %rhel).rpm
RUN rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
RUN rpm -Uvh https://www.elrepo.org/elrepo-release-8.el8.elrepo.noarch.rpm
RUN yum -y install http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
RUN yum -y install http://mirror.ghettoforge.org/distributions/gf/gf-release-latest.gf.el8.noarch.rpm

RUN yarn
# Install Cypress' dependencies
COPY cypress/install-cypress-dependencies.sh /
RUN /bin/sh install-cypress-dependencies.sh

# Cleanup vulnerabilities (as root user)
RUN rm -rf /usr/local/share/.cache/yarn/v6/npm-public-encrypt-*/node_modules/public-encrypt/test/*
RUN rm -rf /root/.cache/Cypress/12.0.2/Cypress/resources/app/node_modules/public-encrypt/test/*
RUN rm -rf /root/.cache/Cypress/12.0.2/Cypress/resources/app/node_modules/http-proxy/test/*
RUN rm -rf /root/.cache/Cypress/12.0.2/Cypress/resources/app/node_modules/lazystream/secret
RUN rm -rf /root/.cache/Cypress/**/Cypress/resources/app/node_modules/public-encrypt/test/*
RUN rm -rf /root/.cache/Cypress/**/Cypress/resources/app/node_modules/http-proxy/test/*
RUN rm -rf /root/.cache/Cypress/**/Cypress/resources/app/node_modules/lazystream/secret

# Prepare working directory
RUN mkdir -p hmda-frontend/cypress/downloads hmda-frontend/cypress/screenshots hmda-frontend/cypress/videos hmda-frontend/cypress/integration hmda-frontend/cypress/fixtures
WORKDIR /hmda-frontend/

# Copy Cypress support files
COPY cypress/support cypress/support
COPY cypress/plugins cypress/plugins
COPY cypress/docker-runner.sh cypress/
COPY ./cypress.config.js ./

# Copy HMDA helper functions
RUN mkdir -p src/common
COPY ../src/common/configUtils.js src/common/
COPY ../src/deriveConfig.js src/
COPY ../src/common/constants src/common/constants
COPY ../src/common/api/ src/common/
RUN mkdir -p src/filing/api/
COPY ../src/filing/api src/filing/api
RUN mkdir -p src/filing/utils/
COPY ../src/filing/utils src/filing/utils
RUN mkdir -p src/tools/larft/config/
COPY ../src/tools/larft/config/ src/tools/larft/config/

# Enable creation of screenshots/videos
RUN useradd -M -d /hmda-frontend -s /bin/bash hmda_cypress_user && \
chown -R hmda_cypress_user:hmda_cypress_user /hmda-frontend/

USER hmda_cypress_user
RUN yarn --cache-folder /hmda-frontend cypress install

# Install Cypress + supporting libraries
COPY cypress/package.json ./
RUN yarn install

# Cleanup vulnerabilities (as hmda_cypress_user)
RUN rm -rf /hmda-frontend/node_modules/public-encrypt/test/*
RUN rm -rf /hmda-frontend/.cache/Cypress/12.0.2/Cypress/resources/app/node_modules/public-encrypt/test/*
RUN rm -rf /hmda-frontend/.cache/Cypress/12.0.2/Cypress/resources/app/node_modules/http-proxy/test/*

RUN rm -rf /hmda-frontend/.cache/Cypress/12.0.2/Cypress/resources/app/node_modules/lazystream/secret
RUN rm -rf /hmda-frontend/.cache/Cypress/**/Cypress/resources/app/node_modules/public-encrypt/test/*
RUN rm -rf /hmda-frontend/.cache/Cypress/**/Cypress/resources/app/node_modules/http-proxy/test/*
RUN rm -rf /hmda-frontend/.cache/Cypress/**/Cypress/resources/app/node_modules/lazystream/secret
41 changes: 27 additions & 14 deletions cypress/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# Cypress Integration Testing
In an effort to automate system validation, this test suite emulates user interaction with the HMDA Frontend using the Cypress testing library.
* [Setup](#setup)
+ [Installation Issues](#installation-issues)
+ [Environment Configuration](#environment-configuration)
* [Running Tests](#running-tests)
+ [via CLI](#via-cli)
+ [via Cypress UI](#via-cypress-ui)
* [Cronjob integration](#cronjob-integration)
+ [Updating Specs](#updating-specs)
+ [Updating Credentials](#updating-credentials)
- [Cypress Integration Testing](#cypress-integration-testing)
- [Setup](#setup)
- [Installation Issues](#installation-issues)
- [Environment Configuration](#environment-configuration)
- [Running Tests](#running-tests)
- [via CLI](#via-cli)
- [via Cypress UI](#via-cypress-ui)
- [Cronjob integration](#cronjob-integration)
- [Updating the test image](#updating-the-test-image)
- [Updating Specs/Fixtures](#updating-specsfixtures)
- [Updating Credentials](#updating-credentials)

## Setup
Install [Node Version Manager (nvm)](https://github.com/nvm-sh/nvm#installing-and-updating)
Expand Down Expand Up @@ -82,19 +84,30 @@ yarn cypress open
Integration testing automatically runs once daily via cronjob.

### Updating the test image
The test image only needs to be updated when there is a change to the testing workflow (i.e. changes to `./docker-runner.sh`) or updates to the image dependencies (`./package.json`, `./install-cypress-dependencies.sh`, './Dockerfile`)
```
docker build . -t hmda-cypress -f cypress/Dockerfile &&
docker tag hmda-cypress <image_repo>/hmda/hmda-cypress &&
docker push <image_repo>/hmda/hmda-cypress
```

### Updating Specs/Fixtures
Cronjob specs and fixtures are pulled from AWS S3 on each job run. To update the testing data used, from the root directory `/hmda-frontend/`, run
```
yarn cy-update-s3
```
Cronjob specs and fixtures are pulled from AWS S3 on each job run.

These files need to be updated when:
- There are tests being added/removed/updated
- There are files that tests depend on (Ex. LAR files for Filing tests) that have changed

Prerequisites:
- Verify that `/cypress/fixtures/2020-FRONTENDTEST-MAX.txt` exists. If not, use `yarn make-lar frontendtestbank9999 2020 MAX` to generate it (this requires the HMDA Platform - Check Digit service to be running locally).

Upload S3 files:
- To update the testing data used, from the root directory `/hmda-frontend/`, run
```
yarn cy-update-s3
```

You will be prompted for an AWS user profile that has `write` access to the S3 bucket.
- You will be prompted for an AWS user profile that has `write` access to the S3 bucket.

### Updating Credentials
In order to update the login credentials used by the testing pod, please see the `Quick Start` section in `/hmda-devops/kubernetes/cypress/README.md`.
28 changes: 22 additions & 6 deletions cypress/docker-runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,35 @@
curl https://s3.amazonaws.com/cfpb-hmda-public/prod/cypress/fixtures.zip > ./cypress/downloads/fixtures.zip \
&& unzip -o cypress/downloads/fixtures.zip -d cypress/

# Download Integration tests
# Download e2e tests
curl https://s3.amazonaws.com/cfpb-hmda-public/prod/cypress/e2e.zip > ./cypress/downloads/e2e.zip \
&& unzip -o cypress/downloads/e2e.zip -d cypress/

# Run configured Integration tests
# Download Docusaurus test file
mkdir -p cypress/e2e/docusaurus
curl https://raw.githubusercontent.com/cfpb/hmda-combined-documentation/main/cypress/e2e/documentation.cy.js > cypress/e2e/docusaurus/documentation.cy.js

# Run configured e2e tests
# Example: "cypress/e2e/data-browser/**,cypress/e2e/data-publication/**"
if [[ -n "$CYPRESS_TEST_LIST" ]];
then
yarn cypress run --spec ${CYPRESS_TEST_LIST} > output_integration.txt
if grep -q "All specs passed!" "output_integration.txt" ; then
post_success 'Integration testing' "output_integration.txt"
yarn cypress run --spec ${CYPRESS_TEST_LIST} > output_e2e.txt
if grep -q "All specs passed!" "output_e2e.txt" ; then
post_success 'e2e testing' "output_e2e.txt"
else
post_failure 'e2e testing' "output_e2e.txt"
fi
fi

# Run Docusaurus e2e test and display results
# Only run Docusaurus in production
if [[ "$CYPRESS_HOST" == *"ffiec.cfpb"* ]];
then
yarn cypress run --spec "cypress/e2e/docusaurus/**" > output_docusaurus_e2e.txt
if grep -q "All specs passed!" "output_docusaurus_e2e.txt" ; then
post_success 'Docusaurus e2e testing' "output_docusaurus_e2e.txt"
else
post_failure 'Integration testing' "output_integration.txt"
post_failure 'Docusaurus e2e testing' "output_docusaurus_e2e.txt"
fi
fi

Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/data-browser/dataset-filtering.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
waitUpto2Mins,
} from '../../support/helpers'

const YEARS = [2021, 2020, 2019, 2018]
const YEARS = [2022, 2021, 2020, 2019, 2018]
const { HOST, ENVIRONMENT } = Cypress.env()
const dbUrl = dbURL.bind(null, HOST)

Expand Down
11 changes: 0 additions & 11 deletions cypress/e2e/data-browser/graphs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,6 @@ if (isBeta(HOST)) {
`${baseURLToVisit}/data-browser/graphs/quarterly/info/filers`
)
})

it('Starts on Graph tab and then switches to faq tab', () => {
cy.visit(`${baseURLToVisit}/data-browser/graphs/quarterly`)
cy.get('[aria-label="Navigate to the FAQ tab."]').click(0, 0, {
force: true,
})
cy.url().should(
'eq',
`${baseURLToVisit}/data-browser/graphs/quarterly/info/faq`
)
})
})

describe('Graph Specific tests', () => {
Expand Down
55 changes: 55 additions & 0 deletions cypress/e2e/data-browser/maps.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,61 @@ const { HOST, ENVIRONMENT } = Cypress.env()
const ACTION_DELAY = 8000 // milliseconds

describe('Maps', () => {
it("State 2022", () => {
cy.get({ HOST, ENVIRONMENT }).logEnv()
cy.viewport(1000, 940)
cy.visit(mapsURL(HOST, "2022?geography=state"))
deleteBetaBanner(HOST)

openSelector("#map-filter-1").type("denied{enter}")
openSelector("#map-filter-2").type("age 55{enter}")

cy.wait(ACTION_DELAY) // Allow the map to complete it's initial render
cy.get(".mapboxgl-canvas").click()

cy.get(".maps-nav-bar .left .count").should("contain", "2,430")
cy.get(".maps-nav-bar .right .count").should("contain", "0.83")
cy.get(".maps-nav-bar .feature").should("contain", "KANSAS")

cy.get(".summary-page .featureName > .colorTextWithBias").should(
"contain",
"KANSAS"
)
cy.get(".summary-page .count").should("contain", "2,430")

cy.get(
".filter-report-1 > table > tbody > tr.highlight > :nth-child(1)"
).should("contain", "Application denied")
cy.get(
".filter-report-1 > table > tbody > tr.highlight > :nth-child(2)"
).should("contain", "16,609")
cy.get(
".filter-report-1 > table > tbody > tr.highlight > :nth-child(3)"
).should("contain", "9.61%")
cy.get(
".filter-report-1 > table > tbody > tr.highlight > :nth-child(4)"
).should("contain", "2,430")
cy.get(
".filter-report-1 > table > tbody > tr.highlight > :nth-child(5)"
).should("contain", "16.77%")

cy.get(
".filter-report-2 > table > tbody > tr.highlight > :nth-child(1)"
).should("contain", "55-64")
cy.get(
".filter-report-2 > table > tbody > tr.highlight > :nth-child(2)"
).should("contain", "24,225")
cy.get(
".filter-report-2 > table > tbody > tr.highlight > :nth-child(3)"
).should("contain", "14.02%")
cy.get(
".filter-report-2 > table > tbody > tr.highlight > :nth-child(4)"
).should("contain", "2,430")
cy.get(
".filter-report-2 > table > tbody > tr.highlight > :nth-child(5)"
).should("contain", "16.54%")
})

it('State 2021', () => {
cy.get({ HOST, ENVIRONMENT }).logEnv()
cy.viewport(1000, 940)
Expand Down
45 changes: 45 additions & 0 deletions cypress/e2e/data-publication/AggregateReports.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,51 @@ const { HOST } = Cypress.env()

// TODO: Test CSV Download
describe("Aggregate Reports", () => {
it("2022", () => {
cy.get({ HOST }).logEnv()
cy.viewport(1680, 867)
cy.visit(`${HOST}/data-publication/aggregate-reports/2022`)

// Select geography and report
cy.findByText("Select a state...").type("Arizona{enter}")
cy.findByText("Select MSA/MD...").type("Phoenix{enter}")
cy.findByText("Select report...").type(
"Applications by Ethnicity and Sex{enter}"
)

// Report Content
cy.get("tbody > :nth-child(3) > :nth-child(2)").should("have.text", "12308")
cy.get("tbody > :nth-child(3) > :nth-child(3)").should(
"have.text",
"3402910000"
)
cy.get("tbody > :nth-child(3) > :nth-child(4)").should("have.text", "790")
cy.get("tbody > :nth-child(3) > :nth-child(5)").should(
"have.text",
"160160000"
)
cy.get("tbody > :nth-child(3) > :nth-child(6)").should("have.text", "5107")
cy.get("tbody > :nth-child(3) > :nth-child(7)").should(
"have.text",
"962115000"
)
cy.get("tbody > :nth-child(3) > :nth-child(8)").should("have.text", "4032")
cy.get("tbody > :nth-child(3) > :nth-child(9)").should(
"have.text",
"1184710000"
)
cy.get("tbody > :nth-child(3) > :nth-child(10)").should("have.text", "1442")
cy.get("tbody > :nth-child(3) > :nth-child(11)").should(
"have.text",
"339530000"
)
cy.get("tbody > :nth-child(3) > :nth-child(12)").should("have.text", "351")
cy.get("tbody > :nth-child(3) > :nth-child(13)").should(
"have.text",
"112775000"
)
})

it("2021", () => {
cy.get({ HOST }).logEnv()
cy.viewport(1680, 867)
Expand Down
Loading

0 comments on commit 2aba3c7

Please sign in to comment.