Skip to content

Commit

Permalink
Cache updates (#25)
Browse files Browse the repository at this point in the history
0.0.22 - Add the ability to edit cached responses.

- feat: users may now edit the cached responses
- feat: persist cache filters
- patch: use routing to navigate acrsoss the ui
- patch: clean-up global state management
- patch: attempt to close any jambox process prior to e2e tests
- fix: crash when deleting unknown cached id
- fix: waterfall ui
- feat: css filter
- fix: unknown props warnings
  • Loading branch information
ballercat authored Jul 17, 2023
1 parent d612889 commit 376b5e2
Show file tree
Hide file tree
Showing 28 changed files with 470 additions and 343 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
node_modules
coverage
coverage-cypress
cypress/screenshots
cypress/videos
.DS_Store
*.log
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 0.0.22 - Implement cached response update flow

- feat: users may now edit the cached responses
- feat: persist cache filters
- patch: use routing to navigate acrsoss the ui
- patch: clean-up global state management
- patch: attempt to close any jambox process prior to e2e tests
- fix: crash when deleting unknown cached id

## 0.0.21 - Bugfix cache read on startup

- fix: correctly read all json caches on startup
Expand Down
13 changes: 11 additions & 2 deletions e2e-backend.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
#!/usr/bin/env node
import http from 'http';
import tinyServer from './src/utils/tiny-server.mjs';
import jamboxServer from './src/server/index.mjs';

await tinyServer(7777);
await jamboxServer({ port: 9000 });
const launch = async () => {
await tinyServer(7777);
await jamboxServer({ port: 9000 });
};

// Shutdown any other server currently running
http
.request('http://localhost:9000/shutdown', { method: 'GET' }, launch)
.on('error', launch)
.end();
4 changes: 2 additions & 2 deletions ext/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ export default class API {
});
}

updateCache(id, values) {
updateCache(id, { response }) {
return fetch(`${this.apiURL.toString()}/cache`, {
headers: { 'Content-Type': 'application/json' },
method: 'POST',
body: JSON.stringify({
action: {
type: 'update',
payload: { id, values },
payload: { id, response },
},
}),
});
Expand Down
5 changes: 3 additions & 2 deletions ext/App.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('Web Extension', () => {
cy.get('@modal').contains('path');
cy.get('@modal').contains('/returnThisAsJson');

cy.get('[data-cy-id="modal-background"]').click({ force: true });
cy.get('[data-cy-id="back-to-waterfall"]').click();

cy.get('@modal').should('not.exist');

Expand All @@ -69,14 +69,15 @@ describe('Web Extension', () => {
cy.get('[data-cy-id="cache-detail"]').contains('path');
cy.get('[data-cy-id="cache-detail"]').contains('/returnThisAsJson');

cy.get('[data-cy-id="modal-background"]').click({ force: true });
cy.get('[data-cy-id="back-to-cache"]').click();

cy.get('[data-cy-id="cache-detail"]').should('not.exist');

// clear cache
cy.get('@test-edit').click();
cy.get('[data-cy-id="cache-delete"]').click();
cy.get('[data-cy-id="cache-detail"]').should('not.exist');

cy.get('@test-edit')
.should('not.exist')
.then(() => {
Expand Down
98 changes: 49 additions & 49 deletions ext/App.svelte
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
<script>
import { Router, Route } from 'svelte-routing';
import {
createHistory,
createMemorySource,
} from 'svelte-routing/src/history';
import { store, reducer } from './store.js';
import Cache from './Cache';
import Checkbox from './Checkbox.svelte';
import Waterfall from './Waterfall.svelte';
import SideNav from './SideNav.svelte';
import RequestInfo from './RequestInfo';
import Modal from './Modal.svelte';
import CacheEntry from './CacheEntry.svelte';
export let api;
const history = createHistory(createMemorySource());
const chrome = window.chrome;
let pauseChecked = false;
let cleanup;
let path = '/Waterfall';
let selection = null;
let url = '/';
api.getConfig().then((payload) => {
store.update((state) => reducer(state, { type: 'config', payload }));
Expand Down Expand Up @@ -50,53 +55,48 @@
</script>
<main class="Container">
<SideNav
onNavigation={(selection) => {
path = selection;
}}
{path}
/>
<div class="Box">
<div class="TopBar">
<Checkbox
checked={$store.config.paused}
inline
id="pause-proxy"
name="pause-proxy"
label="Pause Proxy"
onClick={() => {
api.pause(!$store.config.paused);
}}
/>
<Checkbox
inline
id="block-network"
name="block-network"
checked={$store.config.blockNetworkRequests}
label="Block Network"
onClick={() => {
api.blockNetworkRequests(!$store.config.blockNetworkRequests);
}}
/>
<Router {url} {history}>
<SideNav />
<div class="Box">
<div class="TopBar">
<Checkbox
checked={$store.config.paused}
inline
id="pause-proxy"
name="pause-proxy"
label="Pause Proxy"
onClick={() => {
api.pause(!$store.config.paused);
}}
/>
<Checkbox
inline
id="block-network"
name="block-network"
checked={$store.config.blockNetworkRequests}
label="Block Network"
onClick={() => {
api.blockNetworkRequests(!$store.config.blockNetworkRequests);
}}
/>
</div>
<Route path="/">
<Waterfall data={$store} {history} />
</Route>
<Route path="/cache">
<Cache cache={$store.cache} />
</Route>
<Route path="/cache/entry/:id" let:params>
<CacheEntry cacheEntry={$store.cache[params.id]} {api} {history} />
</Route>
<Route path="/request/:id" let:params>
<RequestInfo
response={$store.http[params.id].response}
request={$store.http[params.id].request}
/>
</Route>
</div>
{#if path === '/Waterfall'}
<Waterfall data={$store} onSelection={(value) => (selection = value)} />
{/if}
{#if path === '/Cache'}
<Cache
cache={$store.cache}
{api}
onSelection={(row) => {
selection = row;
}}
/>
{/if}
</div>
{#if selection}
<Modal on:close={() => (selection = null)}>
<RequestInfo {...selection} />
</Modal>
{/if}
</Router>
</main>
<style>
Expand Down
71 changes: 71 additions & 0 deletions ext/Cache.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import API from './Api';
import App from './App.svelte';

let api;
before(async () => {
await cy.task('set-jambox-config', {
blockNetworkRequests: false,
forward: {
'http://jambox-test.com': {
target: 'http://localhost:7777',
paths: ['**'],
},
},
cache: {
dir: '.jambox',
write: 'auto',
stage: ['jambox-test.com/**'],
},
});
api = await API.create();
});

describe('Cache UI', () => {
it('can edit response objects', () => {
cy.mount(App, { props: { api } });

// Additional requests to fill up the cache
cy.request('http://jambox-test.com/pathA');
cy.request('http://jambox-test.com/pathB');
cy.request('http://jambox-test.com/pathC');

cy.get('[data-cy-id="cache-link"]').click();
cy.get(
'[data-cy-id="cache-cell-edit-f4c55ab257c689845921746061bfeb73"]'
).as('test-edit');

cy.get('@test-edit').click();
cy.get('[data-cy-id="select-response-tab"]').click();

// Edit body
cy.get('[data-cy-id="select-response-tab"]').click();
cy.get(
'[data-path="%2Fbody"] > .jse-props > .jse-json-node > .jse-contents-outer > .jse-contents > .jse-value'
).dblclick();
cy.get('.jse-editable-div').clear();
cy.get('.jse-editable-div').type('foobar{enter}');
cy.get('[data-cy-id="update-response-btn"]').click();

// Close
cy.get('[data-cy-id="back-to-cache"]').click({ force: true });

// Open modal
cy.get('@test-edit').click();
cy.get('[data-cy-id="select-response-tab"]').click();
cy.get('[data-cy-id="cache-detail"]').contains('foobar');

// clear cache
cy.get('[data-cy-id="select-details-tab"]').click();
cy.get('[data-cy-id="cache-delete"]').click();
cy.get('[data-cy-id="cache-detail"]').should('not.exist');

cy.wait(1).then(() => {
// cleanup
return api.delete([
'ba20ccbb470042f3200692cad1926c1c',
'f4c55ab257c689845921746061bfeb73',
'cd4482b36a608021cd943786ecb54c5d',
]);
});
});
});
54 changes: 0 additions & 54 deletions ext/Cache/Breadcrumb.svelte

This file was deleted.

11 changes: 3 additions & 8 deletions ext/Cache/Cell.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script>
import { Link } from 'svelte-routing';
export let row;
export let col;
export let onEdit;
const shorten = (str) => {
if (str.length > 30) {
Expand All @@ -10,7 +10,6 @@
return str;
};
let value, cyID;
$: value =
col.key === 'host' || col.key === 'path'
Expand All @@ -21,12 +20,8 @@

<div class="Cell">
{#if col.key === 'edit'}
<button
inline
data-cy-id="cache-cell-{cyID}"
on:click={() => {
onEdit(row.id);
}}>Edit</button
<Link to="/cache/entry/{row.id}" data-cy-id="cache-cell-{cyID}"
>{row.id}</Link
>
{:else}
<span data-cy-id="cache-cell-{cyID}">{value}</span>
Expand Down
Loading

0 comments on commit 376b5e2

Please sign in to comment.