<commit_before>package main

import (
	"fmt"
	"testing"

	. "github.com/onsi/gomega"
	"github.com/qor/qor/l10n"
	. "github.com/sclevine/agouti/matchers"
)

func TestL10n(t *testing.T) {
	SetupDb(true)
	defer StopDriverOnPanic()

	var productCN Product

	product := Product{Name: "Global product", Description: "Global product description", Code: "Global"}
	draftDB.Create(&product)

	Expect(page.Navigate(fmt.Sprintf("%v/product", baseUrl))).To(Succeed())

	cnProductName := "name for CN product"
	cnProductDesc := "description for CN product"
	cnProductL10nLink := fmt.Sprintf("a[href='/admin/product/%v?locale=zh-CN']", product.ID)
	Expect(page.Find(cnProductL10nLink).Click()).To(Succeed())

	page.Find("#QorResourceName").Fill(cnProductName)
	page.Find("#QorResourceDescription").Fill(cnProductDesc)
	// TODO: test product code should be disabled since it is `l10n:"sync"` attribute when this has been implemented

	page.FindByButton("Save").Click()

	if err := draftDB.Set("l10n:locale", "zh-CN").First(&productCN, product.ID).Error; err != nil {
		panic(err)
	}

	if productCN.Name != cnProductName {
		t.Error("cn product's description not set")
	}
	if productCN.Description != cnProductDesc {
		t.Error("cn product's description not set")
	}

	// Update global product, CN product's code should be changed too because it is `l10n:"sync"` attribute, but others should have no change
	Expect(page.Navigate(fmt.Sprintf("%v/product", baseUrl))).To(Succeed())
	Expect(page.Find(fmt.Sprintf("a[href='/admin/product/%v?locale=global']", product.ID)).Click()).To(Succeed())

	modifiedProductName := "modified name"
	modifiedProductDescription := "modified description"
	modifiedProductCode := "global 2"

	page.Find("#QorResourceName").Fill(modifiedProductName)
	page.Find("#QorResourceDescription").Fill(modifiedProductDescription)
	page.Find("#QorResourceCode").Fill(modifiedProductCode)
	page.FindByButton("Save").Click()

	draftDB.First(&product, product.ID)<commit_msg>Fix CI tests<commit_after>package main

import (
	"fmt"
	"testing"

	. "github.com/onsi/gomega"
	"github.com/qor/qor/l10n"
	. "github.com/sclevine/agouti/matchers"
)

func TestL10n(t *testing.T) {
	SetupDb(true)
	defer StopDriverOnPanic()

	var productCN Product

	product := Product{Name: "Global product", Description: "Global product description", Code: "Global"}
	draftDB.Create(&product)

	Expect(page.Navigate(fmt.Sprintf("%v/product", baseUrl))).To(Succeed())

	cnProductName := "name for CN product"
	cnProductDesc := "description for CN product"
	cnProductL10nLink := fmt.Sprintf("a[href='/admin/product/%v?locale=zh-CN']", product.ID)
	Expect(page.Find(cnProductL10nLink).Click()).To(Succeed())

	page.Find("#QorResourceName").Fill(cnProductName)
	page.Find("#QorResourceDescription").Fill(cnProductDesc)
	// TODO: test product code should be disabled since it is `l10n:"sync"` attribute when this has been implemented

	page.FindByButton("Save").Click()

	if err := draftDB.Set("l10n:locale", "zh-CN").First(&productCN, product.ID).Error; err != nil {
		panic(err)
	}

	if productCN.Name != cnProductName {
		t.Error("cn product's description not set")
	}
	if productCN.Description != cnProductDesc {
		t.Error("cn product's description not set")
	}

	// Update global product, CN product's code should be changed too because it is `l10n:"sync"` attribute, but others should have no change
	Expect(page.Navigate(fmt.Sprintf("%v/product", baseUrl))).To(Succeed())
	Expect(page.Find(fmt.Sprintf("a[href='/admin/product/%v?locale=%v']", product.ID, l10n.Global)).Click()).To(Succeed())

	modifiedProductName := "modified name"
	modifiedProductDescription := "modified description"
	modifiedProductCode := "global 2"

	page.Find("#QorResourceName").Fill(modifiedProductName)
	page.Find("#QorResourceDescription").Fill(modifiedProductDescription)
	page.Find("#QorResourceCode").Fill(modifiedProductCode)
	page.FindByButton("Save").Click()

	draftDB.First(&product, product.ID)
{'fraction_non_alphanumeric': 0.15748230535894844, 'fraction_numerical': 0.008088978766430738, 'mean_word_length': 6.07871198568873, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3804223', 'n_tokens_mistral': 1345, 'n_tokens_neox': 1277, 'n_words': 258}