Skip to content

Commit c299130

Browse files
authored
feat(app): add forceUpdate URL param (#729)
1 parent 3e88a6e commit c299130

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

app/frontend/components/main-page.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export const MainPage = ({
5353
const params: Record<string, string | undefined> = Object.fromEntries(
5454
searchParams.entries()
5555
);
56-
const { page: pageParam } = params;
56+
const { page: pageParam, forceUpdate } = params;
5757

5858
const page = Number(pageParam ?? 1);
5959
const { isLoading, data, isFetching, error } = trpc.fetchCurrentPage.useQuery(
@@ -154,7 +154,9 @@ export const MainPage = ({
154154
)}
155155
<div className="mt-8">
156156
<UpdateImagesButton
157-
disabled={isFetching || !hasViewedAllPages}
157+
disabled={
158+
isFetching || (!hasViewedAllPages && forceUpdate !== 'true')
159+
}
158160
hasViewedAllPages={hasViewedAllPages}
159161
/>
160162
</div>

app/frontend/components/update-images-button.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ export const UpdateImagesButton: React.FC<{
124124
}
125125
};
126126

127+
const forceUpdate = params.forceUpdate === 'true';
127128
const shouldDisableAcceptVisualChangesButton =
129+
!forceUpdate &&
128130
acceptVisualChangesState !== AcceptVisualChangesTexts.NOT_ACCEPTED;
129131

130132
const showReviewPopover =

app/frontend/cypress/component/App.cy.tsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,42 @@ describe('App', () => {
276276
});
277277
});
278278

279+
describe('forceUpdate param case', () => {
280+
beforeEach(() => {
281+
cy.intercept('/trpc/fetchCurrentPage*', req => {
282+
const page = getPageFromRequest(req);
283+
const body = page === 2 ? secondPage : firstPage;
284+
req.reply(body);
285+
});
286+
cy.intercept('/trpc/acceptVisualChanges*', { body: mutationResponse }).as(
287+
'accept-visual-changes'
288+
);
289+
cy.mount(
290+
<MemoryRouter
291+
initialEntries={[
292+
'/?commitHash=123&bucket=bucket&repo=repo&owner=owner&forceUpdate=true'
293+
]}
294+
>
295+
<App />
296+
</MemoryRouter>
297+
);
298+
});
299+
300+
it('should enable accept visual changes button without viewing all pages', () => {
301+
cy.findByRole('button', { name: 'Accept visual changes' }).should(
302+
'be.enabled'
303+
);
304+
});
305+
306+
it('should allow accepting visual changes without viewing all pages', () => {
307+
cy.findByRole('button', { name: 'Accept visual changes' }).click();
308+
cy.findByText(/Are you sure/i);
309+
cy.findByRole('button', { name: 'Accept' }).click();
310+
cy.wait('@accept-visual-changes');
311+
cy.findByRole('button', { name: /Visual changes accepted/i });
312+
});
313+
});
314+
279315
describe('diffId param case', () => {
280316
beforeEach(() => {
281317
cy.intercept('/trpc/fetchCurrentPage*', req => {

0 commit comments

Comments
 (0)