mirror of
https://github.com/ansible/awx.git
synced 2026-03-20 18:37:39 -02:30
Updates a couple of team list checkbox tests to test the UI rather than state/props internals. Fixes bug where select all was selected on load.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { DataListCheck as PFDataListCheck } from '@patternfly/react-core';
|
import { DataListCheck as PFDataListCheck } from '@patternfly/react-core';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
|
|
||||||
|
PFDataListCheck.displayName = 'PFDataListCheck';
|
||||||
export default styled(PFDataListCheck)`
|
export default styled(PFDataListCheck)`
|
||||||
padding-top: 18px;
|
padding-top: 18px;
|
||||||
@media screen and (min-width: 768px) {
|
@media screen and (min-width: 768px) {
|
||||||
|
|||||||
@@ -12,13 +12,13 @@ const mockMe = {
|
|||||||
is_system_auditor: false,
|
is_system_auditor: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
describe.only('<Host />', () => {
|
describe('<Host />', () => {
|
||||||
test('initially renders succesfully', () => {
|
test('initially renders succesfully', () => {
|
||||||
HostsAPI.readDetail.mockResolvedValue({ data: mockDetails });
|
HostsAPI.readDetail.mockResolvedValue({ data: mockDetails });
|
||||||
mountWithContexts(<Host setBreadcrumb={() => {}} me={mockMe} />);
|
mountWithContexts(<Host setBreadcrumb={() => {}} me={mockMe} />);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should show content error when user attempts to navigate to erroneous route', async done => {
|
test('should show content error when user attempts to navigate to erroneous route', async () => {
|
||||||
const history = createMemoryHistory({
|
const history = createMemoryHistory({
|
||||||
initialEntries: ['/hosts/1/foobar'],
|
initialEntries: ['/hosts/1/foobar'],
|
||||||
});
|
});
|
||||||
@@ -41,6 +41,5 @@ describe.only('<Host />', () => {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
await waitForElement(wrapper, 'ContentError', el => el.length === 1);
|
await waitForElement(wrapper, 'ContentError', el => el.length === 1);
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ class HostsList extends Component {
|
|||||||
|
|
||||||
const canAdd =
|
const canAdd =
|
||||||
actions && Object.prototype.hasOwnProperty.call(actions, 'POST');
|
actions && Object.prototype.hasOwnProperty.call(actions, 'POST');
|
||||||
const isAllSelected = selected.length === hosts.length;
|
const isAllSelected = selected.length > 0 && selected.length === hosts.length;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ InventoriesAPI.readDetail.mockResolvedValue({
|
|||||||
data: mockInventory,
|
data: mockInventory,
|
||||||
});
|
});
|
||||||
|
|
||||||
describe.only('<Inventory />', () => {
|
describe('<Inventory />', () => {
|
||||||
test('initially renders succesfully', async done => {
|
test('initially renders succesfully', async done => {
|
||||||
const wrapper = mountWithContexts(
|
const wrapper = mountWithContexts(
|
||||||
<Inventory setBreadcrumb={() => {}} match={{ params: { id: 1 } }} />
|
<Inventory setBreadcrumb={() => {}} match={{ params: { id: 1 } }} />
|
||||||
@@ -29,7 +29,7 @@ describe.only('<Inventory />', () => {
|
|||||||
await waitForElement(wrapper, '.pf-c-tabs__item', el => el.length === 6);
|
await waitForElement(wrapper, '.pf-c-tabs__item', el => el.length === 6);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
test('should show content error when user attempts to navigate to erroneous route', async done => {
|
test('should show content error when user attempts to navigate to erroneous route', async () => {
|
||||||
const history = createMemoryHistory({
|
const history = createMemoryHistory({
|
||||||
initialEntries: ['/inventories/inventory/1/foobar'],
|
initialEntries: ['/inventories/inventory/1/foobar'],
|
||||||
});
|
});
|
||||||
@@ -49,6 +49,5 @@ describe.only('<Inventory />', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
await waitForElement(wrapper, 'ContentError', el => el.length === 1);
|
await waitForElement(wrapper, 'ContentError', el => el.length === 1);
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ class InventoriesList extends Component {
|
|||||||
const { match, i18n } = this.props;
|
const { match, i18n } = this.props;
|
||||||
const canAdd =
|
const canAdd =
|
||||||
actions && Object.prototype.hasOwnProperty.call(actions, 'POST');
|
actions && Object.prototype.hasOwnProperty.call(actions, 'POST');
|
||||||
const isAllSelected = selected.length === inventories.length;
|
const isAllSelected = selected.length > 0 && selected.length === inventories.length;
|
||||||
return (
|
return (
|
||||||
<PageSection>
|
<PageSection>
|
||||||
<Card>
|
<Card>
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ InventoriesAPI.readDetail.mockResolvedValue({
|
|||||||
data: mockSmartInventory,
|
data: mockSmartInventory,
|
||||||
});
|
});
|
||||||
|
|
||||||
describe.only('<SmartInventory />', () => {
|
describe('<SmartInventory />', () => {
|
||||||
test('initially renders succesfully', async done => {
|
test('initially renders succesfully', async done => {
|
||||||
const wrapper = mountWithContexts(
|
const wrapper = mountWithContexts(
|
||||||
<SmartInventory setBreadcrumb={() => {}} match={{ params: { id: 1 } }} />
|
<SmartInventory setBreadcrumb={() => {}} match={{ params: { id: 1 } }} />
|
||||||
@@ -29,7 +29,7 @@ describe.only('<SmartInventory />', () => {
|
|||||||
await waitForElement(wrapper, '.pf-c-tabs__item', el => el.length === 4);
|
await waitForElement(wrapper, '.pf-c-tabs__item', el => el.length === 4);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
test('should show content error when user attempts to navigate to erroneous route', async done => {
|
test('should show content error when user attempts to navigate to erroneous route', async () => {
|
||||||
const history = createMemoryHistory({
|
const history = createMemoryHistory({
|
||||||
initialEntries: ['/inventories/smart_inventory/1/foobar'],
|
initialEntries: ['/inventories/smart_inventory/1/foobar'],
|
||||||
});
|
});
|
||||||
@@ -52,6 +52,5 @@ describe.only('<SmartInventory />', () => {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
await waitForElement(wrapper, 'ContentError', el => el.length === 1);
|
await waitForElement(wrapper, 'ContentError', el => el.length === 1);
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ async function getOrganizations(params) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
describe.only('<Organization />', () => {
|
describe('<Organization />', () => {
|
||||||
test('initially renders succesfully', () => {
|
test('initially renders succesfully', () => {
|
||||||
OrganizationsAPI.readDetail.mockResolvedValue({ data: mockOrganization });
|
OrganizationsAPI.readDetail.mockResolvedValue({ data: mockOrganization });
|
||||||
OrganizationsAPI.read.mockImplementation(getOrganizations);
|
OrganizationsAPI.read.mockImplementation(getOrganizations);
|
||||||
@@ -77,7 +77,7 @@ describe.only('<Organization />', () => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should show content error when user attempts to navigate to erroneous route', async done => {
|
test('should show content error when user attempts to navigate to erroneous route', async () => {
|
||||||
const history = createMemoryHistory({
|
const history = createMemoryHistory({
|
||||||
initialEntries: ['/organizations/1/foobar'],
|
initialEntries: ['/organizations/1/foobar'],
|
||||||
});
|
});
|
||||||
@@ -100,6 +100,5 @@ describe.only('<Organization />', () => {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
await waitForElement(wrapper, 'ContentError', el => el.length === 1);
|
await waitForElement(wrapper, 'ContentError', el => el.length === 1);
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ async function getOrganizations() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
describe.only('<Project />', () => {
|
describe('<Project />', () => {
|
||||||
test('initially renders succesfully', () => {
|
test('initially renders succesfully', () => {
|
||||||
ProjectsAPI.readDetail.mockResolvedValue({ data: mockDetails });
|
ProjectsAPI.readDetail.mockResolvedValue({ data: mockDetails });
|
||||||
OrganizationsAPI.read.mockImplementation(getOrganizations);
|
OrganizationsAPI.read.mockImplementation(getOrganizations);
|
||||||
@@ -68,7 +68,7 @@ describe.only('<Project />', () => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should show content error when user attempts to navigate to erroneous route', async done => {
|
test('should show content error when user attempts to navigate to erroneous route', async () => {
|
||||||
const history = createMemoryHistory({
|
const history = createMemoryHistory({
|
||||||
initialEntries: ['/projects/1/foobar'],
|
initialEntries: ['/projects/1/foobar'],
|
||||||
});
|
});
|
||||||
@@ -91,6 +91,5 @@ describe.only('<Project />', () => {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
await waitForElement(wrapper, 'ContentError', el => el.length === 1);
|
await waitForElement(wrapper, 'ContentError', el => el.length === 1);
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ class ProjectsList extends Component {
|
|||||||
|
|
||||||
const canAdd =
|
const canAdd =
|
||||||
actions && Object.prototype.hasOwnProperty.call(actions, 'POST');
|
actions && Object.prototype.hasOwnProperty.call(actions, 'POST');
|
||||||
const isAllSelected = selected.length === projects.length;
|
const isAllSelected = selected.length > 0 && selected.length === projects.length;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
|
|||||||
@@ -15,6 +15,13 @@ import TeamDetail from './TeamDetail';
|
|||||||
import TeamEdit from './TeamEdit';
|
import TeamEdit from './TeamEdit';
|
||||||
import { TeamsAPI } from '@api';
|
import { TeamsAPI } from '@api';
|
||||||
|
|
||||||
|
const CardHeader = styled(PFCardHeader)`
|
||||||
|
--pf-c-card--first-child--PaddingTop: 0;
|
||||||
|
--pf-c-card--child--PaddingLeft: 0;
|
||||||
|
--pf-c-card--child--PaddingRight: 0;
|
||||||
|
position: relative;
|
||||||
|
`;
|
||||||
|
|
||||||
class Team extends Component {
|
class Team extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
@@ -73,13 +80,6 @@ class Team extends Component {
|
|||||||
{ name: i18n._(t`Access`), link: `${match.url}/access`, id: 2 },
|
{ name: i18n._(t`Access`), link: `${match.url}/access`, id: 2 },
|
||||||
];
|
];
|
||||||
|
|
||||||
const CardHeader = styled(PFCardHeader)`
|
|
||||||
--pf-c-card--first-child--PaddingTop: 0;
|
|
||||||
--pf-c-card--child--PaddingLeft: 0;
|
|
||||||
--pf-c-card--child--PaddingRight: 0;
|
|
||||||
position: relative;
|
|
||||||
`;
|
|
||||||
|
|
||||||
let cardHeader = (
|
let cardHeader = (
|
||||||
<CardHeader style={{ padding: 0 }}>
|
<CardHeader style={{ padding: 0 }}>
|
||||||
<RoutedTabs
|
<RoutedTabs
|
||||||
|
|||||||
@@ -33,14 +33,14 @@ async function getTeams() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
describe.only('<Team />', () => {
|
describe('<Team />', () => {
|
||||||
test('initially renders succesfully', () => {
|
test('initially renders succesfully', () => {
|
||||||
TeamsAPI.readDetail.mockResolvedValue({ data: mockTeam });
|
TeamsAPI.readDetail.mockResolvedValue({ data: mockTeam });
|
||||||
TeamsAPI.read.mockImplementation(getTeams);
|
TeamsAPI.read.mockImplementation(getTeams);
|
||||||
mountWithContexts(<Team setBreadcrumb={() => {}} me={mockMe} />);
|
mountWithContexts(<Team setBreadcrumb={() => {}} me={mockMe} />);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should show content error when user attempts to navigate to erroneous route', async done => {
|
test('should show content error when user attempts to navigate to erroneous route', async () => {
|
||||||
const history = createMemoryHistory({
|
const history = createMemoryHistory({
|
||||||
initialEntries: ['/teams/1/foobar'],
|
initialEntries: ['/teams/1/foobar'],
|
||||||
});
|
});
|
||||||
@@ -63,6 +63,5 @@ describe.only('<Team />', () => {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
await waitForElement(wrapper, 'ContentError', el => el.length === 1);
|
await waitForElement(wrapper, 'ContentError', el => el.length === 1);
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ class TeamsList extends Component {
|
|||||||
|
|
||||||
const canAdd =
|
const canAdd =
|
||||||
actions && Object.prototype.hasOwnProperty.call(actions, 'POST');
|
actions && Object.prototype.hasOwnProperty.call(actions, 'POST');
|
||||||
const isAllSelected = selected.length === teams.length;
|
const isAllSelected = selected.length > 0 && selected.length === teams.length;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
|
|||||||
@@ -53,10 +53,7 @@ describe('<TeamsList />', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TeamsAPI.read = () =>
|
TeamsAPI.read = () =>
|
||||||
Promise.resolve({
|
Promise.resolve({
|
||||||
data: {
|
data: mockAPITeamsList.data,
|
||||||
count: 0,
|
|
||||||
results: [],
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
TeamsAPI.readOptions = () =>
|
TeamsAPI.readOptions = () =>
|
||||||
Promise.resolve({
|
Promise.resolve({
|
||||||
@@ -73,32 +70,43 @@ describe('<TeamsList />', () => {
|
|||||||
mountWithContexts(<TeamsList />);
|
mountWithContexts(<TeamsList />);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Puts 1 selected Team in state when handleSelect is called.', () => {
|
test('Selects one team when row is checked', async () => {
|
||||||
wrapper = mountWithContexts(<TeamsList />).find('TeamsList');
|
wrapper = mountWithContexts(<TeamsList />);
|
||||||
|
await waitForElement(
|
||||||
wrapper.setState({
|
wrapper,
|
||||||
teams: mockAPITeamsList.data.results,
|
'TeamsList',
|
||||||
itemCount: 3,
|
el => el.state('hasContentLoading') === false
|
||||||
isInitialized: true,
|
);
|
||||||
});
|
expect(wrapper.find('input[type="checkbox"]').findWhere(n => n.prop('checked') === true).length).toBe(0);
|
||||||
|
wrapper
|
||||||
|
.find('TeamListItem').at(0)
|
||||||
|
.find('DataListCheck')
|
||||||
|
.props()
|
||||||
|
.onChange(true);
|
||||||
wrapper.update();
|
wrapper.update();
|
||||||
expect(wrapper.state('selected').length).toBe(0);
|
expect(wrapper.find('input[type="checkbox"]').findWhere(n => n.prop('checked') === true).length).toBe(1);
|
||||||
wrapper.instance().handleSelect(mockAPITeamsList.data.results.slice(0, 1));
|
|
||||||
expect(wrapper.state('selected').length).toBe(1);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Puts all Teams in state when handleSelectAll is called.', () => {
|
test('Select all checkbox selects and unselects all rows', async () => {
|
||||||
wrapper = mountWithContexts(<TeamsList />);
|
wrapper = mountWithContexts(<TeamsList />);
|
||||||
const list = wrapper.find('TeamsList');
|
await waitForElement(
|
||||||
list.setState({
|
wrapper,
|
||||||
teams: mockAPITeamsList.data.results,
|
'TeamsList',
|
||||||
itemCount: 3,
|
el => el.state('hasContentLoading') === false
|
||||||
isInitialized: true,
|
);
|
||||||
});
|
expect(wrapper.find('input[type="checkbox"]').findWhere(n => n.prop('checked') === true).length).toBe(0);
|
||||||
expect(list.state('selected').length).toBe(0);
|
wrapper
|
||||||
list.instance().handleSelectAll(true);
|
.find('Checkbox#select-all')
|
||||||
|
.props()
|
||||||
|
.onChange(true);
|
||||||
wrapper.update();
|
wrapper.update();
|
||||||
expect(list.state('selected').length).toEqual(list.state('teams').length);
|
expect(wrapper.find('input[type="checkbox"]').findWhere(n => n.prop('checked') === true).length).toBe(4);
|
||||||
|
wrapper
|
||||||
|
.find('Checkbox#select-all')
|
||||||
|
.props()
|
||||||
|
.onChange(false);
|
||||||
|
wrapper.update();
|
||||||
|
expect(wrapper.find('input[type="checkbox"]').findWhere(n => n.prop('checked') === true).length).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('api is called to delete Teams for each team in selected.', () => {
|
test('api is called to delete Teams for each team in selected.', () => {
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ class TeamListItem extends React.Component {
|
|||||||
<Link
|
<Link
|
||||||
id={labelId}
|
id={labelId}
|
||||||
to={`${detailUrl}`}
|
to={`${detailUrl}`}
|
||||||
style={{ marginRight: '10px' }}
|
|
||||||
>
|
>
|
||||||
<b>{team.name}</b>
|
<b>{team.name}</b>
|
||||||
</Link>
|
</Link>
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ describe('<Template />', () => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should show content error when user attempts to navigate to erroneous route', async done => {
|
test('should show content error when user attempts to navigate to erroneous route', async () => {
|
||||||
const history = createMemoryHistory({
|
const history = createMemoryHistory({
|
||||||
initialEntries: ['/templates/job_template/1/foobar'],
|
initialEntries: ['/templates/job_template/1/foobar'],
|
||||||
});
|
});
|
||||||
@@ -111,6 +111,5 @@ describe('<Template />', () => {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
await waitForElement(wrapper, 'ContentError', el => el.length === 1);
|
await waitForElement(wrapper, 'ContentError', el => el.length === 1);
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user