From c12173233b74cea537c77328ab1b8af7130c767d Mon Sep 17 00:00:00 2001 From: Jake McDermott Date: Sun, 4 Mar 2018 16:11:45 -0500 Subject: [PATCH] add initial test and sanity check for search tags --- awx/ui/test/e2e/tests/test-searchez.js | 125 +++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 awx/ui/test/e2e/tests/test-searchez.js diff --git a/awx/ui/test/e2e/tests/test-searchez.js b/awx/ui/test/e2e/tests/test-searchez.js new file mode 100644 index 0000000000..9442ac66c0 --- /dev/null +++ b/awx/ui/test/e2e/tests/test-searchez.js @@ -0,0 +1,125 @@ +import { range } from 'lodash'; + +import { getAdminMachineCredential } from '../fixtures'; + +// AWX_E2E_URL='https://localhost:3000' npm --prefix awx/ui run e2e -- --filter="*jobz*" + +const spinny = 'div.spinny'; +const searchInput = 'smart-search input'; +const searchSubmit = 'smart-search i[class*="search"]'; +const searchTags = 'smart-search .SmartSearch-tagContainer'; +const searchClearAll = 'smart-search .SmartSearch-clearAll'; +const searchTagDelete = 'i[class*="fa-times"]'; + +const createTagSelector = n => `${searchTags}:nth-of-type(${n})`; +const createTagDeleteSelector = n => `${searchTags}:nth-of-type(${n}) ${searchTagDelete}`; + +const checkTags = (client, tags) => { + const strategy = 'css selector'; + + const countReached = createTagSelector(tags.length); + const countExceeded = createTagSelector(tags.length + 1); + + if (tags.length > 0) { + client.waitForElementVisible(countReached); + client.waitForElementNotPresent(countExceeded); + } + + client.elements(strategy, searchTags, tagElements => { + client.assert.equal(tagElements.value.length, tags.length); + + let n = -1; + tagElements.value.map(o => o.ELEMENT).forEach(id => { + client.elementIdText(id, ({ value }) => { + client.assert.equal(value, tags[++n]); + }); + }); + }); +}; + +module.exports = { + before: (client, done) => { + const resources = range(25).map(n => getAdminMachineCredential(`test-search-${n}`)); + Promise.all(resources).then(done); + }, + 'add and remove search tags': client => { + const credentials = client.page.credentials(); + + client.login(); + client.waitForAngular(); + + credentials.section.navigation.waitForElementVisible('@credentials'); + credentials.section.navigation.click('@credentials'); + + client.waitForElementVisible(spinny); + client.waitForElementNotVisible(spinny); + + client.waitForElementVisible(searchInput); + client.waitForElementVisible(searchSubmit); + + client.expect.element(searchInput).enabled; + client.expect.element(searchSubmit).enabled; + + checkTags(client, []); + + client.setValue(searchInput, 'foo'); + client.click(searchSubmit); + client.waitForElementVisible(spinny); + client.waitForElementNotVisible(spinny); + + checkTags(client, ['foo']); + + client.setValue(searchInput, 'bar e2e'); + client.click(searchSubmit); + client.waitForElementVisible(spinny); + client.waitForElementNotVisible(spinny); + + checkTags(client, ['foo', 'bar', 'e2e']); + + client.click(searchClearAll); + client.waitForElementVisible(spinny); + client.waitForElementNotVisible(spinny); + + checkTags(client, []); + + client.setValue(searchInput, 'fiz name:foo'); + client.click(searchSubmit); + client.waitForElementVisible(spinny); + client.waitForElementNotVisible(spinny); + + checkTags(client, ['fiz', 'name:foo']); + + client.click(searchClearAll); + client.waitForElementVisible(spinny); + client.waitForElementNotVisible(spinny); + + checkTags(client, []); + + client.setValue(searchInput, 'hello name:world fiz'); + client.click(searchSubmit); + client.waitForElementVisible(spinny); + client.waitForElementNotVisible(spinny); + + checkTags(client, ['hello', 'fiz', 'name:world']); + + client.click(createTagDeleteSelector(2)); + client.waitForElementVisible(spinny); + client.waitForElementNotVisible(spinny); + + checkTags(client, ['hello', 'name:world']); + + client.click(createTagDeleteSelector(1)); + client.waitForElementVisible(spinny); + client.waitForElementNotVisible(spinny); + + checkTags(client, ['name:world']); + + client.click(createTagDeleteSelector(1)); + client.waitForElementVisible(spinny); + client.waitForElementNotVisible(spinny); + + checkTags(client, []); + + client.end(); + }, +}; \ No newline at end of file