Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add component tests for filterdropdown component #41

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions nightwatch/components/filterdropdown.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Component, useState } from 'react';
import FilterDropdown from '../../src/components/FilterDropdown';
import GlobalStyles from '../../src/components/GlobalStyles';
import { GlobalContextProvider } from '../utils/TestGlobalContextProvider';

export default {
title: 'FilterDropdown Component',
component: FilterDropdown
};

export const FilterDropdownComponent = () => {
const [filterContext, setFilterContext] = useState('All Tests');

return (
<>
<GlobalContextProvider
value={{
metadata: { date: '2022-12-21T09:07:54.770Z' }
}}>
<GlobalStyles />
<FilterDropdown filterContext={filterContext} setFilterContext={setFilterContext}/>
</GlobalContextProvider>
</>
);
};

FilterDropdownComponent.test = async (browser, { component }) => {
const filterDropdownButton = element('button[aria-label="Customize options"]');

// Testing whether the button is visible
browser.expect(filterDropdownButton).to.be.visible;
// Testing whether the button is clickable
browser.element('button[aria-label="Customize options"]').click();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Along with "All test" text assertion, after selecting another option, assert the text.

// Testing whether the button shows "All Tests" as default selection
browser.expect(filterDropdownButton).text.to.equal('All Tests');
};