Skip to content

Commit

Permalink
test: content search filters
Browse files Browse the repository at this point in the history
  • Loading branch information
rboixaderg committed Dec 26, 2023
1 parent cd3eed0 commit ae615f2
Show file tree
Hide file tree
Showing 8 changed files with 930 additions and 109 deletions.
2 changes: 2 additions & 0 deletions e2e/cypress/elements/panels-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export const ITEMS_PANELS_SELECTORS = {
btnDeleteAction: "[data-test='dropdownItemTest-delete']",
btnMoveAction: "[data-test='dropdownItemTest-move']",
prefixItem: 'itemTest',
prefixFilterItem: 'filterInput',
prefixSortableItem: 'sortableColumn',
}

export const CONTEXT_TOOLBAR_SELECTORS = {
Expand Down
73 changes: 49 additions & 24 deletions e2e/cypress/integration/content-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ LOGIN_TYPES.forEach((loginType) => {
cy.clearCookies()
cy.login(loginType)

cy.interceptGetObject('@canido**')
cy.interceptGetObject('@addable-types')

cy.get(ITEMS_PANELS_SELECTORS.table)
Expand All @@ -24,36 +23,26 @@ LOGIN_TYPES.forEach((loginType) => {
cy.addContent('second folder', 'second-folder', 'btnAddFolder')
cy.addContent('first item', 'first-item', 'btnAddItem')
cy.addContent('second item', 'second-item', 'btnAddItem')
cy.addGMI('Test GMI item', 'test-gmi-item')
cy.addGMI({
name: 'Test GMI item',
id: 'test-gmi-item',
})

cy.get(CONTEXT_TOOLBAR_SELECTORS.selectFilteType).select('Item')
cy.get(ITEMS_PANELS_SELECTORS.table)
.find('tbody')
.find('tr')
.its('length')
.should('eq', 2)
cy.totalItemsInTable(ITEMS_PANELS_SELECTORS.table, 2)

cy.get(CONTEXT_TOOLBAR_SELECTORS.selectFilteType).select('Folder')
cy.get(ITEMS_PANELS_SELECTORS.table)
.find('tbody')
.find('tr')
.its('length')
.should('eq', 2)
cy.totalItemsInTable(ITEMS_PANELS_SELECTORS.table, 2)

cy.get(CONTEXT_TOOLBAR_SELECTORS.selectFilteType).select('GMI')
cy.get(ITEMS_PANELS_SELECTORS.table)
.find('tbody')
.find('tr')
.its('length')
.should('eq', 1)
cy.totalItemsInTable(ITEMS_PANELS_SELECTORS.table, 1)
})

it('Search items in first level', () => {
cy.interceptGetObject('test-folder')
cy.interceptGetObject('@search**')

cy.wait('@get-object-@addable-types')
cy.wait('@get-object-@canido**')

cy.addContent('First item', 'first-item', 'btnAddItem')
cy.addContent('Second Item', 'second-item', 'btnAddItem')
Expand All @@ -75,15 +64,51 @@ LOGIN_TYPES.forEach((loginType) => {
)}/`
)
cy.wait('@get-object-@addable-types')
cy.wait('@get-object-@canido**')

cy.get(CONTEXT_TOOLBAR_SELECTORS.selectFilteType).select('Item')
cy.wait('@get-object-@search**')
cy.get(ITEMS_PANELS_SELECTORS.table)
.find('tbody')
.find('tr')
.its('length')
.should('eq', 2)
cy.totalItemsInTable(ITEMS_PANELS_SELECTORS.table, 2)
})

it('Creates 20 GMI and use the filters', () => {
cy.findByText('GMI Folder').click()
cy.get(
`[data-test='${ITEMS_PANELS_SELECTORS.prefixFilterItem}choice_field']`
).select('keyword')
cy.totalItemsInTable(ITEMS_PANELS_SELECTORS.table, 8)

cy.get(
`[data-test='${ITEMS_PANELS_SELECTORS.prefixFilterItem}choice_field']`
).select('date')

cy.totalItemsInTable(ITEMS_PANELS_SELECTORS.table, 9)
cy.get(`[data-test='tag-date']`).find('button').click()
cy.totalItemsInTable(ITEMS_PANELS_SELECTORS.table, 10)
cy.get(
`[data-test='${ITEMS_PANELS_SELECTORS.prefixFilterItem}boolean_field']`
).select('false')
cy.findAllByText('25 items', { exact: false })
cy.get(`[data-test='tag-false']`).find('button').click()
cy.findAllByText('50 items', { exact: false })
cy.get(
`[data-test='${ITEMS_PANELS_SELECTORS.prefixFilterItem}number_field']`
)
.clear()
.type('19')
cy.totalItemsInTable(ITEMS_PANELS_SELECTORS.table, 1)
})

it('Sort by name', () => {
cy.findByText('GMI Folder').click()
cy.findByText('Test GMI item 0').should('not.exist')
cy.get(
`[data-test='${ITEMS_PANELS_SELECTORS.prefixSortableItem}title']`
).click()
cy.findByText('Test GMI item 9').should('exist')
cy.get(
`[data-test='${ITEMS_PANELS_SELECTORS.prefixSortableItem}title']`
).click()
cy.findByText('Test GMI item 0').should('exist')
})
})
})
5 changes: 5 additions & 0 deletions e2e/cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { setupGuillotina, tearDownGuillotina } from './guillotina'
import '@testing-library/cypress/add-commands'

beforeEach('Setup guillotina', function () {
setupGuillotina()
Expand Down Expand Up @@ -27,3 +28,7 @@ Cypress.Commands.add('setLocalStorage', (key, value) => {
window.localStorage.setItem(key, value)
})
})

Cypress.Commands.add('totalItemsInTable', (key, total) => {
cy.get(key).find('tbody').find('tr').its('length').should('eq', total)
})
41 changes: 22 additions & 19 deletions e2e/cypress/support/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,25 @@ Cypress.Commands.add('addContent', (name, id, selector) => {
cy.get(NOTIFICATION_SELECTOR).should('contain', 'Content created!')
})

Cypress.Commands.add('addGMI', (name, id) => {
// Create GMI item
cy.get(CONTEXT_TOOLBAR_SELECTORS.btnAddType).click()
cy.get(CONTEXT_TOOLBAR_SELECTORS.btnAddGMI).click()
cy.get(FORM_SELECTORS.containerGMI).should('contain', 'Add GMI')
cy.get(`[data-test='title${FORM_BASE_SELECTORS.prefixField}']`).type(name)
cy.get(`[data-test='uuid${FORM_BASE_SELECTORS.prefixField}']`).should(
'have.value',
id
)
cy.get(`[data-test='number_field${FORM_BASE_SELECTORS.prefixField}']`).type(
'5'
)
cy.get(`[data-test='choice_field${FORM_BASE_SELECTORS.prefixField}']`).select(
'keyword'
)
cy.get(FORM_BASE_SELECTORS.btn).click()
cy.get(NOTIFICATION_SELECTOR).should('contain', 'Content created!')
})
Cypress.Commands.add(
'addGMI',
({ name, id, number = '5', choice = 'keyword' }) => {
// Create GMI item
cy.get(CONTEXT_TOOLBAR_SELECTORS.btnAddType).click()
cy.get(CONTEXT_TOOLBAR_SELECTORS.btnAddGMI).click()
cy.get(FORM_SELECTORS.containerGMI).should('contain', 'Add GMI')
cy.get(`[data-test='title${FORM_BASE_SELECTORS.prefixField}']`).type(name)
cy.get(`[data-test='uuid${FORM_BASE_SELECTORS.prefixField}']`).should(
'have.value',
id
)
cy.get(`[data-test='number_field${FORM_BASE_SELECTORS.prefixField}']`).type(
number
)
cy.get(
`[data-test='choice_field${FORM_BASE_SELECTORS.prefixField}']`
).select(choice)
cy.get(FORM_BASE_SELECTORS.btn).click()
cy.get(NOTIFICATION_SELECTOR).should('contain', 'Content created!')
}
)
34 changes: 34 additions & 0 deletions e2e/cypress/support/guillotina.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,40 @@ export function setupGuillotina() {
user_groups: ['group_view_content'],
},
}).then(() => console.log('default user added'))

cy.request({
method: 'POST',
url: `${api_url}/${Cypress.env('GUILLOTINA_CONTAINER')}`,
headers,
body: {
'@type': 'Folder',
id: 'gmi_folder',
title: 'GMI Folder',
},
}).then(() => {
for (let i = 0; i < 50; i++) {
cy.request({
method: 'POST',
url: `${api_url}/${Cypress.env('GUILLOTINA_CONTAINER')}/gmi_folder`,
headers,
body: {
'@type': 'GMI',
title: `Test GMI item ${i}`,
number_field: i,
boolean_field: i % 2 === 0,
choice_field_vocabulary: ['plone', 'guillotina'][i % 2],
choice_field: [
'date',
'integer',
'text',
'float',
'keyword',
'boolean',
][i % 6],
},
}).then(() => console.log('default user added'))
}
})
}

export function tearDownGuillotina() {
Expand Down
Loading

0 comments on commit ae615f2

Please sign in to comment.