Skip to content

Commit

Permalink
Initialize tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shakyapeiris committed Nov 22, 2022
1 parent dc53a97 commit 60cf056
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/__tests__/home/TableRow.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { describe, expect, test, afterEach } from 'vitest';
import { render, screen, cleanup } from '@testing-library/svelte';
import TableRow from '../../lib/home/TableRow.svelte';

describe('Unit:Home/TableRow', () => {
let data = {
id: '_1',
name: 'Test Medicine',
chemicalName: 'Test Medicine Chemical Name',
mrp: 50.0,
totalStock: 10,
index: 0,
};
afterEach(() => {
cleanup()
})
test('should render parsed data', () => {
render(TableRow, data);

Object.keys(data).forEach((key) => {
if (key !== 'id' && key != 'totalStock' && key !== 'index')
expect(screen.getByText(data[key])).toBeTruthy();
});
});

test('should show Out of stock when totalStock == 0', () => {
data['totalStock'] = 0;
render(TableRow, data);

expect(screen.getByTestId('availability').innerHTML).toBe('Out of stock');
})

test('should show Limited Stocks when totalStock < 100', () => {
data['totalStock'] = 80;
render(TableRow, data);

expect(screen.getByTestId('availability').innerHTML).toBe('Limited Stocks');
})

test('should show Available when totalStock >= 100', () => {
data['totalStock'] = 110;
render(TableRow, data);

expect(screen.getByTestId('availability').innerHTML).toBe('Available');
})

test('snapshot test', () => {
render(TableRow, data);

expect(screen).toMatchSnapshot();
})

});
56 changes: 56 additions & 0 deletions src/__tests__/home/__snapshots__/TableRow.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Vitest Snapshot v1

exports[`Unit:Home/TableRow > snapshot test 1`] = `
{
"debug": [Function],
"findAllByAltText": [Function],
"findAllByDisplayValue": [Function],
"findAllByLabelText": [Function],
"findAllByPlaceholderText": [Function],
"findAllByRole": [Function],
"findAllByTestId": [Function],
"findAllByText": [Function],
"findAllByTitle": [Function],
"findByAltText": [Function],
"findByDisplayValue": [Function],
"findByLabelText": [Function],
"findByPlaceholderText": [Function],
"findByRole": [Function],
"findByTestId": [Function],
"findByText": [Function],
"findByTitle": [Function],
"getAllByAltText": [Function],
"getAllByDisplayValue": [Function],
"getAllByLabelText": [Function],
"getAllByPlaceholderText": [Function],
"getAllByRole": [Function],
"getAllByTestId": [Function],
"getAllByText": [Function],
"getAllByTitle": [Function],
"getByAltText": [Function],
"getByDisplayValue": [Function],
"getByLabelText": [Function],
"getByPlaceholderText": [Function],
"getByRole": [Function],
"getByTestId": [Function],
"getByText": [Function],
"getByTitle": [Function],
"logTestingPlaygroundURL": [Function],
"queryAllByAltText": [Function],
"queryAllByDisplayValue": [Function],
"queryAllByLabelText": [Function],
"queryAllByPlaceholderText": [Function],
"queryAllByRole": [Function],
"queryAllByTestId": [Function],
"queryAllByText": [Function],
"queryAllByTitle": [Function],
"queryByAltText": [Function],
"queryByDisplayValue": [Function],
"queryByLabelText": [Function],
"queryByPlaceholderText": [Function],
"queryByRole": [Function],
"queryByTestId": [Function],
"queryByText": [Function],
"queryByTitle": [Function],
}
`;

0 comments on commit 60cf056

Please sign in to comment.