github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/web/wats/test/resource.js (about)

     1  import test from 'ava';
     2  import Suite from '../helpers/suite';
     3  
     4  test.beforeEach(async t => {
     5    t.context = new Suite();
     6    await t.context.init(t);
     7  });
     8  
     9  test.afterEach(async t => {
    10    t.context.passed(t);
    11  });
    12  
    13  test.afterEach.always(async t => {
    14    await t.context.finish(t);
    15  });
    16  
    17  const pinButtonSelector = '[aria-label="Pin Resource Version"]';
    18  const versionInPinBarSelector = '#pin-bar table';
    19  const topBarPinIconSelector = '#pin-icon';
    20  
    21  test('can unpin from top bar when pinned version is not in the versions list', async t => {
    22    await setupPipeline(t);
    23    await pinVersion(t);
    24    await resetVersionsList(t);
    25    await unpinVersionUsingTopBar(t);
    26    await reloadPageAndCheckResourceIsStillNotPinned(t);
    27    t.pass();
    28  });
    29  
    30  async function setupPipeline(t) {
    31    await t.context.fly.run('set-pipeline -n -p pipeline -c fixtures/before-pin.yml');
    32    await t.context.fly.run('unpause-pipeline -p pipeline');
    33    await t.context.fly.run('check-resource -r pipeline/resource');
    34  }
    35  
    36  async function pinVersion(t) {
    37    await goToResourcePage(t);
    38    await t.context.web.clickAndWait(pinButtonSelector, versionInPinBarSelector);
    39  }
    40  
    41  async function resetVersionsList(t) {
    42    await t.context.fly.run('set-pipeline -n -p pipeline -c fixtures/after-pin.yml');
    43    await t.context.fly.run('check-resource -r pipeline/resource');
    44  }
    45  
    46  async function unpinVersionUsingTopBar(t) {
    47    await goToResourcePage(t);
    48    await t.context.web.page.waitFor(topBarPinIconSelector);
    49    await t.context.web.page.click(topBarPinIconSelector);
    50    await checkNoVersionInPinBar(t);
    51  }
    52  
    53  async function reloadPageAndCheckResourceIsStillNotPinned(t) {
    54    await goToResourcePage(t);
    55    await checkNoVersionInPinBar(t);
    56  }
    57  
    58  async function goToResourcePage(t) {
    59    let url = `/teams/${t.context.teamName}/pipelines/pipeline/resources/resource`;
    60    await t.context.web.page.goto(t.context.web.route(url));
    61    await waitForPageLoad(t);
    62  }
    63  
    64  async function checkNoVersionInPinBar(t) {
    65    await t.context.web.page.waitFor(() => !document.querySelector('#pin-bar table'));
    66  }
    67  
    68  async function waitForPageLoad(t) {
    69    await t.context.web.page.waitFor(pinButtonSelector);
    70  }