Bug 1572095 - Fix commit/revision links after changing repo

This commit is contained in:
Cameron Dawson 2019-08-12 08:45:53 -07:00
Родитель 76871f8fac
Коммит 8ad1b1fec0
2 изменённых файлов: 86 добавлений и 1 удалений

Просмотреть файл

@ -0,0 +1,80 @@
import React from 'react';
import { fetchMock } from 'fetch-mock';
import { render, cleanup, waitForElement } from '@testing-library/react';
import App from '../../../ui/job-view/App';
import reposFixture from '../mock/repositories';
import pushListFixture from '../mock/push_list';
import { getApiUrl } from '../../../ui/helpers/url';
import { getProjectUrl, setUrlParam } from '../../../ui/helpers/location';
describe('App', () => {
const repoName = 'autoland';
beforeAll(() => {
fetchMock.get('/revision.txt', []);
fetchMock.get(getApiUrl('/repository/'), reposFixture);
fetchMock.get(getApiUrl('/user/'), []);
fetchMock.get(getApiUrl('/failureclassification/'), []);
fetchMock.get('begin:https://treestatus.mozilla-releng.net/trees/', {
result: {
message_of_the_day: '',
reason: '',
status: 'open',
tree: repoName,
},
});
fetchMock.get(
getProjectUrl('/push/?full=true&count=10', repoName),
pushListFixture,
);
fetchMock.get(getProjectUrl('/push/?full=true&count=10', 'try'), {
results: [
{
id: 111111,
revision: '3333333333335143b8df3f4b3e9b504dfbc589a0',
author: 'whozat@gmail.com',
revision_count: 1,
push_timestamp: 1562867957,
repository_id: 4,
revisions: [
{
repository_id: 4,
revision: '3333333333335143b8df3f4b3e9b504dfbc589a0',
author: 'whozat <whozat@gmail.com>',
comments: 'didathing',
},
],
},
],
});
fetchMock.get(`begin:${getProjectUrl('/jobs/', repoName)}`, {
results: [],
meta: { repository: repoName, offset: 0, count: 2000 },
});
fetchMock.get(`begin:${getProjectUrl('/jobs/', 'try')}`, {
results: [],
meta: { repository: repoName, offset: 0, count: 2000 },
});
});
afterAll(() => cleanup);
test('changing repo updates ``currentRepo``', async () => {
setUrlParam('repo', repoName);
const { getByText } = render(<App />);
const revisionDefault = await waitForElement(() =>
getByText('ba9c692786e9'),
);
expect(revisionDefault).toBeInTheDocument();
setUrlParam('repo', 'try');
await waitForElement(() => getByText('333333333333'));
expect(document.querySelector('.revision a').getAttribute('href')).toBe(
'https://hg.mozilla.org/try/rev/3333333333335143b8df3f4b3e9b504dfbc589a0',
);
});
});

Просмотреть файл

@ -193,7 +193,9 @@ class App extends React.Component {
setCurrentRepoTreeStatus = status => {
const link = document.head.querySelector('link[rel="shortcut icon"]');
link.href = thFavicons[status] || thFavicons.open;
if (link) {
link.href = thFavicons[status] || thFavicons.open;
}
};
getAllShownJobs = pushId => {
@ -220,13 +222,16 @@ class App extends React.Component {
};
handleUrlChanges = ev => {
const { repos } = this.state;
const { newURL, oldURL } = ev;
const urlParams = getAllUrlParams();
const newRepo = urlParams.get('repo');
// We only want to set state if any of these or the filter values have changed
const newState = {
hasSelectedJob: getAllUrlParams().has('selectedJob'),
groupCountsExpanded: urlParams.get('group_state') === 'expanded',
duplicateJobsVisible: urlParams.get('duplicate_jobs') === 'visible',
currentRepo: repos.find(repo => repo.name === newRepo),
};
const oldState = pick(this.state, Object.keys(newState));