-
-
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.
- Loading branch information
1 parent
7eab5d9
commit 3765904
Showing
8 changed files
with
86 additions
and
17 deletions.
There are no files selected for viewing
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.
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=d18fe761aa688c651536", | ||
"/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
67 changes: 56 additions & 11 deletions
67
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 |
---|---|---|
@@ -1,26 +1,71 @@ | ||
import * as React from 'react' | ||
import { screen, render, fireEvent, waitFor, act, waitForElementToBeRemoved } from '@testing-library/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 shows loading by default', async () => { | ||
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('it fetches data once loaded and stop loader once data is fetched', () => { | ||
// render(<ValueMetric name="Some Metric" graphql_query="valueMetricSampleQuery" />); | ||
|
||
// }); | ||
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"} | ||
]; | ||
|
||
// it('it allows to select range if provided', () => { | ||
// render(<ValueMetric name="Some Metric" graphql_query="valueMetricSampleQuery" />); | ||
// }); | ||
render(<ValueMetric name="Some Metric" graphql_query="valueMetricSampleQuery" ranges={ranges} />); | ||
|
||
// it('it fetches data if a range is selected', () => { | ||
// render(<ValueMetric name="Some Metric" graphql_query="valueMetricSampleQuery" />); | ||
// }) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { formatNumber, cutString } from '../'; | ||
|
||
it('formatNumber', () => { | ||
expect(formatNumber(2000)).toBe('2k') | ||
expect(formatNumber(-2000)).toBe('(2k)') | ||
expect(formatNumber(-1530)).toBe('(1.53k)') | ||
expect(formatNumber(-1530, '0[.]00a')).toBe('-1.53k') | ||
}); | ||
|
||
it('cutString', () => { | ||
expect(cutString('saleem', 2)).toBe('sa...') | ||
expect(cutString('saleem', 6)).toBe('saleem') | ||
}); |
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