Chore: SharedPreferences tests (#51132)

* Add a test assertion function to make testing a little bit easier

* Add tests for SharedPreferences

* Remove some tests from UserProfileEditPage because we're testing SharedPreferences directly now
This commit is contained in:
Josh Hunt
2022-06-21 09:36:34 +01:00
committed by GitHub
parent 05fbfdaa13
commit 47abf44224
3 changed files with 165 additions and 16 deletions
@@ -90,8 +90,6 @@ const defaultProps: Props = {
};
function getSelectors() {
const dashboardSelect = () => screen.getByTestId('User preferences home dashboard drop down');
const timepickerSelect = () => screen.getByTestId(selectors.components.TimeZonePicker.containerV2);
const teamsTable = () => screen.getByRole('table', { name: /user teams table/i });
const orgsTable = () => screen.getByTestId(selectors.components.UserProfile.orgsTable);
const sessionsTable = () => screen.getByTestId(selectors.components.UserProfile.sessionsTable);
@@ -100,10 +98,6 @@ function getSelectors() {
email: () => screen.getByRole('textbox', { name: /email/i }),
username: () => screen.getByRole('textbox', { name: /username/i }),
saveProfile: () => screen.getByTestId(selectors.components.UserProfile.profileSaveButton),
dashboardSelect,
dashboardValue: () => within(dashboardSelect()).getByText(/default/i),
timepickerSelect,
timepickerValue: () => within(timepickerSelect()).getByText(/coordinated universal time/i),
savePreferences: () => screen.getByTestId(selectors.components.UserProfile.preferencesSaveButton),
teamsTable,
teamsRow: () => within(teamsTable()).getByRole('row', { name: /team one team.one@test\.com 2000/i }),
@@ -166,16 +160,8 @@ describe('UserProfileEditPage', () => {
it('should show shared preferences', async () => {
await getTestContext();
const { dashboardSelect, dashboardValue, timepickerSelect, timepickerValue, savePreferences } = getSelectors();
expect(screen.getByRole('group', { name: /preferences/i })).toBeInTheDocument();
expect(screen.getByRole('radio', { name: /default/i })).toBeInTheDocument();
expect(screen.getByRole('radio', { name: /dark/i })).toBeInTheDocument();
expect(screen.getByRole('radio', { name: /light/i })).toBeInTheDocument();
expect(dashboardSelect()).toBeInTheDocument();
expect(dashboardValue()).toBeInTheDocument();
expect(timepickerSelect()).toBeInTheDocument();
expect(timepickerValue()).toBeInTheDocument();
expect(savePreferences()).toBeInTheDocument();
// SharedPreferences itself is tested, so here just make sure it's being rendered
expect(screen.getByLabelText('Home Dashboard')).toBeInTheDocument();
});
describe('and teams are loading', () => {