login.e2e.js 938 Bytes
Newer Older
偏右's avatar
偏右 committed
1 2 3 4 5 6
import Nightmare from 'nightmare';

describe('Login', () => {
  let page;
  beforeEach(() => {
    page = Nightmare();
afc163's avatar
afc163 committed
7 8 9 10 11 12
    page
      .goto('http://localhost:8000/')
      .evaluate(() => {
        window.localStorage.setItem('antd-pro-authority', 'guest');
      })
      .goto('http://localhost:8000/#/user/login');
偏右's avatar
偏右 committed
13 14 15 16 17 18
  });

  it('should login with failure', async () => {
    await page.type('#userName', 'mockuser')
      .type('#password', 'wrong_password')
      .click('button[type="submit"]')
afc163's avatar
afc163 committed
19
      .wait('.ant-alert-error') // should display error
偏右's avatar
偏右 committed
20 21 22
      .end();
  });

afc163's avatar
afc163 committed
23
  it('should login successfully', async () => {
偏右's avatar
偏右 committed
24 25 26
    const text = await page.type('#userName', 'admin')
      .type('#password', '888888')
      .click('button[type="submit"]')
afc163's avatar
afc163 committed
27
      .wait('.ant-layout-sider h1') // should display error
偏右's avatar
偏右 committed
28 29 30 31 32
      .evaluate(() => document.body.innerHTML)
      .end();
    expect(text).toContain('<h1>Ant Design Pro</h1>');
  });
});