Skip to content

Commit

Permalink
Update e2e tests for PageContainer (#718)
Browse files Browse the repository at this point in the history
  • Loading branch information
GoelBiju committed Aug 4, 2021
1 parent 7c0f9b7 commit bbcd3ff
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,38 @@ describe('PageContainer Component', () => {

cy.get('[aria-label="container-breadcrumbs"]').should('exist');

cy.get('[aria-label="container-table-count"]').should('exist');
cy.get('[aria-label="container-view-count"]').should('exist');

cy.get('[aria-label="container-table-search"]').should('exist');
cy.get('[aria-label="container-view-search"]').should('exist');

cy.get('[aria-label="container-table-cart"]').should('exist');
cy.get('[aria-label="container-view-cart"]').should('exist');

cy.get('[aria-label="container-table"]').should('exist');
cy.get('[aria-label="container-view"]').should('exist');
});

it('should display correct entity count', () => {
// Check that the entity count has displayed correctly.
cy.get('[aria-label="container-table-count"]')
cy.get('[aria-label="container-view-count"]')
.should('be.visible')
.contains('Results: 239');
});

it('should display number of items in cart correctly', () => {
// Check that the download cart has displayed correctly.
cy.get('[aria-label="container-table-cart-badge"]', { timeout: 10000 })
cy.get('[aria-label="container-view-cart-badge"]', { timeout: 10000 })
.children()
.should('be.hidden');

cy.get('[aria-label="card-button-1"]', { timeout: 10000 }).eq(0).click();

cy.get('[aria-label="container-table-cart-badge"]', { timeout: 10000 })
cy.get('[aria-label="container-view-cart-badge"]', { timeout: 10000 })
.children()
.should('not.be.hidden')
.contains('1');

cy.get('[aria-label="card-button-1"]', { timeout: 10000 }).eq(1).click();

cy.get('[aria-label="container-table-cart-badge"]', { timeout: 10000 })
cy.get('[aria-label="container-view-cart-badge"]', { timeout: 10000 })
.children()
.should('not.be.hidden')
.contains('2');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ describe('PageContainer Component', () => {

cy.get('[aria-label="container-breadcrumbs"]').should('exist');

cy.get('[aria-label="container-table-count"]').should('exist');
cy.get('[aria-label="container-view-count"]').should('exist');

cy.get('[aria-label="container-table-search"]').should('exist');
cy.get('[aria-label="container-view-search"]').should('exist');

cy.get('[aria-label="container-table-cart"]').should('exist');
cy.get('[aria-label="container-view-cart"]').should('exist');

cy.get('[aria-label="container-table"]').should('exist');
cy.get('[aria-label="container-view"]').should('exist');
});

it('should display correct entity count', () => {
// Check that the entity count has displayed correctly.
cy.get('[aria-label="container-table-count"]')
cy.get('[aria-label="container-view-count"]')
.should('be.visible')
.contains('Results: 239');
});

it('should display number of items in cart correctly', () => {
cy.get('[aria-label="container-table-cart-badge"]', { timeout: 10000 })
cy.get('[aria-label="container-view-cart-badge"]', { timeout: 10000 })
.children()
.should('be.hidden');

Expand All @@ -36,7 +36,7 @@ describe('PageContainer Component', () => {
'be.checked'
);

cy.get('[aria-label="container-table-cart-badge"]', { timeout: 10000 })
cy.get('[aria-label="container-view-cart-badge"]', { timeout: 10000 })
.children()
.should('not.be.hidden')
.contains('1');
Expand All @@ -46,7 +46,7 @@ describe('PageContainer Component', () => {
'be.checked'
);

cy.get('[aria-label="container-table-cart-badge"]', { timeout: 10000 })
cy.get('[aria-label="container-view-cart-badge"]', { timeout: 10000 })
.children()
.should('not.be.hidden')
.contains('2');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ exports[`PageContainer - Tests displays the correct entity count 1`] = `
/>
</WithStyles(ForwardRef(Grid))>
<WithStyles(ForwardRef(Grid))
aria-label="container-table"
aria-label="container-view"
item={true}
xs={12}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe('PageContainer - Tests', () => {
);

wrapper
.find('[aria-label="container-table-search"]')
.find('[aria-label="container-view-search"]')
.first()
.simulate('click');

Expand All @@ -139,7 +139,7 @@ describe('PageContainer - Tests', () => {
);

wrapper
.find('[aria-label="container-table-cart"]')
.find('[aria-label="container-view-cart"]')
.first()
.simulate('click');

Expand Down Expand Up @@ -235,6 +235,63 @@ describe('PageContainer - Tests', () => {
).toEqual('loading.filter_message');
});

it('switches view button display when clicked', () => {
// Mock getElementById so that it returns truthy.
const testElement = document.createElement('DIV');
document.getElementById = jest.fn(() => testElement);
state = JSON.parse(
JSON.stringify({
dgcommon: {
...dGCommonInitialState,
totalDataCount: 0,
loadedCount: true,
query: {
...dGCommonInitialState.query,
},
},
dgdataview: dgDataViewInitialState,
router: {
action: 'POP',
location: createLocation(paths.toggle.investigation),
},
})
);

const mockStore = configureStore([thunk]);
const testStore = mockStore(state);
const wrapper = mount(
<Provider store={testStore}>
<MemoryRouter
initialEntries={[
{
key: 'testKey',
pathname: '/browse/investigation',
},
]}
>
<PageContainer />
</MemoryRouter>
</Provider>
);

expect(wrapper.find('[aria-label="container-view"]').exists()).toBeTruthy();
expect(
wrapper.find('[aria-label="container-view-button"]').first().text()
).toEqual('app.view_cards');

// Click view button
wrapper
.find('[aria-label="container-view-button"]')
.first()
.simulate('click');
wrapper.update();

// Check that the text on the button has changed
expect(
wrapper.find('[aria-label="container-view-button"]').first().text()
).toEqual('app.view_table');
});

it('display filter warning on toggle table', () => {
// Mock getElementById so that it returns truthy.
const testElement = document.createElement('DIV');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export const NavBar = (props: {
item
sm={2}
xs={3}
aria-label="container-table-count"
aria-label="container-view-count"
>
<Route
exact
Expand Down Expand Up @@ -212,7 +212,7 @@ export const NavBar = (props: {
<IconButton
className="tour-dataview-search-icon"
onClick={props.navigateToSearch}
aria-label="container-table-search"
aria-label="container-view-search"
style={{ margin: 'auto' }}
>
<SearchIcon />
Expand All @@ -230,15 +230,15 @@ export const NavBar = (props: {
<IconButton
className="tour-dataview-cart-icon"
onClick={props.navigateToDownload}
aria-label="container-table-cart"
aria-label="container-view-cart"
style={{ margin: 'auto' }}
>
<Badge
badgeContent={
props.cartItems.length > 0 ? props.cartItems.length : null
}
color="primary"
aria-label="container-table-cart-badge"
aria-label="container-view-cart-badge"
>
<ShoppingCartIcon />
</Badge>
Expand Down Expand Up @@ -550,8 +550,8 @@ class PageContainer extends React.Component<
</Grid>
)}

{/* Hold the table for remainder of the page */}
<Grid item xs={12} aria-label="container-table">
{/* Hold the view for remainder of the page */}
<Grid item xs={12} aria-label="container-view">
{document.getElementById('datagateway-dataview') && (
<ViewRouting
view={this.props.query.view}
Expand Down

0 comments on commit bbcd3ff

Please sign in to comment.