Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
The translation of the application affected the tests.

Signed-off-by: Alexander Burmatov <[email protected]>
  • Loading branch information
Future998 committed Nov 6, 2024
1 parent 0eef473 commit 68487ff
Show file tree
Hide file tree
Showing 13 changed files with 102 additions and 102 deletions.
22 changes: 11 additions & 11 deletions src/__tests__/Explore/Explore.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ describe('Explore component', () => {
it('displays the no data message if no data is received', async () => {
jest.spyOn(api, 'get').mockResolvedValue({ status: 200, data: { data: { GlobalSearch: { Repos: [] } } } });
render(<StateExploreWrapper />);
expect(await screen.findByText(/Looks like/i)).toBeInTheDocument();
expect(await screen.findByText(/explore.noResults/i)).toBeInTheDocument();
});

it('renders signature icons', async () => {
Expand All @@ -344,17 +344,17 @@ describe('Explore component', () => {

const allUntrustedSignaturesIcons = await screen.findAllByTestId("untrusted-icon");
fireEvent.mouseOver(allUntrustedSignaturesIcons[0]);
expect(await screen.findByText("Signed-by: Unknown")).toBeInTheDocument();
expect(await screen.findByText("signatureTooltip.signedBy: main.unknown")).toBeInTheDocument();
const allTrustedSignaturesIcons = await screen.findAllByTestId("verified-icon");
fireEvent.mouseOver(allTrustedSignaturesIcons[8]);
expect(await screen.findByText("Tool: cosign")).toBeInTheDocument();
expect(await screen.findByText("Signed-by: author1")).toBeInTheDocument();
expect(await screen.findByText("signatureTooltip.tool: cosign")).toBeInTheDocument();
expect(await screen.findByText("signatureTooltip.signedBy: author1")).toBeInTheDocument();
fireEvent.mouseOver(allTrustedSignaturesIcons[9]);
expect(await screen.findByText("Tool: notation")).toBeInTheDocument();
expect(await screen.findByText("Signed-by: author2")).toBeInTheDocument();
expect(await screen.findByText("signatureTooltip.tool: notation")).toBeInTheDocument();
expect(await screen.findByText("signatureTooltip.signedBy: author2")).toBeInTheDocument();
const allNoSignedIcons = await screen.findAllByTestId("unverified-icon");
fireEvent.mouseOver(allNoSignedIcons[0]);
expect(await screen.findByText("Not signed")).toBeInTheDocument();
expect(await screen.findByText("signatureTooltip.notSigned")).toBeInTheDocument();
});

it('renders vulnerability icons', async () => {
Expand All @@ -379,12 +379,12 @@ describe('Explore component', () => {
it("should render the sort filter and be able to change it's value", async () => {
jest.spyOn(api, 'get').mockResolvedValue({ status: 200, data: { data: mockImageList } });
render(<StateExploreWrapper />);
const selectFilter = await screen.findByText('Relevance');
const selectFilter = await screen.findByText('sortCriteria.relevance');
expect(selectFilter).toBeInTheDocument();
userEvent.click(selectFilter);
const newOption = await screen.findByText('Alphabetical');
const newOption = await screen.findByText('sortCriteria.alphabetical');
userEvent.click(newOption);
expect(await screen.findByText('Alphabetical')).toBeInTheDocument();
expect(await screen.findByText('sortCriteria.alphabetical')).toBeInTheDocument();
});

it('should get preselected filters and sorting order from query params', async () => {
Expand Down Expand Up @@ -412,7 +412,7 @@ describe('Explore component', () => {
await userEvent.click(windowsCheckbox);
expect(windowsCheckbox).toBeChecked();
expect(await screen.findAllByTestId('repo-card')).toHaveLength(1);
const signedCheckboxLabel = await screen.findByText(/signed images/i);
const signedCheckboxLabel = await screen.findByText(/filterConstants.signedImages/i);
jest.spyOn(api, 'get').mockResolvedValueOnce({ status: 200, data: { data: filteredMockImageListSigned() } });
await userEvent.click(signedCheckboxLabel);
expect(await screen.findAllByTestId('repo-card')).toHaveLength(6);
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/HomePage/Home.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ describe('Home component', () => {
jest.spyOn(api, 'get').mockResolvedValueOnce({ status: 200, data: { data: mockImageListBookmarks } });
jest.spyOn(api, 'get').mockResolvedValueOnce({ status: 200, data: { data: mockImageListStars } });
render(<HomeWrapper />);
const viewAllButtons = await screen.findAllByText(/view all/i);
const viewAllButtons = await screen.findAllByText(/home.viewAll/i);
expect(viewAllButtons).toHaveLength(4);
jest.spyOn(api, 'get').mockResolvedValue({ status: 200, data: { data: [] } });
fireEvent.click(viewAllButtons[0]);
Expand Down
40 changes: 20 additions & 20 deletions src/__tests__/LoginPage/SignIn.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ describe('Sign in form', () => {

it('should change username and password values on user input', async () => {
render(<SignIn isLoggedIn={false} setIsLoggedIn={() => {}} />);
const usernameInput = await screen.findByLabelText(/^Username/i);
const passwordInput = await screen.findByLabelText(/^Enter Password/i);
const usernameInput = await screen.findByLabelText(/^signIn.username/i);
const passwordInput = await screen.findByLabelText(/^signIn.enterPassword/i);
fireEvent.change(usernameInput, { target: { value: 'test' } });
fireEvent.change(passwordInput, { target: { value: 'test' } });
expect(usernameInput).toHaveValue('test');
Expand All @@ -60,8 +60,8 @@ describe('Sign in form', () => {

it('should display error if username and password values are empty after change', async () => {
render(<SignIn isLoggedIn={false} setIsLoggedIn={() => {}} />);
const usernameInput = await screen.findByLabelText(/^Username/i);
const passwordInput = await screen.findByLabelText(/^Enter Password/i);
const usernameInput = await screen.findByLabelText(/^signIn.username/i);
const passwordInput = await screen.findByLabelText(/^signIn.enterPassword/i);
userEvent.click(usernameInput);
userEvent.type(usernameInput, 't');
userEvent.type(usernameInput, '{backspace}');
Expand All @@ -77,13 +77,13 @@ describe('Sign in form', () => {
it('should log in the user and navigate to homepage if login is successful using button', async () => {
render(<SignIn isLoggedIn={false} setIsLoggedIn={() => {}} />);

const usernameInput = await screen.findByLabelText(/^Username/i);
const passwordInput = await screen.findByLabelText(/^Enter Password/i);
const usernameInput = await screen.findByLabelText(/^signIn.username/i);
const passwordInput = await screen.findByLabelText(/^signIn.enterPassword/i);
userEvent.type(usernameInput, 'test');
userEvent.type(passwordInput, 'test');

jest.spyOn(api, 'get').mockResolvedValue({ status: 200, data: { data: {} } });
const submitButton = await screen.findByText('Continue');
const submitButton = await screen.findByText('signIn.continue');
fireEvent.click(submitButton);
await waitFor(() => {
expect(mockedUsedNavigate).toHaveBeenCalledWith('/home');
Expand All @@ -93,7 +93,7 @@ describe('Sign in form', () => {
it('should display an error if username is blank and login is attempted using button', async () => {
render(<SignIn isLoggedIn={false} setIsLoggedIn={() => {}} />);

const passwordInput = await screen.findByLabelText(/^Enter Password/i);
const passwordInput = await screen.findByLabelText(/^signIn.enterPassword/i);
userEvent.type(passwordInput, 'test');
const submitButton = await screen.findByTestId('basic-auth-submit-btn');
fireEvent.click(submitButton);
Expand All @@ -108,7 +108,7 @@ describe('Sign in form', () => {
it('should display an error if password is blank and login is attempted using button', async () => {
render(<SignIn isLoggedIn={false} setIsLoggedIn={() => {}} />);

const usernameInput = await screen.findByLabelText(/^Username/i);
const usernameInput = await screen.findByLabelText(/^signIn.username/i);
userEvent.type(usernameInput, 'test');
const submitButton = await screen.findByTestId('basic-auth-submit-btn');
fireEvent.click(submitButton);
Expand Down Expand Up @@ -136,8 +136,8 @@ describe('Sign in form', () => {
it('should log in the user and navigate to homepage if login is successful using enter key on username field', async () => {
render(<SignIn isLoggedIn={false} setIsLoggedIn={() => {}} />);

const usernameInput = await screen.findByLabelText(/^Username/i);
const passwordInput = await screen.findByLabelText(/^Enter Password/i);
const usernameInput = await screen.findByLabelText(/^signIn.username/i);
const passwordInput = await screen.findByLabelText(/^signIn.enterPassword/i);
userEvent.type(usernameInput, 'test');
userEvent.type(passwordInput, 'test');

Expand All @@ -151,8 +151,8 @@ describe('Sign in form', () => {
it('should log in the user and navigate to homepage if login is successful using enter key on password field', async () => {
render(<SignIn isLoggedIn={false} setIsLoggedIn={() => {}} />);

const usernameInput = await screen.findByLabelText(/^Username/i);
const passwordInput = await screen.findByLabelText(/^Enter Password/i);
const usernameInput = await screen.findByLabelText(/^signIn.username/i);
const passwordInput = await screen.findByLabelText(/^signIn.enterPassword/i);
userEvent.type(usernameInput, 'test');
userEvent.type(passwordInput, 'test');

Expand All @@ -166,7 +166,7 @@ describe('Sign in form', () => {
it('should display an error if username is blank and login is attempted using enter key', async () => {
render(<SignIn isLoggedIn={false} setIsLoggedIn={() => {}} />);

const passwordInput = await screen.findByLabelText(/^Enter Password/i);
const passwordInput = await screen.findByLabelText(/^signIn.enterPassword/i);
userEvent.type(passwordInput, 'test');
userEvent.type(passwordInput, '{enter}');

Expand All @@ -180,7 +180,7 @@ describe('Sign in form', () => {
it('should display an error if password is blank and login is attempted using enter key', async () => {
render(<SignIn isLoggedIn={false} setIsLoggedIn={() => {}} />);

const usernameInput = await screen.findByLabelText(/^Username/i);
const usernameInput = await screen.findByLabelText(/^signIn.username/i);
userEvent.type(usernameInput, 'test');
userEvent.type(usernameInput, '{enter}');

Expand All @@ -194,7 +194,7 @@ describe('Sign in form', () => {
it('should display an error if username and password are both blank and login is attempted using enter key', async () => {
render(<SignIn isLoggedIn={false} setIsLoggedIn={() => {}} />);

const passwordInput = await screen.findByLabelText(/^Enter Password/i);
const passwordInput = await screen.findByLabelText(/^signIn.enterPassword/i);
userEvent.type(passwordInput, '{enter}');

await waitFor(() => expect(screen.queryByText(/enter a username/i)).toBeInTheDocument());
Expand All @@ -207,18 +207,18 @@ describe('Sign in form', () => {
it('should should display login error if login not successful', async () => {
render(<SignIn isLoggedIn={false} setIsLoggedIn={() => {}} />);

const usernameInput = await screen.findByLabelText(/^Username/i);
const passwordInput = await screen.findByLabelText(/^Enter Password/i);
const usernameInput = await screen.findByLabelText(/^signIn.username/i);
const passwordInput = await screen.findByLabelText(/^signIn.enterPassword/i);
userEvent.type(usernameInput, 'test');
userEvent.type(passwordInput, 'test');

jest.spyOn(api, 'get').mockRejectedValue({ status: 401, data: {} });

const submitButton = await screen.findByText('Continue');
const submitButton = await screen.findByText('signIn.continue');
fireEvent.click(submitButton);

await waitFor(() => {
expect(screen.queryByText(/Authentication Failed/i)).toBeInTheDocument();
expect(screen.queryByText(/signIn.authFailed/i)).toBeInTheDocument();
});
await waitFor(() => {
expect(mockedUsedNavigate).not.toHaveBeenCalled();
Expand Down
12 changes: 6 additions & 6 deletions src/__tests__/RepoPage/Repo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ describe('Repo details component', () => {
jest.spyOn(api, 'get').mockResolvedValue({ status: 200, data: { data: mockRepoDetailsWithMissingData } });
render(<RepoDetailsThemeWrapper />);
expect(await screen.findByText('test')).toBeInTheDocument();
expect((await screen.findAllByText(/timestamp n\/a/i)).length).toBeGreaterThan(0);
expect((await screen.findAllByText(/main.timestampNA/i)).length).toBeGreaterThan(0);
});

it('renders vulnerability icons', async () => {
Expand Down Expand Up @@ -302,13 +302,13 @@ describe('Repo details component', () => {
render(<RepoDetailsThemeWrapper />);
expect(await screen.findAllByTestId('verified-icon')).toHaveLength(2);

const allTrustedSignaturesIcons = await screen.findAllByTestId("verified-icon");
const allTrustedSignaturesIcons = await screen.findAllByTestId('verified-icon');
fireEvent.mouseOver(allTrustedSignaturesIcons[0]);
expect(await screen.findByText("Tool: cosign")).toBeInTheDocument();
expect(await screen.findByText("Signed-by: author1")).toBeInTheDocument();
expect(await screen.findByText('signatureTooltip.tool: cosign')).toBeInTheDocument();
expect(await screen.findByText('signatureTooltip.signedBy: author1')).toBeInTheDocument();
fireEvent.mouseOver(allTrustedSignaturesIcons[1]);
expect(await screen.findByText("Tool: notation")).toBeInTheDocument();
expect(await screen.findByText("Signed-by: author2")).toBeInTheDocument();
expect(await screen.findByText('signatureTooltip.tool: notation')).toBeInTheDocument();
expect(await screen.findByText('signatureTooltip.signedBy: author2')).toBeInTheDocument();
});

it("should log error if data can't be fetched", async () => {
Expand Down
14 changes: 7 additions & 7 deletions src/__tests__/RepoPage/Tags.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ describe('Tags component', () => {
render(<TagsThemeWrapper />);
const openBtn = screen.getAllByText(/show/i);
fireEvent.click(openBtn[0]);
expect(screen.getByText(/OS\/ARCH/i)).toBeInTheDocument();
expect(screen.getByText(/main.osOrArch/i)).toBeInTheDocument();
fireEvent.click(openBtn[0]);
await waitFor(() => expect(screen.queryByText(/OS\/ARCH/i)).not.toBeInTheDocument());
await waitFor(() => expect(screen.queryByText(/main.osOrArch/i)).not.toBeInTheDocument());
});

// it('should see delete tag button and its dialog', async () => {
Expand Down Expand Up @@ -115,7 +115,7 @@ describe('Tags component', () => {

it('should filter tag list based on user input', async () => {
render(<TagsThemeWrapper />);
const tagFilterInput = await screen.findByPlaceholderText(/Search Tags/i);
const tagFilterInput = await screen.findByPlaceholderText(/tags.searchTags/i);
expect(await screen.findByText(/latest/i)).toBeInTheDocument();
expect(await screen.findByText(/bullseye/i)).toBeInTheDocument();
userEvent.type(tagFilterInput, 'bull');
Expand All @@ -125,12 +125,12 @@ describe('Tags component', () => {

it('should sort tags based on the picked sort criteria', async () => {
render(<TagsThemeWrapper />);
const selectFilter = await screen.findByText('Newest');
const selectFilter = await screen.findByText('sortCriteria.newest');
expect(selectFilter).toBeInTheDocument();
userEvent.click(selectFilter);
const newOption = await screen.findByText('A - Z');
const newOption = await screen.findByText('sortCriteria.AZ');
userEvent.click(newOption);
expect(await screen.findByText('A - Z')).toBeInTheDocument();
expect(await screen.queryByText('Newest')).not.toBeInTheDocument();
expect(await screen.findByText('sortCriteria.AZ')).toBeInTheDocument();
expect(await screen.queryByText('sortCriteria.newest')).not.toBeInTheDocument();
});
});
2 changes: 1 addition & 1 deletion src/__tests__/Shared/RepoCard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('Repo card component', () => {
expect(cardTitle).toBeInTheDocument();
userEvent.click(cardTitle);
expect(mockedUsedNavigate).toBeCalledWith(`/image/${mockImage.name}`);
expect(await screen.findByText(/timestamp n\/a/i)).toBeInTheDocument();
expect(await screen.findByText(/main.timestampNA/i)).toBeInTheDocument();
});

it('navigates to explore page when platform chip is clicked', async () => {
Expand Down
10 changes: 5 additions & 5 deletions src/__tests__/Shared/SearchSuggestion.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('Search component', () => {
it('should display suggestions when user searches', async () => {
jest.spyOn(api, 'get').mockResolvedValue({ status: 200, data: { data: mockImageList } });
render(<RouterSearchWrapper />);
const searchInput = screen.getByPlaceholderText(/search for content/i);
const searchInput = screen.getByPlaceholderText(/searchSuggestion.search/i);
expect(searchInput).toBeInTheDocument();
userEvent.type(searchInput, 'test');
expect(await screen.findByText(/alpine/i)).toBeInTheDocument();
Expand All @@ -91,7 +91,7 @@ describe('Search component', () => {
it('should navigate to repo page when a repo suggestion is clicked', async () => {
jest.spyOn(api, 'get').mockResolvedValue({ status: 200, data: { data: mockImageList } });
render(<RouterSearchWrapper />);
const searchInput = screen.getByPlaceholderText(/search for content/i);
const searchInput = screen.getByPlaceholderText(/searchSuggestion.search/i);
userEvent.type(searchInput, 'test');
const suggestionItemRepo = await screen.findByText(/alpine/i);
userEvent.click(suggestionItemRepo);
Expand All @@ -101,7 +101,7 @@ describe('Search component', () => {
it('should navigate to repo page when a image suggestion is clicked', async () => {
jest.spyOn(api, 'get').mockResolvedValue({ status: 200, data: { data: mockImageList } });
render(<RouterSearchWrapper />);
const searchInput = screen.getByPlaceholderText(/search for content/i);
const searchInput = screen.getByPlaceholderText(/searchSuggestion.search/i);
userEvent.type(searchInput, 'debian:test');
const suggestionItemImage = await screen.findByText(/debian:testTag/i);
userEvent.click(suggestionItemImage);
Expand All @@ -112,7 +112,7 @@ describe('Search component', () => {
jest.spyOn(api, 'get').mockRejectedValue({ status: 500, data: {} });
const error = jest.spyOn(console, 'error').mockImplementation(() => {});
render(<RouterSearchWrapper />);
const searchInput = screen.getByPlaceholderText(/search for content/i);
const searchInput = screen.getByPlaceholderText(/searchSuggestion.search/i);
userEvent.type(searchInput, 'debian');
await waitFor(() => expect(error).toBeCalledTimes(1));
});
Expand All @@ -121,7 +121,7 @@ describe('Search component', () => {
jest.spyOn(api, 'get').mockRejectedValue({ status: 500, data: {} });
const error = jest.spyOn(console, 'error').mockImplementation(() => {});
render(<RouterSearchWrapper />);
const searchInput = screen.getByPlaceholderText(/search for content/i);
const searchInput = screen.getByPlaceholderText(/searchSuggestion.search/i);
userEvent.type(searchInput, 'debian:test');
await waitFor(() => expect(error).toBeCalledTimes(1));
});
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/TagPage/DependsOn.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('Dependencies tab', () => {
it('should render the dependencies if there are any', async () => {
jest.spyOn(api, 'get').mockResolvedValue({ status: 200, data: mockDependenciesList });
render(<RouterDependsWrapper />);
expect(await screen.findAllByText(/Tag/i)).toHaveLength(8);
expect(await screen.findAllByText(/Tag/i)).toHaveLength(16);
});

it('renders no dependencies if there are not any', async () => {
Expand All @@ -99,7 +99,7 @@ describe('Dependencies tab', () => {
data: { data: { BaseImageList: { Results: [], Page: {} } } }
});
render(<RouterDependsWrapper />);
expect(await screen.findByText(/Nothing found/i)).toBeInTheDocument();
expect(await screen.findByText(/main.nothingFound/i)).toBeInTheDocument();
});

it("should log an error when data can't be fetched", async () => {
Expand All @@ -113,6 +113,6 @@ describe('Dependencies tab', () => {
jest.spyOn(api, 'get').mockResolvedValue({ status: 500, data: { errors: ['test error'] } });
jest.spyOn(console, 'error').mockImplementation(() => {});
render(<RouterDependsWrapper />);
expect(await screen.findByText(/Nothing found/i)).toBeInTheDocument();
expect(await screen.findByText(/main.nothingFound/i)).toBeInTheDocument();
});
});
2 changes: 1 addition & 1 deletion src/__tests__/TagPage/HistoryLayers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('Layers page', () => {

it('renders no layers if there are not any', async () => {
render(<HistoryLayers name="alpine:latest" history={[]} />);
await waitFor(() => expect(screen.getAllByText(/No Layer data available/i)).toHaveLength(1));
await waitFor(() => expect(screen.getAllByText(/historyLayers.noLayers/i)).toHaveLength(1));
});

it('opens dropdown and renders layer command and digest', async () => {
Expand Down
Loading

0 comments on commit 68487ff

Please sign in to comment.