-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from saleem-hadad/feature/add-value-metric-uni…
…t-tests Add value metric unit tests #features
- Loading branch information
Showing
23 changed files
with
230 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { server } from './resources/js/mocks/server.js' | ||
|
||
beforeAll(() => server.listen()) | ||
afterEach(() => server.resetHandlers()) | ||
afterAll(() => server.close()) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"/js/app.js": "/js/app.js?id=646cbe42f9883c5bee75", | ||
"/css/app.css": "/css/app.css?id=302229d53296b2231e13" | ||
"/js/app.js": "/js/app.js?id=9f1561cb00efdc560d9b", | ||
"/css/app.css": "/css/app.css?id=bd9462ef1c7aca6afb62" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
resources/js/Components/Domain/__tests__/ValueMetric.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import * as React from 'react' | ||
import { screen, render, waitFor, waitForElementToBeRemoved } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import '@testing-library/jest-dom'; | ||
|
||
import ValueMetric from '../ValueMetric'; | ||
|
||
it('it fetches data once loaded and stop loader once data is fetched', async () => { | ||
render(<ValueMetric name="Some Metric" graphql_query="valueMetricSampleQuery" />); | ||
|
||
expect(screen.getByTestId('loading-view')).toBeVisible() | ||
|
||
await waitForElementToBeRemoved(() => screen.queryByTestId('loading-view')) | ||
await waitFor(() => expect(screen.getByText(/some metric/i)).toBeVisible()) | ||
}); | ||
|
||
|
||
it('ranges provided and select first by default', async () => { | ||
const ranges = [ | ||
{name: "Current Month", key: "current-month", start: "2022-04-01", end: "2022-04-30"}, | ||
{name: "Last Month", key: "last-month", start: "2022-03-01", end: "2022-03-31"} | ||
]; | ||
|
||
render(<ValueMetric name="Some Metric" graphql_query="valueMetricSampleQuery" ranges={ranges} />); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByRole('option', {name: 'Current Month'}).selected).toBe(true) | ||
expect(screen.getByRole('option', {name: 'Last Month'}).selected).toBe(false) | ||
}) | ||
}); | ||
|
||
it('it allows to select a range if ranges provides', async () => { | ||
const ranges = [ | ||
{name: "Current Month", key: "current-month", start: "2022-04-01", end: "2022-04-30"}, | ||
{name: "Last Month", key: "last-month", start: "2022-03-01", end: "2022-03-31"} | ||
]; | ||
|
||
render(<ValueMetric name="Some Metric" graphql_query="valueMetricSampleQuery" ranges={ranges} />); | ||
|
||
await waitFor(async () => { | ||
await userEvent.selectOptions( | ||
screen.getByRole('combobox'), | ||
screen.getByRole('option', {name: 'Last Month'}), | ||
) | ||
}) | ||
|
||
await waitFor(() => { | ||
expect(screen.getByRole('option', {name: 'Current Month'}).selected).toBe(false) | ||
expect(screen.getByRole('option', {name: 'Last Month'}).selected).toBe(true) | ||
}) | ||
}); | ||
|
||
it('it fetches data if a range is selected', async () => { | ||
const ranges = [ | ||
{name: "Current Month", key: "current-month", start: "2022-04-01", end: "2022-04-30"}, | ||
{name: "Last Month", key: "last-month", start: "2022-03-01", end: "2022-03-31"} | ||
]; | ||
|
||
render(<ValueMetric name="Some Metric" graphql_query="valueMetricSampleQuery" ranges={ranges} />); | ||
|
||
await waitFor(() => expect(screen.getByText(/3k/i)).toBeVisible()) | ||
|
||
await waitFor(async () => { | ||
await userEvent.selectOptions( | ||
screen.getByRole('combobox'), | ||
screen.getByRole('option', {name: 'Last Month'}), | ||
) | ||
}) | ||
|
||
await waitFor(() => expect(screen.getByText(/2k/i)).toBeVisible()) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.