Skip to content

Commit c132a18

Browse files
Merge pull request #57 from oslabs-beta/dev
Dev
2 parents 575999e + 03281a0 commit c132a18

File tree

257 files changed

+47252
-29551
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

257 files changed

+47252
-29551
lines changed

.github/workflows/tests.yml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
name: Run Tests and Build
22
on:
3+
# Updated to only run on pull requests to dev because all pushed to main will go through dev
34
pull_request:
45
branches:
5-
- main
6-
- dev
7-
push:
8-
branches:
9-
- main
6+
# - main
107
- dev
8+
# push:
9+
# branches:
10+
# - main
11+
# - dev
1112
jobs:
1213
unit-testing-extension:
1314
runs-on: ubuntu-latest
@@ -16,7 +17,7 @@ jobs:
1617
- name: Use Node.js 18
1718
uses: actions/setup-node@v4
1819
with:
19-
node-version: 18
20+
node-version: '20.7.0'
2021
cache: 'npm'
2122
- name: Install Extension dependencies
2223
run: |
@@ -30,7 +31,7 @@ jobs:
3031
run: |
3132
cd extension
3233
npm test
33-
unit-testing-package:
34+
unit-testing-package-react:
3435
runs-on: ubuntu-latest
3536
steps:
3637
- uses: actions/checkout@v4
@@ -41,18 +42,18 @@ jobs:
4142
cache: 'npm'
4243
- name: Install Package dependencies
4344
run: |
44-
cd package
45+
cd package-react
4546
npm ci
4647
- name: Install linux handler for github actions
4748
run: |
48-
cd package
49+
cd package-react
4950
npm i @rollup/rollup-linux-x64-gnu
5051
- name: Build Package
5152
run: |
52-
cd package
53+
cd package-react
5354
npm run build
5455
- name: Test Package
5556
run: |
56-
cd package
57+
cd package-react
5758
npm test
5859

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules/
22
dist
3+
coverage/

README.md

Lines changed: 8 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ React Query Rewind introduces a powerful DevTool extension designed to work in c
4444
_picture of importing the component_
4545

4646
```javascript
47-
import ReactQueryRewind from 'react-query-rewind';
47+
import ReactQueryRewind from "react-query-rewind";
4848
```
4949

5050
3. Place ReactQueryRewind next to the root of your application inside the QueryClientProvider component.
@@ -61,26 +61,26 @@ React Query Rewind introduces a powerful DevTool extension designed to work in c
6161
4. Open the Chrome DevTool Extension and start coding!
6262

6363
<p align="left">
64-
<img src="./assets/chrome-devtool.png" alt="Component Placement" width="600"/>
64+
<img src="https://i.imgur.com/xTEPI20.png" alt="Component Placement" width="600"/>
6565
</p>
6666

6767
# Features
6868

6969
- <b>Query States: </b>Upon opening RQRewind in Chrome Dev Tools, you will see the Queries tab open with a drop down menu listing the query keys of all the incoming queries. Select the queries that you want to monitor, make changes on the web app, and the changes of query states will be logged as reflected by the growing number above the play bar. Use the play bar to navigate to a particular state snapshot that you would like to inspect.
7070

71-
<p align="center"><img src="./assets/query-states.gif" width='800' style="margin-top: 1em; margin-bottom: 1em;"></p>
71+
<p align="center"><img src="https://i.imgur.com/g8KrqAg.gif" width='800' style="margin-top: 1em; margin-bottom: 1em;"></p>
7272

7373
- <b>State Diff: </b>Toggle on the Diff button to see state changes between each snapshot highlighted. Turn on the switch on top of the page to show only parts of the state that are changed.
7474

75-
<p align="center"><img src="./assets/state-diff.gif" width='800' style="margin-top: 1em; margin-bottom: 1em;"></p>
75+
<p align="center"><img src="https://i.imgur.com/a8KAgXZ.gif" width='800' style="margin-top: 1em; margin-bottom: 1em;"></p>
7676

7777
- <b>Live UI Change: </b>As you review the state change history, there is also the option to turn on the time travel mode by clicking on the clock icon button. Under time travel mode, when visiting a logged state snapshot on RQRewindl, the UI of the app will change accordingly. Turn off time travel mode for RQRewind to continue logging future state changes.
7878

79-
<p align="center"><img src="./assets/UI-change.gif" width='800' style="margin-top: 1em; margin-bottom: 1em;"></p>
79+
<p align="center"><img src="https://i.imgur.com/AZ3QGuf.gif" width='800' style="margin-top: 1em; margin-bottom: 1em;"></p>
8080

8181
- <b>Component Tree: </b> Click on the Component Tree tab and turn on the Start Profiling switch. Click on any component on the app, and view the component tree that is rendered on the dev tools panel.
8282

83-
<p align="center"><img src="./assets/component-tree.gif" width='800' style="margin-top: 1em; margin-bottom: 1em;"></p>
83+
<p align="center"><img src="https://i.imgur.com/qa5UJTW.gif" width='800' style="margin-top: 1em; margin-bottom: 1em;"></p>
8484

8585
# Contributing
8686

@@ -111,43 +111,6 @@ Rui Fan - [GitHub](https://github.com/ruifan-IU) - [LinkedIn](https://www.linked
111111
Project Link: [React Query Rewind](https://github.com/oslabs-beta/react-query-rewind-chrome)
112112
113113
# License
114+
[MIT](https://www.mit.edu/~amini/LICENSE.md)
114115
115-
_MIT Link_
116-
117-
<p align="right">(<a href="#readme-top">back to top</a>)</p>
118-
119-
<!-- TABLE OF CONTENTS -->
120-
<!-- <details>
121-
<summary>Table of Contents</summary>
122-
<ol>
123-
<li>
124-
<a href="#about-the-project">About The Project</a>
125-
<ul>
126-
<li><a href="#built-with">Built With</a></li>
127-
</ul>
128-
</li>
129-
<li>
130-
<a href="#getting-started">Getting Started</a>
131-
<ul>
132-
<li><a href="#prerequisites">Prerequisites</a></li>
133-
<li><a href="#installation">Installation</a></li>
134-
</ul>
135-
</li>
136-
<li><a href="#usage">Usage</a></li>
137-
<li><a href="#roadmap">Roadmap</a></li>
138-
<li><a href="#contributing">Contributing</a></li>
139-
<li><a href="#license">License</a></li>
140-
<li><a href="#contact">Contact</a></li>
141-
<li><a href="#acknowledgments">Acknowledgments</a></li>
142-
</ol>
143-
</details> -->
144-
145-
<!-- <p align="right">(<a href="#readme-top">back to top</a>)</p> -->
146-
147-
<!-- <a name="website" href="ARE WE GONNA HAVE A WEBSITE">Website</a> -->
148-
149-
<!-- [![Contributors](https://img.shields.io/github/contributors/oslabs-beta/react-query-rewind-chrome.svg?style=for-the-badge)](https://github.com/oslabs-beta/react-query-rewind-chrome/graphs/contributors)
150-
[![Forks](https://img.shields.io/github/forks/oslabs-beta/react-query-rewind-chrome.svg?style=for-the-badge)](https://github.com/oslabs-beta/react-query-rewind-chrome/forks)
151-
[![Stargazers](https://img.shields.io/github/stars/oslabs-beta/react-query-rewind-chrome.svg?style=for-the-badge)](https://github.com/oslabs-beta/react-query-rewind-chrome/stargazers)
152-
[![Issues](https://img.shields.io/github/issues/oslabs-beta/react-query-rewind-chrome.svg?style=for-the-badge)](https://github.com/oslabs-beta/react-query-rewind-chrome/issues)
153-
[![MIT License](https://img.shields.io/github/license/oslabs-beta/react-query-rewind-chrome.svg?style=for-the-badge)](https://github.com/oslabs-beta/react-query-rewind-chrome/blob/main/LICENSE) -->
116+
<p align="right">(<a href="#readme-top">back to top</a>)</p>

extension/.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
node_modules
2-
build/
1+
node_modules/
2+
dist/

extension/LICENSE

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import * as React from 'react';
2+
import { render, screen, fireEvent } from '@testing-library/react';
3+
import userEvent from '@testing-library/user-event';
4+
import ContinuousSlider from '../src/components/ContinuousSlider'; // Adjust the import path as necessary
5+
import '@testing-library/jest-dom';
6+
7+
describe('ContinuousSlider', () => {
8+
it('renders correctly with given props', () => {
9+
const handleChange = jest.fn();
10+
const { asFragment } = render(<ContinuousSlider value={30} maxValue={100} onChange={handleChange} />);
11+
12+
const slider = screen.getByRole('slider');
13+
expect(slider).toBeInTheDocument();
14+
expect(slider).toHaveAttribute('aria-valuemax', '100');
15+
expect(slider).toHaveAttribute('aria-valuenow', '30');
16+
expect(asFragment()).toMatchSnapshot();
17+
});
18+
19+
it('calls onChange with the new value when changed', async () => {
20+
const handleChange = jest.fn();
21+
render(<ContinuousSlider value={30} maxValue={100} onChange={handleChange} />);
22+
23+
// Assuming the slider allows keyboard input, you can simulate changes like this
24+
const slider = screen.getByRole('slider');
25+
await userEvent.click(slider);
26+
await userEvent.keyboard('{arrowright}'); // Simulates pressing the right arrow key to increase the value
27+
28+
expect(handleChange).toHaveBeenCalledWith(expect.any(Number));
29+
});
30+
31+
});

extension/__tests__/DiffTab.test.tsx

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import React from 'react';
2+
import { render, screen, fireEvent } from '@testing-library/react';
3+
import DiffTab from '../src/containers/DiffTab';
4+
import '@testing-library/jest-dom';
5+
import { QueryDisplay } from '../src/types';
6+
import exp from 'constants';
7+
8+
describe('DiffTab Component', () => {
9+
const queryDisplayMock: QueryDisplay[][] = [
10+
[
11+
{
12+
queryKey: 'Query 1',
13+
queryData: { some: 'data' }
14+
},
15+
{
16+
queryKey: 'Query 2',
17+
queryData: { more: 'data' }
18+
}
19+
],
20+
[
21+
{
22+
queryKey: 'Query 1',
23+
queryData: { some: 'different data' }
24+
}
25+
]
26+
];
27+
28+
it('renders correctly with initial state', () => {
29+
const { asFragment } = render(<DiffTab queryDisplay={queryDisplayMock} currentIndex={0} />);
30+
expect(screen.getByLabelText(/Hide Unchanged Properties/i)).toBeInTheDocument();
31+
expect(screen.getByText(/Query 1/i)).toBeInTheDocument();
32+
expect(asFragment()).toMatchSnapshot();
33+
});
34+
35+
it('toggles isHidden state on switch toggle', () => {
36+
const { asFragment } = render(<DiffTab queryDisplay={queryDisplayMock} currentIndex={0} />);
37+
fireEvent.click(screen.getByRole('checkbox')); // Clicks the switch
38+
expect(screen.getByLabelText(/Show Unchanged Properties/i)).toBeInTheDocument();
39+
expect(asFragment()).toMatchSnapshot();
40+
});
41+
42+
it('renders JsonDiff component with correct props based on isHidden state', () => {
43+
const { rerender, asFragment } = render(<DiffTab queryDisplay={queryDisplayMock} currentIndex={1} />);
44+
let switchControl = screen.getByRole('checkbox');
45+
46+
// Initially, isHidden should be false, so "Hide" should be in the label
47+
expect(switchControl).not.toBeChecked();
48+
expect(screen.getByText(/Hide Unchanged Properties/i)).toBeInTheDocument();
49+
expect(asFragment()).toMatchSnapshot();
50+
51+
// Toggle the switch to change isHidden state
52+
fireEvent.click(switchControl);
53+
// Rerendering is necessary only if the component's response to state changes cannot be detected without it
54+
rerender(<DiffTab queryDisplay={queryDisplayMock} currentIndex={1} />);
55+
56+
// Now, isHidden should be true, so "Show" should be in the label
57+
expect(screen.getByLabelText(/Show Unchanged Properties/i)).toBeInTheDocument();
58+
expect(asFragment()).toMatchSnapshot();
59+
});
60+
});

extension/__tests__/JsonDiff.test.tsx

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import React from 'react';
2+
import { render } from '@testing-library/react';
3+
import '@testing-library/jest-dom';
4+
import JsonDiff from '../src/components/JsonDiff';
5+
6+
describe('JsonDiff Component', () => {
7+
it('displays initial state message for empty currentJson and snapshot', () => {
8+
const { getByText, asFragment } = render(
9+
<JsonDiff
10+
oldJson={undefined}
11+
currentJson=""
12+
queryKey="testQueryKey"
13+
isHidden={false}
14+
/>
15+
);
16+
expect(getByText(/Initial state - no comparison available/i)).toBeInTheDocument();
17+
expect(asFragment()).toMatchSnapshot();
18+
});
19+
20+
it('displays a diff when there are differences between oldJson and currentJson and snapshot', () => {
21+
const oldJson = { key: "oldValue" };
22+
const currentJson = { key: "newValue" };
23+
const { container, asFragment } = render(
24+
<JsonDiff
25+
oldJson={oldJson}
26+
currentJson={currentJson}
27+
queryKey="testQueryKey"
28+
isHidden={false}
29+
/>
30+
);
31+
// Assert that the diff is displayed
32+
expect(container.querySelector('.jsondiffpatch-delta')).not.toBeNull();
33+
expect(asFragment()).toMatchSnapshot();
34+
});
35+
36+
37+
it('displays no changes message when oldJson and currentJson are the same', () => {
38+
const json = { key: "value" };
39+
const { getByText, asFragment } = render(
40+
<JsonDiff
41+
oldJson={json}
42+
currentJson={json}
43+
queryKey="testQueryKey"
44+
isHidden={false}
45+
/>
46+
);
47+
expect(getByText(/QueryKey data not modified on this state change/i)).toBeInTheDocument();
48+
expect(asFragment()).toMatchSnapshot();
49+
});
50+
51+
it('toggles visibility based on isHidden prop', () => {
52+
const json = { key: "value" };
53+
const newJson = { key: "newValue" };
54+
const { container, rerender, asFragment } = render(
55+
<JsonDiff
56+
oldJson={json}
57+
currentJson={newJson}
58+
queryKey="testQueryKey"
59+
isHidden={true}
60+
/>
61+
);
62+
// Initially, the class indicating hidden changes should be present
63+
expect(container.querySelector('.jsondiffpatch-unchanged-hidden')).not.toBeNull();
64+
expect(asFragment()).toMatchSnapshot();
65+
66+
// Rerender with isHidden = false and check if the class is removed
67+
rerender(
68+
<JsonDiff
69+
oldJson={json}
70+
currentJson={newJson}
71+
queryKey="testQueryKey"
72+
isHidden={false}
73+
/>
74+
);
75+
expect(container.querySelector('.jsondiffpatch-unchanged-hidden')).toBeNull();
76+
expect(asFragment()).toMatchSnapshot();
77+
});
78+
79+
});

extension/__tests__/JsonFormatter.tsx renamed to extension/__tests__/JsonFormatter.test.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import { render } from '@testing-library/react';
33
import JsonFormatter from '../src/components/JsonFormatter';
44

55
describe('JsonFormatter component', () => {
6-
it('renders without crashing', () => {
7-
render(<JsonFormatter
6+
it('renders without crashing and snapshot', () => {
7+
const { asFragment } = render(<JsonFormatter
88
key={1}
99
queryKey={'[posts-one]'}
1010
jsonData={{val: 'test', arr: [1,2,3]}}
1111
/>);
12+
13+
expect(asFragment()).toMatchSnapshot();
1214
});
1315
});

0 commit comments

Comments
 (0)