Skip to content

Commit

Permalink
Remove useless code
Browse files Browse the repository at this point in the history
  • Loading branch information
willdurand committed Apr 24, 2019
1 parent 479a276 commit 78d961a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 48 deletions.
36 changes: 0 additions & 36 deletions src/pages/Compare/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -478,42 +478,6 @@ describe(__filename, () => {
expect(dispatchSpy).not.toHaveBeenCalled();
});

it('dispatches viewVersionFile() on mount if the query string contains a `path` that is different than `version.selectedPath`', () => {
const path = 'a/different/file.js';
const history = createFakeHistory({
location: createFakeLocation({
search: queryString.stringify({ path }),
}),
});
const {
_viewVersionFile,
dispatchSpy,
fakeThunk,
version,
} = loadDiffAndRender({ history });

expect(dispatchSpy).toHaveBeenCalledWith(fakeThunk.thunk);
expect(dispatchSpy).toHaveBeenCalledTimes(1);
expect(_viewVersionFile).toHaveBeenCalledWith({
versionId: version.id,
selectedPath: path,
preserveHash: true,
});
});

it('does not dispatch viewVersionFile() on mount when `path` is equal to the selected path', () => {
const version = fakeVersionWithDiff;
const history = createFakeHistory({
location: createFakeLocation({
search: queryString.stringify({ path: version.file.selected_file }),
}),
});

const { dispatchSpy } = loadDiffAndRender({ history });

expect(dispatchSpy).not.toHaveBeenCalled();
});

it('dispatches fetchDiff() with the path specified in the URL on mount', () => {
const addonId = 9999;
const baseVersionId = 1;
Expand Down
25 changes: 13 additions & 12 deletions src/pages/Compare/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ export class CompareBase extends React.Component<Props> {

const path = getPathFromQueryString(history);

if (!version) {
if (version === null) {
// An error has occured when fetching the version.
return;
}

if (version === undefined) {
dispatch(
_fetchDiff({
addonId: parseInt(addonId, 10),
Expand All @@ -87,18 +92,14 @@ export class CompareBase extends React.Component<Props> {
return;
}

// We do not want to update the selected path again (e.g., when a keyboard
// navigation updates the selected path), so we apply this logic to the
// first render (mount) only.
if (!prevProps) {
if (path && path !== version.selectedPath) {
// We preserve the hash in the URL (if any) when we load the file from
// an URL that has likely be shared.
this.viewVersionFile(path, { preserveHash: true });
}
} else if (
(prevProps.version &&
version.selectedPath !== prevProps.version.selectedPath) ||
return;
}

if (
(prevProps &&
(prevProps.version &&
version.selectedPath !== prevProps.version.selectedPath)) ||
addonId !== prevProps.match.params.addonId ||
baseVersionId !== prevProps.match.params.baseVersionId ||
headVersionId !== prevProps.match.params.headVersionId
Expand Down

0 comments on commit 78d961a

Please sign in to comment.