github.com/saucelabs/saucectl@v0.175.1/internal/playwright/code/parser_test.go (about)

     1  package code
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  )
     7  
     8  func TestParse(t *testing.T) {
     9  	tests := []struct {
    10  		name  string
    11  		input string
    12  		want  []TestCase
    13  	}{
    14  		{
    15  			name: "basic test case match",
    16  			input: `
    17  test.describe('New Todo', () => {
    18    test('should allow me to add todo items', async ({ page }) => {
    19    });
    20  
    21    test('should allow me to add todo items', async ({ page }) => {
    22    });
    23  });
    24  `,
    25  			want: []TestCase{
    26  				{
    27  					Title: "New Todo",
    28  				},
    29  				{
    30  					Title: "should allow me to add todo items",
    31  				},
    32  				{
    33  					Title: "should allow me to add todo items",
    34  				},
    35  			},
    36  		},
    37  
    38  		{
    39  			name: "complex case match",
    40  			input: `
    41  // @ts-check
    42  const { test, expect } = require('@playwright/test');
    43  
    44  test.beforeEach(async ({ page }) => {
    45    await page.goto('https://demo.playwright.dev/todomvc');
    46  });
    47  
    48  const TODO_ITEMS = [
    49    'buy some cheese',
    50    'feed the cat',
    51    'book a doctors appointment'
    52  ];
    53  
    54  test.describe('New Todo', async () => {
    55    test('should allow me to add todo items', async ({ page }) => {
    56      // Create 1st todo.
    57      await page.locator('.new-todo').fill(TODO_ITEMS[0]);
    58      await page.locator('.new-todo').press('Enter');
    59  
    60      // Make sure the list only has one todo item.
    61      await expect(page.locator('.view label')).toHaveText([
    62        TODO_ITEMS[0]
    63      ]);
    64  
    65      // Create 2nd todo.
    66      await page.locator('.new-todo').fill(TODO_ITEMS[1]);
    67      await page.locator('.new-todo').press('Enter');
    68  
    69      // Make sure the list now has two todo items.
    70      await expect(page.locator('.view label')).toHaveText([
    71        TODO_ITEMS[0],
    72        TODO_ITEMS[1]
    73      ]);
    74  
    75      await checkNumberOfTodosInLocalStorage(page, 2);
    76    });
    77  
    78  
    79    test('Non-empty', async ({ page }) => {
    80      // Create 1st todo.
    81    });
    82  
    83    test('should clear text input field when an item is added @fast', async ({ page }) => {
    84      // Create one todo item.
    85      await page.locator('.new-todo').fill(TODO_ITEMS[0]);
    86      await page.locator('.new-todo').press('Enter');
    87  
    88      // Check that input is empty.
    89      await expect(page.locator('.new-todo')).toBeEmpty();
    90      await checkNumberOfTodosInLocalStorage(page, 1);
    91    });
    92  `,
    93  			want: []TestCase{
    94  				{
    95  					Title: "New Todo",
    96  				},
    97  				{
    98  					Title: "should allow me to add todo items",
    99  				},
   100  				{
   101  					Title: "Non-empty",
   102  				},
   103  				{
   104  					Title: "should clear text input field when an item is added @fast",
   105  				},
   106  			},
   107  		},
   108  	}
   109  
   110  	for _, tt := range tests {
   111  		t.Run(tt.name, func(t *testing.T) {
   112  			if got := Parse(tt.input); !reflect.DeepEqual(got, tt.want) {
   113  				t.Errorf("parseTitle() = \"%v\", want \"%v\"", got, tt.want)
   114  			}
   115  		})
   116  	}
   117  }