From 10a351a587317eb9c4e3a5aa710db7cfd1ab281d Mon Sep 17 00:00:00 2001 From: Cameron Dawson Date: Wed, 18 Sep 2019 12:48:44 -0700 Subject: [PATCH] Bug 1576966 - Convert app switch test to React Testing Library (#5383) --- tests/selenium/test_switch_app.py | 16 --------- tests/selenium/test_switch_repo.py | 9 ----- tests/selenium/test_view_single_result.py | 14 -------- tests/ui/job-view/App_test.jsx | 43 ++++++++++++++++++++++- 4 files changed, 42 insertions(+), 40 deletions(-) delete mode 100644 tests/selenium/test_switch_app.py delete mode 100644 tests/selenium/test_switch_repo.py delete mode 100644 tests/selenium/test_view_single_result.py diff --git a/tests/selenium/test_switch_app.py b/tests/selenium/test_switch_app.py deleted file mode 100644 index 324f497b7..000000000 --- a/tests/selenium/test_switch_app.py +++ /dev/null @@ -1,16 +0,0 @@ -from pages.treeherder import Treeherder - - -def test_switch_app(base_url, selenium, test_repository): - """Switch between Treeherder and Perfherder using header dropdown""" - page = Treeherder(selenium, base_url).open() - assert page.header.active_app == 'Treeherder' - page = page.switch_to_perfherder() - assert page.header.active_app == 'Perfherder' - page = page.switch_to_treeherder() - # Be aware that when switching back from Perfherder, it will try to - # default to mozilla-inbound, which does not exist in this test scenario. - # So part of this test is to ensure what happens when the ``repo`` param - # in the url is an invalid repo. We should still display the nav bars - # and a meaningful error message. - assert page.header.active_app == 'Treeherder' diff --git a/tests/selenium/test_switch_repo.py b/tests/selenium/test_switch_repo.py deleted file mode 100644 index ce5dea356..000000000 --- a/tests/selenium/test_switch_repo.py +++ /dev/null @@ -1,9 +0,0 @@ -from pages.treeherder import Treeherder - - -def test_switch_repo(base_url, selenium, test_repository, test_repository_2): - """Switch to new active watched repo""" - page = Treeherder(selenium, base_url).open() - assert test_repository.name == page.active_watched_repo - page.select_repository(test_repository_2.name) - assert test_repository_2.name == page.active_watched_repo diff --git a/tests/selenium/test_view_single_result.py b/tests/selenium/test_view_single_result.py deleted file mode 100644 index 08d145ff4..000000000 --- a/tests/selenium/test_view_single_result.py +++ /dev/null @@ -1,14 +0,0 @@ -from pages.treeherder import Treeherder - - -def test_open_single_result(base_url, selenium, test_commit): - page = Treeherder(selenium, base_url).open() - page.wait.until(lambda _: 1 == len(page.pushes)) - page.pushes[0].view() - page.wait.until(lambda _: len(page.pushes)) - assert 1 == len(page.pushes) - assert test_commit.author == page.pushes[0].author - assert test_commit.push.time.strftime('%a, %b %-d, %H:%M:%S') == page.pushes[0].datestamp - assert 1 == len(page.pushes[0].commits) - assert test_commit.revision[:12] == page.pushes[0].commits[0].revision - assert test_commit.comments == page.pushes[0].commits[0].comment diff --git a/tests/ui/job-view/App_test.jsx b/tests/ui/job-view/App_test.jsx index 78082867e..a98726ab9 100644 --- a/tests/ui/job-view/App_test.jsx +++ b/tests/ui/job-view/App_test.jsx @@ -1,6 +1,11 @@ import React from 'react'; import { fetchMock } from 'fetch-mock'; -import { render, cleanup, waitForElement } from '@testing-library/react'; +import { + render, + cleanup, + waitForElement, + fireEvent, +} from '@testing-library/react'; import App from '../../../ui/job-view/App'; import reposFixture from '../mock/repositories'; @@ -49,10 +54,30 @@ describe('App', () => { }, ], }); + fetchMock.get( + `begin:${getProjectUrl( + '/push/?full=true&count=11&push_timestamp', + 'try', + )}`, + { + results: [], + }, + ); fetchMock.get(`begin:${getApiUrl('/jobs/')}`, { results: [], meta: { repository: repoName, offset: 0, count: 2000 }, }); + + // Need to mock this function for the app switching tests. + // Source: https://github.com/mui-org/material-ui/issues/15726#issuecomment-493124813 + document.createRange = () => ({ + setStart: () => {}, + setEnd: () => {}, + commonAncestorContainer: { + nodeName: 'BODY', + ownerDocument: document, + }, + }); }); afterAll(() => cleanup); @@ -73,4 +98,20 @@ describe('App', () => { 'https://hg.mozilla.org/try/rev/3333333333335143b8df3f4b3e9b504dfbc589a0', ); }); + + test('should have links to Perfherder and Intermittent Failures View', async () => { + const { getByText, getByAltText } = render(); + const appMenu = await waitForElement(() => getByAltText('Treeherder')); + + expect(appMenu).toBeInTheDocument(); + fireEvent.click(appMenu); + + const phMenu = await waitForElement(() => getByText('Perfherder')); + expect(phMenu.getAttribute('href')).toBe('/perf.html'); + + const ifvMenu = await waitForElement(() => + getByText('Intermittent Failures View'), + ); + expect(ifvMenu.getAttribute('href')).toBe('/intermittent-failures.html'); + }); });