From 3a5977991323cd277611a7ae5f80fc609dcf9622 Mon Sep 17 00:00:00 2001 From: George Lima Date: Tue, 22 Jan 2019 15:50:11 -0300 Subject: [PATCH] test(setup): add basics e2e tests --- __tests__/e2e/sidebar.test.js | 110 +++++++++++++++++++++++++++++++ __tests__/e2e/startup.test.js | 35 +++++++--- app/components/layout.js | 2 +- app/components/loading-screen.js | 2 +- app/components/sidebar.js | 16 ++--- 5 files changed, 144 insertions(+), 21 deletions(-) create mode 100644 __tests__/e2e/sidebar.test.js diff --git a/__tests__/e2e/sidebar.test.js b/__tests__/e2e/sidebar.test.js new file mode 100644 index 0000000..73701b1 --- /dev/null +++ b/__tests__/e2e/sidebar.test.js @@ -0,0 +1,110 @@ +// @flow + +import { getApp } from '../setup/utils'; + +const app = getApp(); + +beforeAll(async () => { + await app.start(); + await app.client.waitUntilWindowLoaded(); + await app.client.waitUntilTextExists('#sidebar', 'Dashboard', 120000); +}); +afterAll(() => app.stop()); + +describe('Sidebar', () => { + test('should see the active dashboard route', async () => { + await app.client.element('#sidebar a:nth-child(1)').click(); + + expect(await app.client.getUrl()).toEndWith('/'); + + expect( + await app.client.element('#sidebar a:nth-child(1)').getHTML(), + ).toEqual(expect.stringContaining('Dashboard')); + + expect( + await app.client + .element('#sidebar a:nth-child(1) img') + .getAttribute('src'), + ).toEqual(expect.stringContaining('/assets/dashboard_icon_active.svg')); + }); + + test('should see the active send route', async () => { + await app.client.element('#sidebar a:nth-child(2)').click(); + + expect(await app.client.getUrl()).toEndWith('/send'); + + expect( + await app.client.element('#sidebar a:nth-child(2)').getHTML(), + ).toEqual(expect.stringContaining('Send')); + + expect( + await app.client + .element('#sidebar a:nth-child(2) img') + .getAttribute('src'), + ).toEqual(expect.stringContaining('/assets/send_icon_active.svg')); + }); + + test('should see the active receive route', async () => { + await app.client.element('#sidebar a:nth-child(3)').click(); + + expect(await app.client.getUrl()).toEndWith('/receive'); + + expect( + await app.client.element('#sidebar a:nth-child(3)').getHTML(), + ).toEqual(expect.stringContaining('Receive')); + + expect( + await app.client + .element('#sidebar a:nth-child(3) img') + .getAttribute('src'), + ).toEqual(expect.stringContaining('/assets/receive_icon_active.svg')); + }); + + test('should see the active transactions route', async () => { + await app.client.element('#sidebar a:nth-child(4)').click(); + + expect(await app.client.getUrl()).toEndWith('/transactions'); + + expect( + await app.client.element('#sidebar a:nth-child(4)').getHTML(), + ).toEqual(expect.stringContaining('Transactions')); + + expect( + await app.client + .element('#sidebar a:nth-child(4) img') + .getAttribute('src'), + ).toEqual(expect.stringContaining('/assets/transactions_icon_active.svg')); + }); + + test('should see the active settings route', async () => { + await app.client.element('#sidebar a:nth-child(5)').click(); + + expect(await app.client.getUrl()).toEndWith('/settings'); + + expect( + await app.client.element('#sidebar a:nth-child(5)').getHTML(), + ).toEqual(expect.stringContaining('Settings')); + + expect( + await app.client + .element('#sidebar a:nth-child(5) img') + .getAttribute('src'), + ).toEqual(expect.stringContaining('/assets/settings_icon_active.svg')); + }); + + test('should see the active console route', async () => { + await app.client.element('#sidebar a:nth-child(6)').click(); + + expect(await app.client.getUrl()).toEndWith('/console'); + + expect( + await app.client.element('#sidebar a:nth-child(6)').getHTML(), + ).toEqual(expect.stringContaining('Console')); + + expect( + await app.client + .element('#sidebar a:nth-child(6) img') + .getAttribute('src'), + ).toEqual(expect.stringContaining('/assets/console_icon_active.svg')); + }); +}); diff --git a/__tests__/e2e/startup.test.js b/__tests__/e2e/startup.test.js index 803ac51..4584cb7 100644 --- a/__tests__/e2e/startup.test.js +++ b/__tests__/e2e/startup.test.js @@ -2,17 +2,34 @@ import { getApp } from '../setup/utils'; -describe('Zcash', () => { - const app = getApp(); +const app = getApp(); - beforeEach(() => app.start()); - afterEach(() => { - app.stop(); +beforeAll(async () => { + await app.start(); + await app.client.waitUntilWindowLoaded(); +}); +afterAll(() => app.stop()); + +describe('Startup', () => { + test('should open the window', async () => expect(await app.client.getWindowCount()).toEqual(1)); + + test('should have the right title', async () => { + expect(await app.client.getTitle()).toEqual('ZEC Wallet'); }); - test('should open the window', () => { - app.client - .getWindowCount() - .then((count: number) => expect(count).toEqual(1)); + test('should show the text "ZEC Wallet Starting" in loading screen', async () => { + expect(await app.client.getText('#loading-screen p')).toEqual( + 'ZEC Wallet Starting', + ); + }); + + test('should show the zcash logo in loading screen', async () => expect(await app.client.getAttribute('#loading-screen img', 'src')).toEqual( + expect.stringContaining('/assets/zcash-simple-icon.svg'), + )); + + test('should show the loading circle in loading screen', async () => { + expect( + await app.client.element('#loading-screen svg').isExisting(), + ).toEqual(true); }); }); diff --git a/app/components/layout.js b/app/components/layout.js index 703ed28..8841e65 100644 --- a/app/components/layout.js +++ b/app/components/layout.js @@ -21,5 +21,5 @@ export const LayoutComponent = (props: Props) => { // $FlowFixMe const { children } = props; // eslint-disable-line - return {children}; + return {children}; }; diff --git a/app/components/loading-screen.js b/app/components/loading-screen.js index 9e8d7e1..49df46a 100644 --- a/app/components/loading-screen.js +++ b/app/components/loading-screen.js @@ -36,7 +36,7 @@ const Logo = styled.img` `; export const LoadingScreen = ({ progress }: { progress: number }) => ( - + props.theme.colors.transitionEase}; &:hover { - color: ${/* eslint-disable-next-line max-len */ - props => (props.isActive - ? props.theme.colors.sidebarItemActive - : '#ddd')} + color: ${ + /* eslint-disable-next-line max-len */ + props => (props.isActive ? props.theme.colors.sidebarItemActive : '#ddd') +} background-color: ${props => props.theme.colors.sidebarHoveredItem}; } `; @@ -70,16 +70,12 @@ type Props = { }; export const SidebarComponent = ({ options, location }: Props) => ( - + {(options || []).map((item) => { const isActive = location.pathname === item.route; return ( - +