test('iterates over scoped items with a for of loop', async function(assert) {
    let page = create({
      foo: collection({
        scope: 'div',
        itemScope: 'span',

        item: {
          text: text()
        }
      })
    });

    await this.adapter.createTemplate(this, page, `
      <div>
          <span>Lorem</span>
          <span>Ipsum</span>
      </div>
    `);

    let textContents = [];

    withIteratorSymbolDefined(() => {
      for (let item of page.foo()) {
        textContents.push(item.text);
      }
    });

    assert.deepEqual(textContents, ['Lorem', 'Ipsum']);
  });
  test('does not mutate definition object', async function(assert) {
    let prop = text('.baz');
    let expected = {
      scope: '.a-scope',
      itemScope: '.another-scope',
      item: {
        baz: prop
      },

      bar: prop
    };
    let actual = {
      scope: '.a-scope',
      itemScope: '.another-scope',
      item: {
        baz: prop
      },

      bar: prop
    };

    let page = create({
      foo: collection(actual)
    });

    await this.adapter.createTemplate(this, page);

    assert.deepEqual(actual, expected);
  });
  test('iterates over scoped items with a forEach loop', async function(assert) {
    let page = create({
      foo: collection({
        scope: 'div',
        itemScope: 'span',

        item: {
          text: text()
        }
      })
    });

    await this.adapter.createTemplate(this, page, `
      <div>
          <span>Lorem</span>
          <span>Ipsum</span>
      </div>
    `);

    let textContents = [];

    page.foo().toArray().forEach(function(item) {
      textContents.push(item.text);
    });

    assert.deepEqual(textContents, ['Lorem', 'Ipsum']);
  });
  test('delegates configured methods to `toArray()`', async function(assert) {
    let page = create({
      foo: collection({
        itemScope: 'span',

        item: {
          isSpecial: hasClass('special'),
          text: text()
        }
      })
    });

    await this.adapter.createTemplate(this, page, `
      <span class="special">Lorem</span>
      <span>Ipsum</span>
    `);

    assert.deepEqual(page.foo().map((i) => i.text), ['Lorem', 'Ipsum']);
    assert.deepEqual(page.foo().mapBy('text'), ['Lorem', 'Ipsum']);

    assert.deepEqual(page.foo().filter((i) => i.isSpecial).map((i) => i.text), ['Lorem']);
    assert.deepEqual(page.foo().filterBy('isSpecial').map((i) => i.text), ['Lorem']);
    let textArray = [];
    page.foo().forEach((i) => {
      textArray.push(i.text);
    });
    assert.deepEqual(textArray, ['Lorem', 'Ipsum']);
  });
  test('resets scope for items', async function(assert) {
    let page = create({
      scope: 'div',

      foo: collection({
        resetScope: true,
        scope: '.scope',
        itemScope: 'span',

        item: {
          text: text()
        }
      })
    });

    await this.adapter.createTemplate(this, page, `
      <div>
        <span>Lorem</span>
      </div>
      <div class="scope">
        <span>Ipsum</span>
      </div>
    `);

    assert.equal(page.foo(0).text, 'Ipsum');
  });
  test('iterates over scoped items with a for loop', async function(assert) {
    let page = create({
      foo: collection({
        scope: 'div',
        itemScope: 'span',

        item: {
          text: text()
        }
      })
    });

    await this.adapter.createTemplate(this, page, `
      <div>
          <span>Lorem</span>
          <span>Ipsum</span>
      </div>
    `);

    let textContents = [];

    for (let i = 0; i < page.foo().count; i++) {
      let item = page.foo(i);
      textContents.push(item.text);
    }

    assert.deepEqual(textContents, ['Lorem', 'Ipsum']);
  });
  test('looks for elements inside the scope', async function(assert) {
    let page = create({
      scope: '.scope',

      foo: collection({
        itemScope: 'span',
        hola: 'mundo',

        item: {
          text: text()
        }
      })
    });

    await this.adapter.createTemplate(this, page, `
      <div>
        <span>Lorem</span>
      </div>
      <div class="scope">
        <span>Ipsum</span>
      </div>
    `);

    assert.equal(page.foo(0).text, 'Ipsum');
  });
test("doesn't show a deprecation warning when first parameter is a string", function(assert) {
  let page = create({
    foo: collection('foo')
  });

  page.foo;

  assert.expectNoDeprecation();
});
test('shows deprecation warning when first parameter is not a string', function(assert) {
  let page = create({
    foo: collection({
      itemScope: 'li'
    })
  });

  page.foo();

  assert.expectDeprecation('You are currently using the legacy collection API, check the documentation to see how to upgrade to the new API.');
});
Example #10
0
function existingRepositoriesCollection(scope) {
  return collection(`${scope} li.profile-repolist-item`, {
    name: text('a.profile-repo'),
    isActive: hasClass('active', '.switch'),
    isMigrated: isPresent('a.already-migrated'),
    isDisabled: hasClass('non-admin', 'a.profile-repo'),
    toggle: clickable('.switch'),
    ariaChecked: attribute('aria-checked', '.switch'),
    role: attribute('role', '.switch')
  });
}
  test("doesn't generate an item or itemScope property", async function(assert) {
    let page = create({
      foo: collection({
        itemScope: 'span',
        item: {}
      })
    });

    await this.adapter.createTemplate(this, page);

    assert.notOk(page.foo().item);
    assert.notOk(page.foo().itemScope);
  });
Example #12
0
function githubAppsRepositoryCollection(scope) {
  return collection(`${scope} li.profile-repolist-item`, {
    name: text('a.profile-repo'),

    isPublic: isPresent('.icon.public'),
    isPrivate: isPresent('.icon.private'),

    settings: {
      scope: '.profile-settings',
      isDisabled: hasClass('disabled')
    }
  });
}
  test('generates a count property', async function(assert) {
    let page = create({
      foo: collection({
        itemScope: 'span'
      })
    });

    await this.adapter.createTemplate(this, page, `
      <span>Lorem</span>
      <span>Ipsum</span>
    `);

    assert.equal(page.foo().count, 2);
  });
Example #14
0
export default scope => ({
  scope,

  isPresent: isPresent(),

  toggle: clickable('[data-test-dropdown-trigger]'),

  options: collection('[data-test-dropdown-option]', {
    testContainer: '#ember-testing',
    resetScope: true,
    label: text(),
    key: attribute('data-test-dropdown-option'),
    toggle: clickable('label'),
  }),
});
  test('sets correct scope to child collections', async function(assert) {
    let page = create({
      foo: collection({
        scope: '.scope',
        itemScope: 'span',

        item: {
          bar: collection({
            itemScope: 'em',
            item: {
              text: text()
            }
          })
        }
      })
    });

    await this.adapter.createTemplate(this, page, `
      <div><span><em>Lorem</em></span></div>
      <div class="scope"><span><em>Ipsum</em></span></div>
    `);

    assert.equal(page.foo(0).bar(0).text, 'Ipsum');
  });
  test('does not override custom count property', async function(assert) {
    let page = create({
      foo: collection({
        itemScope: 'span',

        count: 'custom count'
      })
    });

    await this.adapter.createTemplate(this, page, `
      <span>Lorem</span>
      <span>Ipsum</span>
    `);

    assert.equal(page.foo().count, 'custom count');
  });
  test('can provide custom array methods', async function(assert) {
    assert.expect(6);

    let page = create({
      foo: collection({
        toArray() {
          assert.ok(true, 'custom toArray allowed');
        },

        forEach() {
          assert.ok(true, 'custom forEach allowed');
        },

        map() {
          assert.ok(true, 'custom map allowed');
        },

        mapBy() {
          assert.ok(true, 'custom mapBy allowed');
        },

        filter() {
          assert.ok(true, 'custom filter allowed');
        },

        filterBy() {
          assert.ok(true, 'custom filterBy allowed');
        },

        itemScope: 'span'
      })
    });

    await this.adapter.createTemplate(
      this,
      page,
      '<span>Lorem</span><span>ipsum</span>',
      { useAlternateContainer: true }
    );

    page.foo().toArray();
    page.foo().forEach();
    page.foo().map();
    page.foo().mapBy();
    page.foo().filter();
    page.foo().filterBy();
  });
  test('returns collection\'s component', async function(assert) {
    let page = create({
      foo: collection({
        itemScope: 'span',

        text: text('button')
      })
    });

    await this.adapter.createTemplate(this, page, `
      <span>Lorem</span>
      <span>Second</span>
      <button>Submit</button>
    `);

    assert.equal(page.foo().text, 'Submit');
  });
  test("returns the page object path when collection's element doesn't exist", async function(assert) {
    let page = create({
      foo: {
        bar: collection({
          scope: 'span',
          itemScope: 'span',

          baz: {
            qux: text('span')
          }
        })
      }
    });

    await this.adapter.createTemplate(this, page);

    assert.throws(() => page.foo.bar().baz.qux, /page\.foo\.bar\(\)\.baz\.qux/);
  });
  test('returns an item', async function(assert) {
    let page = create({
      foo: collection({
        itemScope: 'span',

        item: {
          text: text()
        }
      })
    });

    await this.adapter.createTemplate(this, page, `
      <span>Lorem</span>
      <span>Ipsum</span>
    `);

    assert.equal(page.foo(0).text, 'Lorem');
    assert.equal(page.foo(1).text, 'Ipsum');
  });
  test('collection supports taking a page object directly as its definition', async function(assert){
    const textPage = create({
      spanText: text("span")
    });
    let page = create({
      scope: '.container',
      collection: collection("li", textPage)
    });

    await this.adapter.createTemplate(this, page, `
      <ul class="container">
        <li>Text <span>Lorem</span></li>
        <li>Text <span>Ipsum</span><>li<
      <ul>
    `);

    assert.equal(page.collection.objectAt(0).spanText, 'Lorem');
    assert.equal(page.collection.objectAt(1).spanText, 'Ipsum');
  });
  test('looks for elements inside multiple scopes', async function(assert) {
    let page = create({
      scope: '.scope',

      foo: collection({
        itemScope: 'li',

        item: {
          bar: {
            scope: '.another-scope',

            text: text('li', { at: 0 })
          }
        }
      })
    });

    await this.adapter.createTemplate(this, page, `
      <ul>
        <li>Blah</li>
        <li>
          <ul class="another-scope">
            <li>Lorem<li>
          </ul>
        </li>
      </ul>
      <ul class="scope">
        <li>Ipsum</li>
        <li>
          <ul>
            <li>Dolor</li>
          </ul>
          <ul class="another-scope">
            <li>Sit</li>
            <li>Amet</li>
          </ul>
        </li>
      </ul>
    `);

    assert.equal(page.foo(1).bar.text, 'Sit');
  });
  test('the collection definition can be composed from page objects', async function(assert){
    const textPage = create({
      spanText: text("span")
    });
    let page = create({
      scope: '.container',
      collection: collection("li", {
        textPage: textPage
      })
    });
    await this.adapter.createTemplate(this, page, `
      <ul class="container">
        <li>Text <span>Lorem</span></li>
        <li>Text <span>Ipsum</span><>li<
      <ul>
    `);

    assert.equal(page.collection.objectAt(0).textPage.spanText, 'Lorem');
    assert.equal(page.collection.objectAt(1).textPage.spanText, 'Ipsum');
  });
  test('new pages can be composed from pages containing collections', async function(assert) {
    let collectionPage = create({
      foo: collection('span', {
        text: text()
      })
    });

    let page = create({
      scope: '.container',
      collectionPage: collectionPage
    })
    await this.adapter.createTemplate(this, page, `
      <div class="container">
        <span>Lorem</span>
        <span>Ipsum</span>
      </div>
    `);
    assert.equal(page.collectionPage.foo.objectAt(0).text, 'Lorem');
    assert.equal(page.collectionPage.foo.objectAt(1).text, 'Ipsum');
  });
  test('legacy collections support taking a page object as the "item" definition directly', async function(assert) {
    let textPage = {
      text: text()
    };
    let page = create({
      foo: collection({
        itemScope: 'span',

        item: textPage
      })
    });
    await this.adapter.createTemplate(this, page, `
      <div class="container">
        <span>Lorem</span>
        <span>Ipsum</span>
      </div>
    `);

    assert.equal(page.foo(0).text, 'Lorem');
    assert.equal(page.foo(1).text, 'Ipsum');
  });
  test('collects an array of items', async function(assert) {
    let page = create({
      foo: collection({
        itemScope: 'span',

        item: {
          text: text()
        }
      })
    });

    await this.adapter.createTemplate(this, page, `
      <span>Lorem</span>
      <span>Ipsum</span>
    `);

    let array = page.foo().toArray();
    assert.equal(array.length, 2);
    assert.equal(array[0].text, 'Lorem');
    assert.equal(array[1].text, 'Ipsum');
  });
  test('looks for elements inside collection\'s scope (collection component)', async function(assert) {
    let page = create({
      foo: collection({
        scope: '.scope',
        itemScope: 'li',

        text: text('span')
      })
    });

    await this.adapter.createTemplate(this, page, `
      <div>
        <span>Lorem</span>
      </div>
      <div class="scope">
        <span>Ipsum</span>
      </div>
    `);

    assert.equal(page.foo().text, 'Ipsum');
  });
  test('looks for elements inside collection\'s scope', async function(assert) {
    let page = create({
      foo: collection({
        scope: '.scope',
        itemScope: 'li',

        item: {
          text: text()
        }
      })
    });

    await this.adapter.createTemplate(this, page, `
      <ul>
        <li>Lorem</li>
      </ul>
      <ul class="scope">
        <li>Ipsum</li>
      </ul>
    `);

    assert.equal(page.foo(0).text, 'Ipsum');
  });
  test('looks for elements within test container specified', async function(assert) {
    assert.expect(2);

    let expectedContext = '#alternate-ember-testing';
    let page;

    page = create({
      foo: collection({
        testContainer: expectedContext,
        itemScope: 'span'
      })
    });

    await this.adapter.createTemplate(
      this,
      page,
      '<span>Lorem</span><span>ipsum</span>',
      { useAlternateContainer: true }
    );

    assert.equal(page.foo().count, 2);
    assert.equal(page.foo(0).text, 'Lorem');
  });
  test('legacy collections support composition', async function(assert) {
    let collectionPage = create({
      foo: collection({
        itemScope: 'span',

        item: {
          text: text()
        }
      })
    });
    let page = create({
      scope: '.container',
      collectionPage: collectionPage
    });
    await this.adapter.createTemplate(this, page, `
      <div class="container">
        <span>Lorem</span>
        <span>Ipsum</span>
      </div>
    `);

    assert.equal(page.collectionPage.foo(0).text, 'Lorem');
    assert.equal(page.collectionPage.foo(1).text, 'Ipsum');
  });